Getting Started with Eclipse/Java Overview The Java programming language is based on the Java Virtual Machine. This is a piece of software that Java source code is run through to produce executables. The sequence of creating a runnable Java program is: Java Source Code Java Compiler (creating a.class file) Java Virtual machine Executable code The two middle steps are used to support a cross platform environment for Java programs. The final step, having the Virtual Machine actually execute the compiled code, can be implemented on different platforms (PC, Mac, Linux) but the.class files produced by the Java compiler will be the same. This means that you can write a Java program under one operating system and move it (without recompiling) to another system that is running a compatible Virtual Machine. In order to write and run Java programs you need to install a Java Virtual Machine run-time program (called a JRE) and a Java software development kit that contains the Java libraries needed to create the.class files. Both of these can be installed by downloading and running the Java JDK program. 1. Go to http://www.oracle.com/technetwork/java/javase/downloads/jdk9-downloads-3848520.html 2. Click the Accept License Agreement button and click the download for your operating system. 3. Run the download program and install the JDK and the JRE. Along with the Java compiler and Virtual Machine you also need some easy way to create Java programs. Most people that program in Java use a Java Integrated Development Environment (IDE). One of the commercial quality IDEs that many programmers use is Eclipse. Installing Eclipse The Eclipse program is written in Java and can be run on multiple operating systems. 1. Go to the Eclipse Web Site and click Download. 2. Download Oxygen (the installable version) or click the Download Packages link. You can also download the Zip version which does not require installation. 3. Either unzip or install Eclipse. 4. Start Eclipse and choose a workspace. This is where your projects will be saved. You next wish to ensure that Eclipse is using the version of Java you just downloaded. 5. Click Window and choose Preferences. You see the Preferences window
6. Click the Java item to show the Java options.
7. Click the Installed JREs item. This shows which Java runtime libraries are being used by default. If you don t see a jre-9.0.x selected then you must add the JRE. 8. Click the Add button. 9. Click the Add button and choose Standard VM and click Next. 10. Click the Directory button next to JRE Home and browse to c:\program files\java\jre-9.0.x and select the JRE folder.
11. Click OK to choose this JRE and then click Finish on the next screen. 12. Make sure the JRE is selected and click the Apply button. 13. Click the Compiler option under Java. 14. On the Compiler screen choose the drop-down next to the compiler compliance level and select 9. 15. Click Apply and Close. The Eclipse Environment The Eclipse IDE is a project-based system. This means that when you create a Java project to hold your code you will be creating a folder with the projects name in the workspace. Inside this folder you will create the various java code files and other files your project may need. 1. Click the X next to the Welcome tab to close the starting window. 2. In the Eclipse menu choose File, choose New, and choose Java Project. You see the Java Project window:
3. For the project name type FirstJavaProject and click Finish. You see the Java perspective
You have a project but no Java source file. 4. Click File, choose New, and choose Class:
The class menu lets you create a Java source file. 5. Type the name Program1 and click the option to create public static void main.
6. Click Finish to create your file. Your file is automatically added to the Project and a template set of commands shown in the Editor window:
By default, the starting point for a Java program is the method named main(). 7. In the editor window click on the blank line below the line starting with // TODO and press the Tab key. 8. Type the command: System.out.println( Hello ); The editor window look like:
Make sure you type the commands with the same case as indicated in this screen. You will next run your program. 9. Click the File menu and choose Save to save your program. 10. Click the Green Run button. The output from your program displays at the bottom of the window in the Console area: