Skip to main content

Posts

Showing posts from November, 2016

Regarding class files

Class files:- Regarding class file or dot class file also known as byte code of class, in a java programming language we can use any number of classes in our program. After compilation all classes convert into individual   .class   file. Example:- class A { } class B { } class C { } class Student { public static void main(String[]args) { System.out.println("Well-come to my java blog"); } } We can save above program to any   classname.java   or we can use any other   name.java,   there is no compulsion for java file name. But recommended to save by that class name which having main method. I saved the above file to   Student.java   name .   Before compilation my   C:\JAVATECH   folder contain only one java file. Student.java For  compilation. C:\JAVATECH>javac  Student.java After compilation   my   C:\JAVATECH   folder contains five files, one java file as previous and four .class files. Student.java Stu

java private

Access Modifier:- There are four access modifiers are available in java . public private protected default In java by default modifier is default if we are not using any modifier then by default access modifier will be default modifier. Applicable access modifiers for outer classes are default and public only. We cannot use private or protected modifier for outer classes. If we use   private or protected   modifier for outer class then compiler gives below error. private  class Student1 { } C:\JAVATECH>javac Student1.java Student1.java:1: error: modifier private not allowed here private class Student1         ^ 1 error protected class Student1 { } C:\JAVATECH>javac Student1.java Student1.java:1: error: modifier protected not allowed here protected class Student1         ^ 1 error If we use   default   modifier than we will not face any problem, but if we use   public   modifier than file name must be public  

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

java array

Array:- Array is special type of variable which can store multiple values into a single variable but all the values must be same. In java array is object. How to use array:- 1.      Declaration of array 2.      Create array Syntax for array declaration:- type arrayname[]; Or type []arrayname; For example int a[];  or int[]a; Create array:- a=new int[5];  or int a[]=new int[5]; or int []a=new int[5]; Example1:ArraY.java class ArraY { public static void main(String[]args) { int []a; a=new int[5]; System.out.println("length of array is : "+a.length); } } Output:- C:\JAVATECH>javac ArraY.java C:\JAVATECH>java ArraY length of array is : 5 Example2:- ArraY.java class ArraY { public static void main(String[]args) { int []a; a=new int[5]; System.out.println("length of array is : "+a.length); System.out.println("Array elements are : "); for(int i=0;i<a.length;i++)