Declarations and Access Control
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 and Keywords
All the Java components we just talked about—classes, variables, and methods need names. In Java these names are called identifiers.
Example:- Animal , employeeName, setName(String name)
Like all programming languages, Java has a set of built-in keywords. These keywords must not be used as identifiers.
Example :- int , long, if ,else, while, float, double, Integer,Double
Central to Java and other object-oriented languages is the concept of inheritance, which allows code defined in one class to be reused in other classes.
Example :- a Car superclass class could define general methods common to all automobiles, but a Ferrari subclass could override the accelerate() method.
A powerful companion to inheritance is the use of interfaces. Interfaces are like a 100-percent abstract superclass that defines the methods a subclass must support, but not how they must be supported.
class Cow implements Animal
Identifiers & JavaBeans
1) Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ ). Identifiers cannot start with a number!
2) After the first character, identifiers can contain any combination of letters,currency characters, connecting characters, or numbers.
3) In practice, there is no limit to the number of characters an identifier can contain.
4) You can’t use a Java keyword as an identifier.
5) Identifiers in Java are case-sensitive; foo and FOO are two different identifiers.
Examples of legal and illegal identifiers follow, first some legal identifiers:
The following are illegal (it’s your job to recognize why):
Complete List of Java Keywords
Sun’s Java Code Conventions
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:
For interfaces, the names should typically be adjectives like
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:
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;
Java constants are created by marking variables static and
final. They should be named using uppercase letters with underscore characters as separators:
for more download ppt: Java_PPT