Java Reference
In-Depth Information
Java programs can also be stored and run on a client. These types of Java programs are called client-based
applications . Finally, Java programs can be stored and run on a server and the results sent to the PC's browser for
display. There are many different types of Java programs that can run on the server. As a group they are called a
server-side (or server-based) application. However, each different type of Java program (Servlet, JSP, Bean, etc.) has
advantages and disadvantages and a specific purpose in the application. We will explore this in later chapters.
Oracle/Sun has continued to work with many companies (Microsoft, IBM) and international organizations
to insure that Java is compatible with all hardware and operating systems. Of course, there is also competition.
Microsoft offers a number of programming languages, specifically J# (pronounced “jay sharp”), that compete with
Java and an Integrated Development Environment (IDE) called .Net (pronounced “dot net”) that competes with
IBM's WebSphere.
Classes
Java statements are grouped into a class . A class is comparable to what other programming languages call a program.
A class begins with a header. The class header identifies the Java code as a class and defines class attributes . For
instance, a class header can include an access modifier (e.g., public , private ), the keyword class , and the class
name with at least one space between each. For instance, the following class header defines a class called Employee
(note we still need to add a body to this class definition):
public class Employee
The words public and class are examples of keywords (also called reserved words). A keyword has a specific
purpose in Java and can only be used in the manner dictated by the Java syntax. For example, class identifies the
code as a class, and public means that any other class can access Employee. The access modifier public must come
before the class keyword, and the keywords public or class cannot be used as the name of the class. There are
many other keywords (such as if , else , do , while , return ) that also cannot be used as a class name, and there are
a couple other rules that must be followed. For instance, class names can consist of letters, numbers, and some
special characters, however, it is strongly recommended that class names begin with an uppercase letter. Table 1-1
shows a brief list of the rules and examples.
Table 1-1.
Class name rule
Good
Bad
Begin with a letter
Sale1
Sale$
1Sales
No spaces
Tax_Calc
TaxCalc
Tax Calc
No keywords
MyFirstClass
Class
class
do
Notice that the third row in Table 1-1 lists “Class” as a valid name but “class” as invalid. This highlights another
feature: Java is case sensitive. This means that classes named Employee, EMployee, and EmployeE are all considered
different classes. In addition, if you referred to employee or EMPLOYEE, the system would not find a class with that
name. Be aware and careful of your capitalization! It is customary (but not required) to begin class names with a
capital letter and capitalize the first letter of each “word” within the class name (e.g., MyFirstClass). This mix of
upper- and lowercase letters is called “camel case.”
 
Search WWH ::




Custom Search