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 :
- Steps for installation of eclipse :
- First of all open up the browser.
- Open up google search engine and enter the keyword as download eclipse in it.
- Just select the eclipse kepler indicated by the arrow as shown in the above image.
- You will get the below screen where you have to select the eclipse IDE for your respective machine i.e 32/64 Bit.
- You will be navigated to the following screen :
- Just click on the download button as shown in the image and that’s it.
- After it gets downloaded you will get a compressed file of eclipse as shown in the image below:
- 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 :
- Now double click on the eclipse icon and it will ask you to save your workspace.
- Click on browse button, set your workspace and then click ok. You will get the eclipse window as shown bwlow :
- Here Installation of eclipse is completed.
- Steps for writing your first program in java
- click on File-> New-> Java Project as shown in the image.
- 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.
- After clcking on the next button you will get another dialog box as shown below where you have to click on the Finish button.
- You can see your First Project created at the right hand side corner in the package explorer.
- Now double click on that project it will get expanded and you will see the src folder.
- Right click on src -> New -> Class as shown in the image.
- A dialog box will appear where you have to enter the class name then choose the public method then click on Finish button.
- Your class will be created successfully and you will have the following window :
- Now in main method write the print statement i.e. “ System.out.println(“ ”) ”.
- And in the print statement in ” “ enter your message i.e. System.out.println(“This is my first program in eclipse”)
- So, you will have the following view of your window :
- Now click on save button which is indicated by an arrow in the above image.
- Now lets run the program.
- At the left hand side double click on your Project name -> src -> (default package).
- Now right click on our class name -> Run As -> Java Application.
- Now the output will get displayed on the console.
- Thus we have learned how to write and run a java program in eclipse.
- Operators and Conditions: –
- We can divide operators in six groups: –
- Arithmetic Operators: –
- Bitwise Operators: –
This operators works on bits and perform bitwise operations, it will give you result in binary format. - Relational Operator: –
- Logical Operators: –
If a holds value true and b hold value false. - Assignment Operator: –
- Hence, we successfully learnt how to install eclipse and execute your first program in java .
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.
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