Wednesday, July 30, 2014

Creating User Defined Jar File In Java

In java jar file  contains collection of classes and interfaces.If you want to create our user defined jar file use the following steps.

step1:

Develop user defined  classes and interfaces under any user defined package

step2:

Compile the above created classes and interfaces any location in your hard disk drive:

C:>javac -d . filename.java

step3:

Go to command prompt type the following command,

C:>jar cf satya.jar myPack1\*.class

Here cf--------create file,      satya.jar-------jar file name,        myPack1------content of the jar file

step4: If you want to know the content of your jar file use the following command

          C:>jar ft satya.jar





Wednesday, July 16, 2014

Java7 Features

We have the following features are there in java7 version they are,

1. In Java 7:

  int allows numbers and underscore.
So, it is easy to read the numbers. Especially when declare amount, in integer it’s easy to read it and avoid confusion.
2 SampleArrayList
Before Java 7:
                                        List<String> al=new ArrayList<String>();
In Java 7:
                              List<String> al=new ArrayList<>();
3) SampleSwitch.java
Before Java 7:
                        String not allowed in switch statement. Switch allows only character and numeric. If we need to compare a string in switch statement, assign string values to an numeric and use it in switch statement.
In Java 7:
                    Java 7 allows String in switch statement. So, we can directly use strings in switch statement.
4) SampleException.java
Before Java 7:
                                        catch(ArithmeticException e){}
                                         catch(NumberFormatException){}
                                         catch(NullPointerException){}
                                        catch(IOException){}
In Java 7: 
               catch(ArithmeticException|NumberFormatException|NullPointerException|IOException e){}
It’s more simple than the previous. Multiple catch can be handled in one catch statement.

Monday, July 14, 2014

Different Ways To Read Data Form Command Prompt or Keyboard





We have four ways to read the data from command prompt They are,

1. By using Scanner Class
2. By using InputStreamReader Class
3. By using Console Class
4. By using DataInputStream Class