Wednesday, February 25, 2009

Access Control and Declaration:Basics

Access control and Declaration Basics:-

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.Also some memory is allocated on the heap.

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, He 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.

Inheritance
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. In Java, you
can define a general (abstract) superclass, and then extend it with more
specific subclasses. The superclass knows nothing of the classes that inherit from it,
but all of the subclasses that inherit from the superclass must explicitly declare the
inheritance relationship. A subclass that inherits from a superclass is automatically
given accessible instance variables and methods defined by the superclass, but is also
free to override superclass methods to define more specific behavior.This is very useful feature
of Java as it provides specific functionality to every subclass irrespective of Superclass.

Interfaces
Interfaces are like a 100-percent abstract superclass that defines the methods a subclass must support. In other words, a Bus interface might declare
that all Animal implementation classes have an run() method, but the Bus
interface doesn't supply any logic for the run() method. That means it's up to the
classes that implement the Car interface to define the actual code for how that
particular Bus type behaves when its run() method is invoked.

Legal Identifiers

Rules:-

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. Table 1-1 lists all of the Java
keywords including one new one for 5.0, enum.
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:
int _name;
int $a;
int ___2_w;
int _$;
int this_is_a_name_for_an_identifier;

The following are illegal (it's your job to recognize why):
int :a;
int -bb;
int a#;
int .d;
int 9g;

Complete List of Java Keywords (assert added in 1.4, enum added in 1.5)

abstract, boolean, break, byte, case, catch,
char, class, const, continue, default, do,
double, else, extends, final, finally, float,
for, goto, if, implements, import, instanceof,
int, interface, long, native, new, package,
private, protected, public, return, short, static,
strictfp, super, switch, synchronized, this, throw,
throws, transient, try, void, volatile, while,
assert, enum.

Namaing Conventions:-
1.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

For example:
Cat
Account
Printer

For interfaces, the names should typically be adjectives like

ActionListener
Beauty

2.Methods The first letter should be lowercase, and then normal camelCase
rules should be used. For example:
getDate
doSomeWork
setCustomerid

3.Variables Like methods, the camelCase format should be used, starting with
a lowercase letter. Some examples:
labelWidth
accountNumber
myYahoo

4.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

0 comments:

About This Blog

This Blog is all about Java and programming.This blog is written by Vaibhav Pandey .He is a Computer Science Graduate .You can contact the author at javatute@gmail.com for any suggestion or Query.You can also contact the author for advertising on this blog.All the material presented here is the property of author and its reproduction in any form is strictly prohibited.

Disclaimer:-Download links provided here are not of author in any means.These are found over the Internet.
Page copy protected against web site content infringement by Copyscape

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP