Tuesday 22 July 2014

Java : Few Important Points

A simple program in java
  • Imp Point 1
 class Hello
{
    public static void main(String args[])
                  {
                      System.out.println("Hello how are you?");
                   }

}  If you want to run this program ,you have to save this file with .java extension.
So you can save it with Hello1.java or Hello.java or even .java
means .java is also valid .
  •  Imp Point 2
if you declare a class public then file name should be the same as the public class name with .java extension.
public  class Hello
{
    public static void main(String args[])
                  {
                      System.out.println("Hello how are you?");
                   }

}
Means you have to save this with the name Hello.java only
  •  Imp Point 3
A single .java can contain only one public class and any  no of private classes.You cant have more than one public class if you do,you will get an error.
  •   Imp Point 4 

public  class Hello
{
    public static void main(String... args)
                  {
                      System.out.println("Hello how are you?");
                   }

}
Instead of args[] array ,use can use varags(...).
  •   Imp Point 5

public  class Hello
{
   static public  void main(String... args)
                  {
                      System.out.println("Hello how are you?");
                   }

}
Instead of public static void main ,you can write static public void main but you cant do void public as it will effect function signature.
Modifier Return Type Name of Function(Arguments)
public and static are both modifiers so their order does not effect the function signature 
 
 

 
 
 

No comments:

Post a Comment