Java ProgrammingHow to install eclipse and execute your first program in java

How to install eclipse and execute your first program in java

In this tutorial we will learn how to install eclipse and execute your first program in java, have a brief lookout on operators used in java programming and have a short description regarding it.

  • To learn how to install eclipse and execute your first program in java and to have a brief overview on operators follow the steps given below :

  1. Steps for installation of eclipse :
    1. First of all open up the browser.
    2. Open up google search engine and enter the keyword as download eclipse in it.
    3. google search engine

    4. Just select the eclipse kepler indicated by the arrow as shown in the above image.
    5. You will get the below screen where you have to select the eclipse IDE for your respective machine i.e 32/64 Bit.
    6. 3

    7. You will be navigated to the following screen :
    8. eclipse

    9. Just click on the download button as shown in the image and that’s it.
    10. After it gets downloaded you will get a compressed file of eclipse as shown in the image below:
    11. zip file for eclipse

    12. Now just right click on the zip folder and extract it. After extracting it just double click on the eclipse folder and you will get the following window :
    13. eclipse installation

    14. Now double click on the eclipse icon and it will ask you to save your workspace.
    15. saving workspace

    16. Click on browse button, set your workspace and then click ok. You will get the eclipse window as shown bwlow :
    17. eclipse window

    18. Here Installation of eclipse is completed.
  2. Steps for writing your first program in java
    1. click on File-> New-> Java Project as shown in the image.
    2. writing first program in java

    3. Now a dialog box will appear where you will be asked to specify your project name . After specifying your project name click on the Next button.
    4. project name dialog box

    5. After clcking on the next button you will get another dialog box as shown below where you have to click on the Finish button.
    6. Eclipse installation

    7. You can see your First Project created at the right hand side corner in the package explorer.
    8. Now double click on that project it will get expanded and you will see the src folder.
    9. Right click on src -> New -> Class as shown in the image.
    10. installation of eclipse

    11. A dialog box will appear where you have to enter the class name then choose the public method then click on Finish button.
    12. class name

    13. Your class will be created successfully and you will have the following window :
    14. first program in java

    15. Now in main method write the print statement i.e. “ System.out.println(“ ”) ”.
    16. And in the print statement in ” “ enter your message i.e. System.out.println(“This is my first program in eclipse”)
    17. So, you will have the following view of your window :
    18. java program

    19. Now click on save button which is indicated by an arrow in the above image.
    20. Now lets run the program.
    21. At the left hand side double click on your Project name -> src -> (default package).
    22. Now right click on our class name -> Run As -> Java Application.
    23. executing the first program in java

    24. Now the output will get displayed on the console.
    25. output

    26. Thus we have learned how to write and run a java program in eclipse.
  3. Operators and Conditions: –
    • We can divide operators in six groups: –

    1. Arithmetic Operators: –
    2. operators

    3. Bitwise Operators: –
      This operators works on bits and perform bitwise operations, it will give you result in binary format.
    4. Example :

      If a = 38 and b = 13 no binary format of are follows: -
      a = 0010 0110
      b = 0000 1101 
      Now operations apply on above a and b operands
      a&b = 0000 0100.
      

      operators description

    5. Relational Operator: –
    6. Relational Operators

    7. Logical Operators: –
      If a holds value true and b hold value false.
    8. eclipse installation

    9. Assignment Operator: –
    10. Assignment Operator

      Example : This example shows how to use java operators in a class.

      class Operator//create class
      {
      public static void main(String arg[])//throws IOException
      {
      Scanner s = new Scanner (System.in);
      //create object of Scanner class, which is reference to scanner object 
      //and we use InputStream which is connected to keyboard input of console program
      System.out.println ("Enter two no");
      int a=s.nextInt(); //it will get next integer entered by user
      int b=s.nextInt(); //it will get next integer entered by user
      System.out.println ("Enter choice 1: Arithmetic operator 2: Logical operator 3: relational operator 4: bitwise operator");
      int ch=s.nextInt();//it will get next integer entered by user
      switch (ch)//choose the case  
      {
      case 1: System.out.println("Enter choice 1:add 2:sub 3:mult 4:div");
      int c1=s.nextInt();//it will get next integer entered by user
      switch (c1)//choose the case
      {
      case 1: System.out.println ("Addition is"+(a+b)); break;//Addition
      case 2: System.out.println ("Subtraction is"+(a-b)); break;	//Subtraction 
      case 3: System.out.println ("Multiplication is"+(a*b)); break; //Multiplication
      case 4: System.out.println ("division is"+(a/b)); break;//division
      }
      break;
      case 2:  System.out.println("Enter choice 1:AND 2:OR ");
      int c2=s.nextInt();//it will get next integer entered by user
      switch (c2)	 
      {   
      case 1: if(a>0&&b>0)//condition of case 1
      System.out.println ("true");    break;
      case 2:    if(a>0||b>0)//condition of case 2
      System.out.println ("false");   break;
      } break; 
      case 3: System.out.println("Enter choice 1:< 2:> 3<= 4:>= ");
      int c3=s.nextInt(); //it will get next integer entered by user      
      switch (c3)//choose the case
      {
      case 1:if(a<b) System.out.println(a+" is less than "+b );
      case 2:if(a>b) System.out.println(a+" is greater than "+b ); break;	
      case 3: if(a<=b) System.out.println(a+" is less than "+b ); break;
      case 4:if(a>=b) System.out.println(a+" is greater than "+b ); break;
      }
      break;//break switch statement
      case 4: System.out.println("1:<< 2:>>");
      int c4=s.nextInt ();     //it will get next integer entered by user  
      switch(c4)//choose the case
      { 
      case 1:System.out.println("Left shift of"+ a +"is "+(a<<2)); break;
      case 2:System.out.println("Left shift of"+ a +"is "+(a>>2)); break;
      }    
      break;  
      }
      } 
      }                                       
      

      Output :

      Enter two no
      2
      3
      Enter choice 1: Arithmetic operator 2: Logical operator 3: relational operator 4: bitwise operator
      2
      Enter choice 1: AND 2: OR 
      2
      false
      

  4. Hence, we successfully learnt how to install eclipse and execute your first program in java .

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Exclusive content

- Advertisement -

Latest article

21,501FansLike
4,106FollowersFollow
106,000SubscribersSubscribe

More article

- Advertisement -