Program 1 : Create a Java Program that display "Hello World" on your command line window.

Program : 
Create a Java Program that display "Hello World" on your command line window.

Solution :

Steps to create a Java Program:
       1. Create new text file using notepad.
       2. Now write given below code to your notepad file.

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

       3. Now save this file using "SabTech.java" .

How to Compile and Run Java Program:
       1. Open Command-line window.

       2. To COMPILE your java Program write below code:-
                      " javac SabTech.java"
           Then press Enter.
           So Now in your Folder a one new File Created with Name "SabTech.class"

       3. Now to RUN your java Program write below code:-
                      " java SabTech"
           Then press Enter.
           Now it will showing you O/P : Hello World

Explanation of Code Line by Line:
1. class SabTech :
                             It will Declare your Class.
                             Remember Your Class Name First Letter Always Capital.

2. public static void main(String args[]) :
    It will tell the Interpreter that Program is started from this line.
    here we take 
    "public" because when Program Execute "void main" is called from outside the class(by Interpreter) so we    
     must take it as public.
    "static" so  Interpreter can directly call static function using class name  so interpreter does not have to    
    create an object of class.
    "void" because it cannot return any value.

3.System.out.println("Hello World") :
    'S' = capital
    System.out.println is use to print any string on command line which is given using argument.
    here,
    'System' is a class and 'out' is an object which refer to the function 'println'.

Comments

Popular posts from this blog

Part 1: Introduction to Bigdata

Maths for Machine Learning

Good news for SAP Developers, SAP not cutting jobs in India but Creating more Jobs in India.