Skip to main content

Posts

Showing posts with the label args

java print

Syntax of main method in java is    public static void main(String[]args)  before understanding about main method we have to understand that who is responsible for main method.if we write a simple program or write a simple java class without main method like      Test.java           class Test      {      } above program will compile successfully.for compilation of  java file use  javac tool  or  javac.exe  file. javac Test.java it means compiler checks only syntax of class that means compiler does not check the main method in the file or program,so that compiler is not responsible for main method in java. After successfully compilation of above program we have to run the generated byte code. java Test Error: Main method not found in class Test, please define the main method as:    public static void main(String[] args) So JVM...

command line options

Command Line Argument:- value supplied to the main method String array from the run time or from command prompt called command line argument. All the values will be String. When we supplied value from command prompt automatically an array will be created of that length (number of arguments). Example1:- Command.java class Command { public static void main(String[]args) { System.out.println("Demo of Command Line"); } } Output:- C:\JAVATECH>javac Command.java C:\JAVATECH>java Command command com om Demo of Command Line Example2:- Command.java class Command { public static void main(String[]args) { System.out.println("Demo of Command Line"); System.out.println(args[0]); } } Output:- C:\JAVATECH>javac Command.java C:\JAVATECH>java Command command com om Demo of Command Line Command Example3:- Command.java class Command { public static void main(String[]args) { System.out.println("Demo of ...