16 October 2010

How every class has top super class is object ???

How every class has top super class is object???


when we create any class implicitly (automatically) it super class is Object class(java.lang.Object) but if create class but it extends its our own class..... let see how that working


 this class list C extend B, B extend A, A extend nothing


class A {
.....
}


class B extends A {
.....
}


class C extends B {
.....
}




But C extending B ... Java inheritance rule. one class can extends only one class. so C extends B,
every class extends Object class ....


Here is C extends B, B extends A, but A extends implicitly Object (which class has no extending any class that class extends Object class)


it means C has properties of Object class because | Object > A > B > C |,  C class has also advance java Object class properties


any class extends any class those class does not extends Object.. actually there is one class which has no explicitly extends so that class extends Object class by compiler

Java 6.0 New Collection APIs an Overview

Java 6.0 New Collection APIs an Overview
The following are the new collection APIs introduced in Java 6.0. I listes them as Interfaces and classes.

  • New Interfaces
  1. Deque
  2. BlockingDeque
  3. NavigableSet
  4. NavigableMap


  • New Classes
  1. ArrayDeque
  2. LinkedBlockingDeque
  3. ConcurrentSkipListSet
  4. ConcurrentSkipListMap
  5. AbstractMap.SimpleEntry
  6. AbstractMap.SimpleImmutableEntry

  • Updated Classes in Java 6.0
  1. LinkedList
  2. TreeSet
  3. TreeMap
  4. Collections

11 October 2010

JLable text Horizontal and Vertical Alignment

Horizontal Alignment 
Text Alignment Rigth
JLabel label1 = new JLabel("BottomRight", SwingConstants.RIGHT);

Text Alignment Left (It is by default)
JLabel label2 = new JLabel("CenterLeft", SwingConstants.LEFT);

Text Alignment Center
JLabel label3 = new JLabel("TopCenter", SwingConstants.CENTER);

Vertical Alignment
Text Alignment Bottom
label1.setVerticalAlignment(SwingConstants.BOTTOM);

Text Alignment Center vertically
label2.setVerticalAlignment(SwingConstants.CENTER);

Text Alignment Top
label3.setVerticalAlignment(SwingConstants.TOP);

10 October 2010

Disable JFram windows maximize button

just writer code

Myframe.setResizable(false);
class MyFrame {

       MyFrame() {
              this.setResizable(false);
       }

}

06 October 2010

(confusion code) check out what the output..???

public class CDummy
{
       static int toto = 7;

       CDummy getDummy() {
              return null; // pay attention here !
       }

       public static void main(String args[])
       {
              System.out.println("CDummy.");

              CDummy dmy = new CDummy();

              System.out.println(dmy.getDummy().toto);
       }
}

can you guess the output of the above code ? (try not to run the code)

plz replay me....

03 October 2010

Tip for Today

You can write code as anonymous

this code you may writing like....

MyClass mc1 = new MyClass();
mc1.justShow();

you want to just call method of you class need to further requirement. you can write code like this

(new MyClass()).justShow();

01 October 2010

Java Top Tips - 2

1. Add Application Exit Logic

Swing frame windows (JFrames) automatically close themselves if you click on the close icon (the X in the corner). However, if the JFrame was the main window for your application, the application will not actually quit. After closing the window, users will need to hit Ctrl-C or whatever key sequence stops a running application on their particular platform. Worse, if the application was started with javaw, it will continue to run invisibly. There's an easy fix: shut down the application when the main window closes. It looks like this: 

       // JFrame f;
       f.addWindowListener(new WindowAdapter() {
              public void windowClosing(WindowEvent we) { System.exit(0); }
       });

================================================================== 

2. Use the Main-class JAR Attribute

If you do package up an application in a JAR, there are two ways to run it. The first way is kind of clumsy--you have to add the JAR to your CLASSPATH and you have to know the name of the class to run. Suppose, for example, that I have an application called Shorts, packages in a JAR called Shorts.jar. To run it, I'd do something like this: 

java -cp Shorts.jar Shorts

A much nicer solution is to use the Main-class attribute, which is a way of embedding the name of the class to run inside the JAR. Then you can just run the application (in Java 2, at least) like this:
java -jar Shorts.jar
How do you do it? Normally, you would create the JAR something like this:
jar cvf Shorts.jar *.class
The trick to adding the Main-class attribute is defining an entirely separate file with the attribute definition. For instance, create the following one-line file and save it as extra.mf:
Main-class: Shorts
Now, to create the JAR, use this command line:
jar cvmf extra.mf Shorts.jar *.class
==================================================================