1. the installation of java programming language http

12
Fundamentals I (Introduction in Java Programming Language), COSC-1336-01 Tutorial 0 (Introduction) 1. The installation of Java programming language You need to go to the official website of Java programming language: http://java.sun.com/ Since Sun Inc. was purchased by Oracle in April 2010, you’ll get a screen showing you the “Oracle” logo instead of the “Sun” logo. Then, look for “Top Downloads” and click on “Java SE”, in particular. You get the below screen.

Upload: others

Post on 05-Oct-2021

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1. The installation of Java programming language http

Fundamentals I (Introduction in Java Programming Language), COSC-1336-01 Tutorial 0 (Introduction) 1. The installation of Java programming language You need to go to the official website of Java programming language: http://java.sun.com/ Since Sun Inc. was purchased by Oracle in April 2010, you’ll get a screen showing you the “Oracle” logo instead of the “Sun” logo.

Then, look for “Top Downloads” and click on “Java SE”, in particular. You get the below screen.

Page 2: 1. The installation of Java programming language http

Then you need to click on “Download JDK” to get the next screen.

Page 3: 1. The installation of Java programming language http

After you click “Download”, you get the screen:

Now, you are asked to select the platform from “Linux/Solaris/Windows”. After you click “Continue”, you need to click on the file listed in the “Available File”:

Page 4: 1. The installation of Java programming language http

The rest of the steps are self-explanatory, click “Run” or “Save”, and continue the Java installation. 2. Writing and testing our first Java program from the command prompt 2.1. For the Windows XP, Vista operating system:

1. Click “Start”, write “cmd” in “Start Search” box, and then click on “cmd” 2. Using “cd” command, go to your folder, say, c:\users\yourname 3. Edit a file by running the command “edit OurFirstProgram.java”

Page 5: 1. The installation of Java programming language http

4. Write the following text (the class name has to coincide with the filename, that is, OurFirstProgram):

5. Click “File – Save”, and then “File – Exit”. You should have in your folder the file

“OurFirstProgram.java”. 2.2. For the Windows 7 operating system (that may not contain the same settings for the 'edit' command):

1. Click “Start”, write “notepad” in “Start Search” box, and then hit <Enter> 2. After you finish writing the text file, go to "Save as". 3. In the file dialog, select in the "Save as type" the option "All files". 4. Then type in "File name" text field the complete name, say "Lincoln.java", and save in your

working folder. 2.3. How to compile the Java file at command prompt

Page 6: 1. The installation of Java programming language http

1. Compile the Java program using the command “<JavaPath> javac OurFirstProgram.java”.

For example, we get:

2. Your folder should contain the file “OurFirstProgram.class”. This is the object Java code corresponding to our source code.

3. Run the Java program using the command “<JavaPath> java OurFirstProgram”. For example, we get:

4. The program execution will display the text “This is our first Java program.”.

Page 7: 1. The installation of Java programming language http

2.2. Adding Java class-path in the Windows environment To make sure that Windows can find the Java compiler and interpreter, you need to do the following steps: 1. Start the application to add this setting: 1.1. [In Windows 7] Select Start -> Computer -> System Properties -> Advanced system settings ->

Environment Variables -> System variables -> Path. 1.2. [In Windows Vista] select Start -> My Computer -> Properties -> Advanced -> Environment

Variables -> System variables -> PATH. 1.3. [In Windows XP] Select Start -> Control Panel -> System -> Advanced -> Environment Variables

-> System variables -> PATH. 2. Click “Edit” button after you select the “Path” variable, and prepend the path to the Java executable folder followed by a semicolon, say “C:\Program Files\Java\jdk1.6.0_07\bin;” at the beginning of the PATH variable. 3. Click OK three times. 4. Reset your laptop. 5. When you check it, you can run the command "path" in your command prompt. Your Java path should be the first there. (Section 3 is not compulsory, and it is not requested for the final exam) 3. Writing and testing our first Java program using Eclipse 3.1. Installing Eclipse The Eclipse software can be used for writing, compiling, and testing programming assignments. We recommend you install the Eclipse environment on your computer. The Eclipse installation process needs to download the file eclipse-SDK-3.2.1-win32.zip (or whatever version is current) from the Eclipse official website: http://www.eclipse.org/downloads/index.php (please select Eclipse IDE for Java Developers). Once you have unzipped the previously downloaded file, you will see a folder named Eclipse. In that folder you will find the Eclipse application (a big blue dot). We recommend you create a shortcut on the desktop to simplify the launching of Eclipse. Notice that unlike Java, Eclipse does not have an installation process. Once you have unzipped the file you are done. 3.2. Launching Eclipse 1. Go to the folder called Eclipse and double-click on the big blue dot called “Eclipse application”.

Page 8: 1. The installation of Java programming language http

2. After you obtained the Eclipse environment, you can click on any of the “Welcome” screen buttons or you can close it. 3. Then click on File – New – Project, and you get this screen:

Page 9: 1. The installation of Java programming language http

4. After choosing “Java Project”, click “Next”. 5. We give a name for the “Java Project”, say “Lab1Ex2”, then click “Finish”.

Page 10: 1. The installation of Java programming language http

6. Press right-click on the project name, “Lab1Ex2”, and select “New”, followed by “Class”. You can also select automatically generation of “public static void main(String[] args)”, and then click “Finish”. You will get this screen:

Page 11: 1. The installation of Java programming language http

7. You can see the system gave the class name AnotherExample, like the filename. You can write, say, System.out.println("This is the second example."); You will see that, compared to the command prompt method, the Eclipse IDE helps by providing hints, methods prototypes, the parenthesis “(“, “)”, etc. 8. Go to File – Save or hit “Ctrl-S”. 9. Click Run – Run As – Java Application. Alternatively, you can right click on “AnotherExample.java” followed by Run As – Java Application. 10. The execution will appear in the below window, displaying the text “This is the second

example.”.

Page 12: 1. The installation of Java programming language http