About Java :
Java is a programming language and computing platform first released by Sun Microsystems in 1995.
Features Of Java
The major characteristics of Java are:
- The programs you create are portable in a network. (See portability.) Your source program is compiled into what Java calls bytecode, which can be run anywhere in a network on a server or client that has a Java virtual machine. The Java virtual machine interprets the bytecode into code that will run on the real computer hardware. This means that individual computer platform differences such as instruction lengths can be recognized and accommodated locally just as the program is being executed. Platform-specific versions of your program are no longer needed.
- The code is robust, here meaning that, unlike programs written in C++ and perhaps some other languages, the Java objects can contain no references to data external to themselves or other known objects. This ensures that an instruction can not contain the address of data storage in another application or in the operating system itself, either of which would cause the program and perhaps the operating system itself to terminate or "crash." The Java virtual machine makes a number of checks on each object to ensure integrity.
- Java is object-oriented, which means that, among other characteristics, an object can take advantage of being part of a class of objects and inherit code that is common to the class. Objects are thought of as "nouns" that a user might relate to rather than the traditional procedural "verbs." A method can be thought of as one of the object's capabilities or behaviors.
- In addition to being executed at the client rather than the server, a Java applet has other characteristics designed to make it run fast.
- Relative to C++, Java is easier to learn. (However, it is not a language you'll pick up in an evening!)
Java was introduced by Sun Microsystems in 1995 and instantly created a new sense of the interactive possibilities of the Web. Both of the major Web browsers include a Java virtual machine. Almost all major operating system developers (IBM, Microsoft, and others) have added Java compilers as part of their product offerings.
The Java virtual machine includes an optional just-in-time compiler that dynamically compiles bytecode into executable code as an alternative to interpreting one bytecode instruction at a time. In many cases, the dynamic JIT compilation is faster than the virtual machine interpretation.
Java includes
■ Class A template that describes the kinds of state and behavior that objects of its type support.
■ Object At runtime, when the Java Virtual Machine (JVM) encounters the new keyword, it will use the appropriate class to make an object which is an instance of that class. That object will have its own state, and access to all of the behaviors defined by its class.
■ State (instance variables) Each object (instance of a class) will have its own unique set of instance variables as defined in the class. Collectively, the values assigned to an object's instance variables make up the object's state.
■ Behavior (methods) When a programmer creates a class, she creates methods for that class. Methods are where the class' logic is stored. Methods are where the real work gets done. They are where algorithms get executed, and data gets manipulated.
Identifiers
All the Java components we just talked about—classes, variables, and methods— need names. In Java these names are called identifiers, and, as you might expect, there are rules for what constitutes a legal Java identifier.
■ Legal Identifiers The rules the compiler uses to determine whether a name is legal.
Technically, legal identifiers must be composed of only Unicode characters, numbers, currency symbols, and connecting characters (like underscores).
Here are some of the rules you do need to know:
- Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ ). Identifiers cannot start with a number!
- After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers.
- In practice, there is no limit to the number of characters an identifier can contain.
- You can't use a Java keyword as an identifier.
- Identifiers in Java are case-sensitive; foo and FOO are two different identifiers.
Examples of legal and illegal identifiers follow, first some legal identifiers:
- int identifier1;
- char _name;
- int _________2_w;
- float $currency;
- int this_is_a_very_big_identifier;
The following are illegal:
- int :b;
- int -d;
- int e#;
- int .f;
- int 7g;
■ Sun's Java Code Conventions Sun's recommendations for naming classes, variables, and methods. Sun has created a set of coding standards for Java, and published those standards in a document cleverly titled "Java Code Conventions," which you can find at java.sun.com. It's a great document, short and easy to read and we recommend it highly.
Here are the naming standards that Sun recommends:
■ Classes and
interfaces The first letter should be capitalized,
and if several words are
linked together to form the name, the first letter of the inner words should be
uppercase (a format that's sometimes called "camelCase"). For classes, the
names should typically be nouns. For example:
- Dog
- Account
- PrintWriter
- For interfaces, the names should typically be adjectives like
- Runnable
- Serializable
■ Methods The first letter should be lowercase, and then normal camelCase rules should
be used. In addition, the names should typically be verb-noun pairs. For
example:
- getBalance
- doCalculation
- setCustomerName
■
Variables Like methods, the camelCase format
should be used, starting with a lowercase letter. Sun recommends short, meaningful names,
which sounds good to us. Some examples:
- buttonWidth
- accountBalance
- myString
■
Constants Java constants are created by marking
variables static and final. They should be named using uppercase letters with underscore characters as separators:
- MIN_HEIGHT
■ JavaBeans Naming Standards The naming requirements of the JavaBeans specification.
By using naming rules, the JavaBeans spec helps guarantee that tools can recognize and use components built by different developers.
First, JavaBeans are Java classes that have properties. For our purposes, think of
properties as private instance variables. Since they're private, the only way they can be accessed from outside of their class is through methods in the class. The methods that change a property's value are called setter methods, and the methods that retrieve a property's value are called getter methods.
JavaBean Property Naming Rules
■
If the property is not a
boolean, the getter method's prefix must be get. For example, getSize()is
a valid JavaBeans getter name for a property named "size".
■ If the property is a boolean, the getter method's prefix is either get or is. For example, getStopped() or isStopped() are both valid JavaBeans names for a boolean property.
■ The setter method's prefix must be set. For example, setSize() is the valid JavaBean name for a property named size.
■ To complete the name of a getter or setter method, change the first letter of the property name to uppercase, and then append it to the appropriate prefix (get, is, or set).
■ Setter method signatures must be marked public, with a void return type and an argument that represents the property type.
■ Getter method signatures must be marked public, take no arguments, and have a return type that matches the argument type of the setter method for that property.
JavaBean Listener Naming Rules
■ Listener method names used to "register" a listener with an event source must use the prefix add, followed by the listener type. For example, addActionListener() is a valid name for a method that an event source will have to allow others to register for Action events.
■ Listener method names used to remove ("unregister") a listener must use the prefix remove, followed by the listener type (using the same rules as the registration add method).
■ The type of listener to be added or removed must be passed as the argument to the method.
■ Listener method names must end with the word "Listener".
Examples of valid JavaBean method signatures are
Examples of invalid JavaBean method signatures are
■ If the property is a boolean, the getter method's prefix is either get or is. For example, getStopped() or isStopped() are both valid JavaBeans names for a boolean property.
■ The setter method's prefix must be set. For example, setSize() is the valid JavaBean name for a property named size.
■ To complete the name of a getter or setter method, change the first letter of the property name to uppercase, and then append it to the appropriate prefix (get, is, or set).
■ Setter method signatures must be marked public, with a void return type and an argument that represents the property type.
■ Getter method signatures must be marked public, take no arguments, and have a return type that matches the argument type of the setter method for that property.
JavaBean Listener Naming Rules
■ Listener method names used to "register" a listener with an event source must use the prefix add, followed by the listener type. For example, addActionListener() is a valid name for a method that an event source will have to allow others to register for Action events.
■ Listener method names used to remove ("unregister") a listener must use the prefix remove, followed by the listener type (using the same rules as the registration add method).
■ The type of listener to be added or removed must be passed as the argument to the method.
■ Listener method names must end with the word "Listener".
Examples of valid JavaBean method signatures are
- public void setMyValue(int v)
- public int getMyValue()
- public boolean isMyStatus()
- public void addMyListener(MyListener m)
- public void removeMyListener(MyListener m)
Examples of invalid JavaBean method signatures are
- void setCustomerName(String s) // must be public
- public void modifyMyValue(int v) // can't use 'modify'
- public void addXListener(MyListener m) // listener type mismatch
Keywords
abstract
|
const
|
finally
|
int
|
public
|
this
|
assert
|
boolean
|
continue
|
float
|
interface
|
return
|
throw
|
enum
|
break
|
default
|
for
|
long
|
short
|
throws
|
|
byte
|
do
|
goto
|
native
|
static
|
transient
|
|
case
|
double
|
if
|
new
|
strictfp
|
try
|
|
catch
|
else
|
implements
|
package
|
super
|
void
|
|
char
|
extends
|
import
|
private
|
switch
|
volatile
|
|
class
|
final
|
instanceof
|
protected
|
synchronized
|
while
|
Hire php developers – Save cost by hiring dedicated PHP developers & PHP programmer from this site.
ReplyDelete