Tuesday, November 6, 2007

Serialization

If we want to carry liquid in other city or any where then we must keep it CAN which can can carry it.
Here the liquid is our object of any class and we are we must keep it in file to carry in nay other location then that class must implements the serializable interface which is the markable inteface.
suppose we want to keep some fields not serialize then declare those fields as transient.
It means that field is not available while reading the serialized object from file.

Mangesh S. S. Waghaye,
Nagpur.

Externalization

If we want to write the readObject and writeObject as per our requirment we must implement our class by interface Externalizable .
for example if you want to sysout in readObject or in writeObject or any other changes then this is done by Externalizable interface which has two methods ,
1)readExternal(ObjectInput input).
2)writeExternal(ObjectOutput out).

Mangesh S.S.Wagahye,
Nagpur.

Wednesday, August 29, 2007

log4j introduction...

log4j is a logging utility written in Java.It can be used as a debugging utility.log4j is one of widely used Java logging frameworks.log4j allows you to log to a file, console, remote server etc.

log4j has six logging levels from highest to lowest:
1. FATAL
2. ERROR
3. WARN
4. INFO
5. DEBUG
6. TRACE

You can configure log4j either using properties file or XML file.log4j configuration file contains
3 main components:
1. Loggers
2. Appenders
3. Layouts

The advantage of logging using log4j is that logging can be turned on or off without actually modifying the application that uses log4j.The application can be allowed to run with logging turned off until there's problem and later if there is any problem the user can turned on logging to see where is the problem.

Regards,
Tausif Khan, Nagpur

Thursday, August 16, 2007

Need a Dose again????????????

He guys,
It was really depressing not see a single blog since a week or more.Ya, there was some inconsistency in the class last week but atleast we must keep blogging regularly.I felt so and hence i m blogging though i dont have any valuable contents.But i will try to gather something useful and i promise I will be Back, very soon!!!

Till then, take care and Keep Blogging, else we might have one more class of heavy doses from Tushar Sir!!!

Take care,
Regards,
S A Vakeel

Monday, August 6, 2007

Inner classes

Hi everyone!!!
I really mised out the weekend!It was like i had not attended the class from a month.Neways, Mangesh helped me a lot by letting me know what had been taught on Friday.Thanx Mangesh!!!
Here, i m irting about inner classes.Hope it ould help u ppl in ome way!!

Inner classes are a feature added to Java with the release of JDK 1.1. Inner classes, sometimes also called as Nested classes, can give your programs additional carity and make them more concise.

Basically, an inner class is same as any other class except that it is declared inside an opening and closing braces of some construct that may be a class or a method.Following is an example of inner classes:

public class OuterOne{

private int x;

public class InnerOne{
private int y;
public innerMethod(){
System.out.println("Y = " + y);
}
}

public void outerMethod(){

System.out.println(" X = " + x);
}

}


When an inner class is declared like this, the enclosing class name becomes part of the fully qualified name of the inner class.In this case, the full names of the two classes are OuterOne and OuterOne.Innerone. itis possible since an inner class belongs to its enclosing class similar to the way a class belongs to a package.

Following example shows an extended view at the inner classes where the inner class uses the members of the enclosing class.

public class OuterOne{

private int x;

public class InnerOne{
private int y;
public innerMethod(){
System.out.println("Enclosing X = " + y);
System.out.println("Y = " + y);
}
}

public void outerMethod(){

System.out.println(" X = " + x);
}

}


Sometimes you might to create an instance of an inner class from a static method, or in some situation where ther is no this object available. The situtaion arises in a main() method.You can ahieve this by using new operator as :

public sytatic void main(String[] args){

OuterOne.InnerOne inner = new OuterOne().InnerOne();
inner.innerMethod();
}


We can also define classes inside Methods.The first point to be noted here is that anything declared inside a method is not a member of the class, but is local to the method.The imediate consequence is that classes declared in methods are private to the method and cannot be marked with any access modifier, neither can they be marked as static.

The second and most important point to be noted here is that the classes defined inside a method can access variables of the enclosing methods if and only if those variables are defined as FINAL.
The reason is that: An onject declared inside a mehod is likely to outlive the method invocation.Since the local variables and method arguments are conventionally destroyed when their method exits,these variables will be invalid for access by inner class methods after the enclosing method exits. By allowing the methods to access only final variables, it is possible to maintain a copy of the variables with the object itself, therby extending their lifetime.


Anonymous classes: Some classes that you define inside a method do not need a name , such classes are called as Anonymous classes.

Anonymous classes are mainly used to extend some class or implement an interface.This restricts you to extend more than one class and implement more than one interface.

Since there is no name given to the anonymous classes, we cannot use the new keyword in the usual way.The definition, contsruction and instantiation of an anonymous class all occur in the same place.This is explained in the next example:

public void aMethod(){
theButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.pritnln("The action has occurred");
}
}
);
}

This example may look somewhat weird to you since we have not learnt ActionListener yet.So lets check this example for our IStatusPrinter interface where we will use the Flexigame object to set the IStatusPrinter reference:

Flexigame fgame = new Flexigame("Cricket");

fgame.setStatusPrinter(
new IStatusPrinter(){
public void start(){
System.out.println("Starting the Game thgrough Anonymous class");
}
public void stop(){
System.out.println("Stopping the Game thgrough Anonymous class");
}

});


Thats all for now, guys!!!
See u soon with more stuff!!!
Take care,
Regards,
S A Vakeel

Thursday, August 2, 2007

Object Property

Variables of the class are related to the object of the that class irrespective whether those are private,public or protected. This is because we can make use of the variables of other class in our class by using the . .
Similar to this we can access non static methods using the object of that respective class, thus these are also related to objec property of class.
We Know that static inner class not related to the object property of enclosing class.Thus we can not have access inside static inner classs of the nonstatic methods and non final variables of the enclosing class.
by,
Mangesh S.S.Waghaye.