Wednesday, March 10, 2010

JAVA CORE....the real core

This are various refined descriptions those may help you while learning Java . Moreover the discussion is largely related to the practical approach...be in touch to learn more friends........
Class: keyword to create a template that describes the kinds of state and behavior that objects of its type support.
New:    it is a keyword that creates the object of the desired class by taking memory from the heap.
Object:  the object is the instance of the class, that object will have its own state, and access to all of the behaviors defined by its class.
State: it is the set of instance variable that is described by the class. the value assigned to these instance variables make up the object’s state.
Behavior: it is the class logic where algorithms are executed and the data get manipulated.
Inheritance (extends):  defining the behavior of super class in the sub class.
Interface (implements):  A  100 % abstract super class that defines a method a subclass must  support  . Its main purpose is to unattached the method definition from the hierarchy .
Source files declaration rules:
1.        There can be only one public class.
2.       If there is a public class then the name of the file(.java ) must match the name of the public class.
3.       If the class is the part of the package then then package statement must be the first line in a source code file.
4.       The file can have more than one non public class.
5.       Files with no public class can have a name that does not match any match any of the classes in the file.


Modifiers:
Access modifiers: public protected and private.
*      Access modifiers cannot be applied the local variables.(compile but no use)
*      A  class cannot be protected or private.
*       there are four access controls but there are only three access modifiers. The  forth is default(package access) which we get if we does not use any.
Non access modifiers:  strictfp, final, abstract, transient, synchronized, native, static.(s3atn).
*      local variable can be final.
.

Access means:
§  Whether method code in one class can access a member of another class.
1.       Generally using dot operator.(class.method());{achually Constracter.method (this,super can also be used)}.
§  Whether a subclass can inherit a member of its superclass  .
1.       When   a subclass wants to access a member of the superclass   . { here method can also be understood as this.method(),instead of simplely method()
      Class access:
If class A has access to another class B then it means:-
Class A can:
1.create an instance of class B .
2. Extend class B.
3. Access certain methods and variables in the class B.depending  on the Access controls of these methods and variables.
Default Access: default access is a package level access.
That is a class in a package can:
·         Create instance
·         Declare variable
·         Return type
       Of the another class in a same package with default Access control.
PUBLIC ACCESS:  A class declared with public keyword can be accessed by the any class in the java universe (ju).
Þ     Class must be declared public so that it is visible to the java universe
Þ     Method to be invoked must be declared public .
Þ     Constructor   should also be declared public if you want to make a instance of the class in some other class.
Þ     Always remember to import the class firstly.

Protected Access: protected member can be accessed (through inheritance) by a subclass even if subclass is in a different  peckage.Protected means the variable can be accessible to all other classes inside the same package as well as inheritable by any subclass outside the package.
                                PROTECTED=DEFAULT+INHERITANCE
¤   import the class .
¤   make the imported class as extended class(inherited )
¤   any subclass can access it through inheritance.
¤   We cannot access the protected member through a reference to an instance of the class.
¤   The protected member can be accessed by only the subclass and for any other class(like subclass of the actual subclass it act like the private package.
Private Access:    private means access in the  declaring class only.
o   When a member  is declared private a subclass cannot  inherit it (hence use it ).
o   Private method cannot be overwridden.             
o   Method with same name can be declared in the subclass but it is not the overridden method.

(nonAccess) modifiers:
Strictfp:  keyword to modify class and method.
Final: (keyword)  it tells that the class cannot be subclassed.that is no other class can ever extend a final class.
Abstract:  it is just creating a imaginary class whose methods are defined
Ø  If even a single method is abstract then whole class must be declared abstract.
Ø  An abstract class can contain a concrete method.
Ø  An abstract class can never be instantiated.
Ø  Its sole purpose is to be extended(subclassed).
Ø  It can be compiled unless you don’t make an instance.
Ø  It can be executed unless you don’t make an instance.
Ø  The method marked abstract ends in the semicolon rather than curly braces.
Ø  A class cannot be both abstract and final.

Final:
Ø       Prevent a method for being overwridden in a subclass.
Ø       Formal parameter can also be declared as final to prevent it to be modified by the method.
Interface: 
it tells what a class must  do.it is just used to unattached the methods from hierarchy .
that is suppose that there are some behaviours /methods  (like actionPerformed) which can be in various different  classes. The definations of such methods is declared in a 100% abstract class .
v  All interface method must be implemented,
v  All interface method must be marked public(when overridden in subclass).
v  Interface can have only abstract method.
v  All interface methods are implicitly public and abstract(we don’t need to type public and abstract while declaration).
v  All interface variables are implicitly public ,static and final( we don’t need to type public static and final while decreration).
v  Interface can declare only constants,non instance variable( public,static final).
v  An interface can extends(not implements) one or more other interfaces.
v  Constants in the interface (public static final) is same as #define in c..

No comments:

Post a Comment