Friday 26 June 2015

Class 2

Class 2

Void: The main method never returns any value to the JVM. If the main method doesn't return any value, then the return type should be void in JAVA.
public static = static public
COMMAND LINE ARGUMENT
The arguments accepted by the main function is called command line arguments. The main function in JAVA only accepts array of strings as an argument.
String is a predefined class present in JAVA language.
String args [ ] -> name of the array of strings.

NAMING CONVENTION FOR PREDEFINED MEMBERS.
1. Class -
Example: BufferedReader , String
Each word's first letter should be capital, and there shouldn't be any space.
2. Predefined "to" Method -
Example: toString( ), toCharArray( ) ; I.e except the first word, each word's first letter should be capital.
3. Predefined Constant: SIZE , MAX_VALUE; All the letters should be inupper case.
4. Package: java.lang, javax.swing, java.applet ; here each letter should be in lower case and the packages are separated by a "." symbol.

DEFAULT LENGTH OF THE COMMAND LINE ARGUMENT IS 0.

EXAMPLE OF A COMMAND LINE ARGUMENT:
public class Test{
static public void main ( String args[  ] )
{
    System.out.println (args.length); // 2
    for(int i=0; I<args.length; I++)
    {
        System.out.println (args [ i ]); //10, 20
    }
    System.out.println( args[ 0 ] + args [ 1 ] ); // 1020
    System.out.println(10+20); // 30
    System.out.println (5+6+'A'+'B'+5+6+(4+5)); //76B569
    System.out.println("10" + (5 - 10)); // 10-5
}
}

Convert string to integer by parseInt( ). It is a static member and it is called by a class.
Similarly, string to float can be converted by the use of parseFloat.

SYSTEM.OUT.PRINTLN:
A static member is always called by a Class name and a Non Static member is always called by an object name.
The difference between System.out and System.err is that the output produced by System.err can't redirect a file but System.out can
The difference between print and println is that println just adds a new line after printing your desired line.

No comments:

Post a Comment