Saturday, 10 September 2016

JAVA BLOG_2

BLOG-2: 
            
Java Syntax Learning!
  Syntax:::

    class CLASS_NAME
    {
        public static void main(String args[])
        {
        //Execution of code.......
        }
    } 


  Learn  Syntax:::

                  Here,

                       class is a keyword for defining the classname.

                       CLASS_NAME is  a class's name which you   
                       want to set, but set appropriate classname 
                       related to your program so you can easily find it.

Main Method:: public static void main(String args[])

                     "public" means that main() can be called from 
                    anywhere.

                   "static" means that main() doesn't belong to a

                    specific object.

                    "void" means that main() returns no value.


                    "main" is the name of a function. main() is

                     special because it is the start of the program.

                    "String[]" means an array of String.


                    "args" is the name of the String[] (within the

                    body of main()). "args" is not special; you can
                    name it anything else and the program would
                    work the same.


EXECUTION:

                  Open Command Promp and write::

          To Compile :: javac CLASS_NAME.java
          To Run  :: java CLAS_NAME

Program::

AIM      ::::::::::::::::::Write Hello World in JAVA::::::::::::::::::::

INPUT-
---------------------------------------------------------------------------------

    class JavaDemo    {        public static void main(String args[])        {            System.out.println("Hello World");        }    }


---------------------------------------------------------------------------------
Explanation-

What is " System.out.println(); "?
                  
                               System is a class in the java.lang package. out is a static member of the   
                  System class, and is an instance of java.io.PrintStream .out is an object of the 
                  System class. println is a method of java.io.PrintStream . This method is
                  overloaded to print message to output destination, which is typically a console or file.

                  Firstly, compile the program of  (.java) file, It is converted into (.class) file
                  by compiler. Then run (.class) file and your code will be generated 
                  successfully. If (.class) file is not created then check the Exception of the program
                  and solve it and compile again.

---------------------------------------------------------------------------------------------------------------------------       
OUTPUT-

                         javac JavaDemo.java
                         java JavaDemo

                         Hello World 
 -----------------------------***************************************--------------------------------                 

No comments:

Post a Comment