Monday, March 15, 2010

the this keyword


This definition:

Java’s ‘this’ keyword is used to refer the current instance of the method on which it is used.
Following are the ways to use this
1) To specifically denote that the instance variable is used instead of static or local varible.That is,
private String javaFAQ;
void methodName(String javaFAQ) {
this.javaFAQ = javaFAQ;
}
Here this refers to the instance variable. Here the precedence is high for the local variable. Therefore the absense of the this denotes the local variable. If the local variable that is parameter’s name is not same as instance variable then irrespective of this is used or not it denotes the instance variable.


2) This is used to refer the constructors
public JavaQuestions(String javapapers) {
this(javapapers, true);
}
This invokes the constructor of the same java class which has two parameters.


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.