Changes between Version 3 and Version 4 of ControlSystems/SoftwareTeam/Training/GettingStarted/HelloWorld
- Timestamp:
- Nov 4, 2019, 2:46:23 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/HelloWorld
v3 v4 1 Java is a programming language. It consists of a small, concise set of words that let you describe to the computer exactly what you want it to do. A Java program consists of one or more files. We use a Microsoft program called VSCode to write and run Java programs. Each program must have its own folder. To write your first Java program, you need to create a new folder for it. First create a folder to hold all of your Java projects in your Documents folder named Java Projects. Then in the Java Projects folder, create another new folder named Hello World that will hold your first program. 2 [[Image(ProjectFolder.jpg, 50%, margin=10)]] 1 You can think of a computer program as a recipe for the computer to follow. The program tells the computer exactly what to do. Programming languages have been developed to make it easy to write concise, precise instructions. Unlike human languages, computer languages are very small; they consist of a set of carefully chosen words that let you describe to the computer exactly what you want it to do. A popular programming language (C) has only [https://www.programiz.com/c-programming/list-all-keywords-c-language 32 words]! Java is a programming language that descended from C and is the language we will use to program the robot. 3 2 3 A Java program consists of one or more files (documents). We use a program from Microsoft called VSCode to write and run Java programs. 4 4 5 In VSCode: 6 1. Select File->Open Folder and choose the !JavaProjects\Hello World folder you just created. 7 1. Select File->New which will open the editor for you to enter a new program 8 1. Cut and paste the following program into the editor: 9 {{{ 10 public class Hello { 11 public static void main(String args[]) { 12 System.out.println("Hello world"); 13 } 14 } 15 }}} 16 1. Select File->Save and name the file Hello.java the name is important; it must be Hello.java with a capital H (case matters to Java). The name of the file must be the same as the name of the class (more on classes later) 5 It's a long standing tradition in programming to make your first program display the message "Hello world!": 6 7 === Create your program === 8 1. Each program must have its own folder, so [[Image(ProjectFolder.jpg, 50%, margin=10)]] 9 1. Create a folder named '''Java Projects''' in your Documents folder to hold all of your Java programs. 10 1. Create another folder named '''Hello World''' inside the Java Projects folder to hold your first program. 11 1. Launch VSCode and then: 12 1. Select File->Open Folder and choose the !JavaProjects\Hello World folder you created. 13 1. Select File->New which will open the editor for you to enter a new program 14 1. Cut and paste the following program into the editor: 15 {{{ 16 public class Hello { 17 public static void main(String args[]) { 18 System.out.println("Hello world"); 19 } 20 } 21 }}} 22 1. Select File->Save and name the file '''Hello.java''' [[BR]] 23 NOTE: the name of the file is important; it must be Hello.java with a capital H (case matters to Java). [[BR]] 24 The name of the file must be the same as the name of the class (more on classes later) 17 25 18 26 === Run the program … … 24 32 In the terminal window below, you'll see the output: 25 33 {{{ Hello world! }}} 34 26 35 Congratulations, you just wrote your first Java program!!! 27 36