Create program Hello World Lab 2 Objective Learn

Create program Hello World! Lab 2

Objective • Learn about the Eclipse program • Create a project and class • Explain the structure of the program • Writing print sentences System. out. print • Write comment on the program • Run the program and correct the errors if any • Save the project and close the program

Open the Eclipse program • There is a shortcut to the program by double-clicking the program Run the program Menu bar View and edit the class Toolbar Move between project and class The result of running the program

Create project File New Java project

Create project • Write project name. • click finish button.

Create project • From a window Package Explorer • We can review projects

Review of projects • If the Review of Projects does not appear Follow the path below Window Show View A window will appear Package Explorer

Create class • Right-click on the project to which you want to add the class • New Class

Class naming rules • • • The identifiers name consists of English letters ( A Z , a z ), numbers (0 -9), and special symbols $, _ six rules must be taking into account: • The name starts with a letter. • The name cannot begin with a number. • It does not contain any white space. • It should not be reserved names. • It's a good idea to give your variables mnemonic names that are closely related to the values they hold. • It does not contain any letters or other special marks are not mentioned earlier. It is recommended that the name of the class begin with a capital letter.

Create class 1) Write class name helloworld as example in small letter 2) Check the status modifiers (Public) 3) In the first class is created we choose the first option to create the main function

Create class 1) The class name appears on the second line and begins with a brace { and ends with it} in the tenth line. 2) The fourth line, the main function, which is the beginning of the program execution point and start from the beginning brace { and ends on the ninth line} The program is written inside the main function. 3) Write instruction (code) If the Review of Projects does not appear Follow the path below Window - Show View - Project Explorer Here the program outputs appear The fifth line is comment and ignored during execution Comments are usually used to help The reader understands what he or she wrote and the comments begin with // If the output window does not appear, follow the following path Window -- Show View -- Console

Write the program 1) Type the following sentence in the line 6 System. out. println("Hello World!"); Under the comment //TODO 2) Click the Run button to execute the program or the Run menu select the first Run option Line numbers -Run the program If the toolbar does not appear, follow the path below Window Appearance Show Toolbar

The result of the program ! • In the Console window, you will see the result, whether the program have error, or the program is working properly ﺓ Here show the result of the program ﺟﻴﺘﻨﻼﺭﻫﻈﺖ ﺍﻧﻪ

The result of the program ! • In the Console window the error message appears with the line number, or in the program writing screen at the sixth line we notice a sign . • The appearance of the curvy red line under the word system. • • What is the reason? Note that Java is case sensitive in both uppercase and lowercase so you should pay attention! The appearance of the curvy red line under the wrong message

The result of the program ! • • What causes this error? All Java sentences must end with a semicolon ; The appearance of the curvy red line under the wrong message

Write the program 1) Type the following commands as they appear on the screen System. out. println("this is my first program"); System. out. print("My name is: "); System. out. println(“Your. Name"); 2) Run the program 3) What is the difference between print and println?

Save the program • File Save Or • Press (Ctrl+S) • And the extension of the class always *. java

Create another Class • Right-click on the project to which you want to add the class New class

Create another Class 1) Write class name drawrec as example in small letter 2) Check the status modifiers (Public) 3) Note that this option is not selected because the main function has already been created in the helloworld class

Create another Class 1) How many of the class appears within the project Helloworld? 2) What are the names of the class that appears in front of you? 3) In the screen writing the program appears on the second line class name and begins with {and ends in the fourth line } The program writes among them

Move between classes 1) 2) To return to the class helloworld. java we click on its name Add a comment to line 10 // Here a rectangle will be drawn 3) Complete the program so that it gives the following result

Delete the project • Right-click on the project you want to delete Delete

Close the project • Make a save and then press the button from the top of the window, then OK button to confirm exit If you want to close the class only

Summary • Learn about the Eclipse program • Create a project and class • Explain the structure of the program • Writing print sentences System. out. print • Write comment on the program • Run the program and correct the errors if any • Save the project and close the program
- Slides: 24