Changes between Version 9 and Version 10 of ControlSystems/SoftwareTeam/Training/GettingStarted/IntroJava
- Timestamp:
- Oct 1, 2019, 10:37:04 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/IntroJava
v9 v10 1 1 == Introduction to Java 2 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, create a new folder in your Documents folder named Java Projects. In the Java Projects folder, create another new folder named Hello World.2 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. 3 3 [[Image(ProjectFolder.jpg, 50%)]] 4 4 5 5 6 6 In VSCode: 7 1. Select File->Open Folder and choose the Hello World folder.7 1. Select File->Open Folder and choose the JavaProjects\Hello World folder you just created. 8 8 2. Select File->New which will open the editor for you to enter a new program 9 9 3. Cut and paste the following program into the editor: … … 15 15 } 16 16 }}} 17 4. Select File->Save and name the file Hello.java 17 4. 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) 18 18 5. In the left navigation window, you'll now see Hello.java with a red J icon next to it; right click on the Hello.java and select Run 19 19 6. A terminal window will open, the program will be compiled and then run; you'll see the output: Hello world! … … 62 62 == Conditionals 63 63 Programs need to be able to react differently to varying data. Conditional statements let us do this. For example, a robot must be able to monitor its sensors to prevent collisions. Consider (and try running) the following program: 64 * Create a new folder and new file; cut and paste this program into it and save it as !ConditionalExample.java 64 65 {{{ 65 66 public class ConditionalExample { … … 77 78 } 78 79 }}} 79 * Save the program as ConditionalExample.java (notice how the name of the file must match the name of the class)80 * Save the program as !ConditionalExample.java (notice how the name of the file must match the name of the class) 80 81 * Run the program using the debugger with a breakpoint set on the first executable line (rangeInInches=10); step through the program using the stepover tool and observe the flow of the program. 81 82 * What happens if you change the values stored in the variable rangeInInches to 25?