Java How to Install

Published on February 2017 | Categories: Documents | Downloads: 45 | Comments: 0 | Views: 416
of 7
Download PDF   Embed   Report

Comments

Content

Checking the initial Setup for Java. Getting Started with JDK for Windows This page will demonstrate how to compose, compile, and run a simple java program on your local PC running windows. To ensure all the procedures work, JDK (Java Software Development Kit ) must be installed properly on your PC. To check whether Java Running environment is properly installed in the machine type the following command in your command prompt. java -version If the java environment is properly installed you may see the currently installed JAVA version in the machine. If nothing is given in then JDK may be need to installed in the machine. Installing JDK version In order to installed the JAVA in the machines we need to download the necessary binary files in to the machine. Use the following URL to download the necessary JDK ( Java Development Toolkit) in to the machine. http://www.oracle.com/technetwork/java/javase/downloads/index.html (For this step you may ask the help from the instructor) For more installing information on Windows environment follow the following URL. http://www.oracle.com/technetwork/java/javase/documentation/install-windows152927.html Once you download the file run and install the file in the machine by following the steps. You will see a page with numerous download choices. You want the Java Development Kit (JDK) without the NetBeans environment, and without the Enterprise Edition. Click on the Download link. (In 2005, the marketing geniuses at Sun started labeling the most current version "Update n", such as JDK 5.0 Update 6. That's the one you want. It is the full JDK, not an update to an existing installation.) Select the Windows installer (either the online or offline version are fine). Download and run the installation program.

When the installation program starts, it gives you a chance to change the installation location. As always, you should not accept the default in the Program Files directory. Instead, click on the Change button. Carefully remove Program Files\Java\ from the installation directory, so that the installation directory looks similar to c:\jdk1.5.0\. Make a note of the exact name of the directory. Continue with the installation. After the JDK has been installed, you are invited to install other features (a runtime environment and additional fonts). You can safely skip these features by clicking the Cancel button. When the installation is finished, you need to restart the computer. Open a command prompt and type in the command c:\jdk1.5.0\bin\java -version However, be sure to change the first part jdk1.5.0 to match the exact name of the download directory. You should get a message that describes the version of the Java installation.

If you get that message, close the shell window and go on to the next step. Otherwise, carefully check the name of the installation directory or ask the help from the instructor.

Setting up the class path Now the important step of adding the JAVA commands to the normal command execution. This can be done by adding the JAVA command bin folder to the WINDOWS environment variables. Click on the Start button and launch the Control Panel. Select the Performance and Maintenance category.

Then select the System dialog. In the dialog, click on the Advanced tab.

Now click on the EnvironmentVariables button.

In the System variables list, select the Path variable and click the Edit button.

Carefully click on the Variable value field so that the entire path is no longer highlighted. If you accidentally erase it, hit Cancel right away and try again. Move the cursor to the beginning of the line. Add an entry to the beginning of the field. The entry has the form
c:\JDK directory name\bin;

Be sure you enter the exact name of the JDK directory and follow it by \bin; (a backslash, the word bin and a semicolon).

Click Ok three times. Start a new command prompt and type the commands
java -version javac

You should now get a version information and the java compiler . If got error message saying "command not found" ask the help from your instructor . Start working with JAVA You now need to create one folder for processing your work. If you already have a lab account, you should save your work to a folder on a drive. If you do not have a lab account yet, use “My Computer” or “Windows Explorer” to create one folder on a drive. Name it something that is likely to be unique. Your lab user id is always a good choice for this. Using notepad to create a Java Source File Java source code files are plain text files. There are several choices for creating text files on a windows PC. We will use the notepad utility because it is usually present on all windows PC’s. Create a new edit file by selecting “Notepad” from “start” -“Accessories”. Inside the Notepad editor, add the following code. public class HelloWorld { public static void main (String args[]) { System.out.println("Hello World"); }

}

Now you need to save the Java source code that you created.

All Java source code files must have a “ .java” extension ( i.e. of the form “ myfile.java”). Notepad will by default, save files with the “ . txt” extension. To save your source file correctly, change click “File-Save”, then change the selection in the “Save As Type” field from “text documents” to “all files”. Then in the “File Name” field, name you’re the source file “HelloWorld.java” . All commands and filenames in Java are case sensitive, so pay close attention to the case of file that you name. In the “Save In” field at the top of the screen, browse to the directory you created earli er for your work and click OK. Compiling and running your program from the Command Prompt Look for “Command Prompt” or “Dos Prompt” on the start menu. Open a Command Prompt and and change to the directory that you saved source code in. Use the command "cd" to change your current directory to working directory. Once it is done check for the necessary java source file by using "dir" command. Now we need to compile the first java program. To compile the java source file we need to use the "javac" command. Then type “javac HelloWorld.java”, and press enter. If you receive error message, edit the file with Notepad and fix the mistakes. Then re-compile your program as previously instructed. If there are no compile error messages, the compiler will create a file called “HelloWorld.class” in your current working directory. Type “dir” at the DOS Prompt to see that the HelloWorld.class file has indeed been created by the compiler. The class file created by the compiler can be executed by the Java virtual machine on the PC. (If the file listing went by the screen too fast for you to read when you executed the dir command, try using “dir/w” or “dir/p” as your listing command.) To see how the compilation process works use the following command javac -verbose HelloWorld.java

Now, to run your file, type “java HelloWorld” (no quotes) at the DOS prompt. Then you will see the output text as HelloWorld in the command prompt area. If it does not appear in the screen ask help from the instructor to get it done correctly. Run the same program several times by changing the text "Hello World" and re-compile and run in the command prompt. With the help of the instructor try to do these steps again with different text editors available in the machine such as Textpad, wordpad or any other IDE tool available in the machine. You may ask the help from the instructor to work with other text editors.

Getting familiar with JAVA api and tutorial available For any program available in JAVA language it contained many libraries which need to import and these may contain many different types of methods which we can used in our day to day programming. To get an understanding on these methods available we can refer to the JAVA documentation which is known as the JAVA API. You can follow the following url to visit the java api and get hands on familiarization with it. http://docs.oracle.com/javase/7/docs/api/

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close