Programming Environment
Objective #1: Explain how to download & install Eclipse.
- There are numerous free and inexpensive Java integrated development environments (IDE's) that make the task of writing, compiling, debugging, executing and editing Java programs easier.
A very popular, free, open-source one is Eclipse.
- At our school, we are using the Windows 32 bit version of "Eclipse IDE fro Java Developers" which can be downloaded for free
at eclipse.org/downloads
- In order to execute Java programs and web page applets, you need to have Java (technically known as the Java Runtime Environment or JRE) installed on your
computer. The JRE includes the Java Virtual Machine (JVM) that is necessary to translate bytecode into machine code and execute a Java program. The JRE is probably already installed on your home computer. However, if you
have trouble executing the Java programs that you write with Eclipse or running Java game applets, visit java.com
to get the free Java download.
- Note that if you want to develop Java programs without using Eclipse, NetBeans or one of the many other nice, full-featured IDE's, you can download the JDK (Java Development Kit but also known as SDK or even JSDK) a create your programs from a command line.
Objective #2: Understand how to use Eclipse.
- How to import an existing .java source file into an Eclipse project
- Copy the existing java source file into the package within your project or into the project's src directory (e.g., copy my_program.java \my_eclipse_directory\project_name\src).
- Or, you can right-click the package name (or the src folder if you have no package yet), select Import/File System & then browse to the folder storing the source file you want and select
it.
- Or, if you have a bunch of source files in a folder within a workspace, you can create a new project with a name identical to that folder.
- If you are using an older version of Eclipse, you must make it notice the new file by doing a refresh (you can right click on the project name in the package explorer pane and select refresh,
or you can hit function key F5, or you can select menu item File->Refresh)
- selecting a class to run
- open the file that you want to run in the main window or click its tab to bring it into view, then right-click in the window and select Run As.../Java Application
- even if several classes in one project have their own main methods, the one that's designated as the active source file will execute when you click the Run icon. if not, the class that executed
most recently is the one that executes.
- Eclipse tutorials
- For students in an AP Java course, it is recommended that you set up Eclipse to automatically use the gridworld.jar file. Open the menu command Window/Preferences. Click on the icon
to the left of Java to expand the Java choices. Click Expand Build Path and then select the Classpath Variables. Click the New button. For the name, enter GRIDWORLD. For the path, click the File button
and find the gridworld.jar file that is in my Handout folder (or save that jar file to your network folder and use that copy.) Click the OK button two times.
- ADVANCED >>>> If you would like to compile and execute Java programs from a command line (i.e. the DOS, console window), you may should "put
Java into the path" of your Windows computer so you can use the javac command from anywhere on your computer. To do this on a Windows XP computer, click the Start/Control Panel menu command and
then double-click the System icon to open the System Control panel. If the System icon is not visible, first click on the "Switch to Classic View" button. In the System control panel, select
the Advanced tab, and then click the "Environment Variables" button. This will bring up a window in which you can edit system variables, including the PATH variable. After you've added the
location of the SDK to your PATH, save the changes and reboot your machine when prompted. In order to be recognized on some systems, the addition may need to be added at the beginning of the variable
list. With the Java compiler installed, you can use the program NotePad to create a file such as the HelloWorld.java program below and save it in your My Documents folder. Then, at a C:\My Documents> prompt
you can type the command \j2sdk1.4.2\bin\javac HelloWorld.java to compile the program. However, if you placed java in the
path, you only need to type the command javac HelloWorld.java You can only execute the program after you've compiled it and fixed any bugs. To execute the program,
you type java HelloWorld at the C:\My Documents> prompt. The
output of the program will appear in your DOS console window. To edit a program that was already compiled you must edit the original .java source file with a text editor such as NotePad. The fixed
version of the program must be re-compiled in order to see the changes when it is re-executed.
Objective #3: Explain how to download & install Eclipse for dual use on a Mac and a PC but share the same EclipseWorkspace.
- Visit http://www.eclipse.org/downloads/packages/eclipse-classic-361/heliossr1 to download both, the Mac and the PC, versions of Eclipse. Download the Mac version “Mac OS X(Cocoa 32)” and the PC version, "Windows 32-Bit"
- If you are using a Windows computer to perform these downloads, save the files to your flash drive. From there you can extract the files by right-clicking and “Extract”.
- If you are using Mac to perform these downloads, it will download to your Desktop. From there, click on the download and, once it is done extracting, move it to your flash drive.
- Once the versions of Eclipse are on your flash drive, start Eclipse. Eclipse asks where you want your files to be saved, this is known as the “Workspace”. Click Browse. Go to your flash drive and click “Make New Folder.” Name this folder “EclipseWorkspace” click “OK” This file is where all of your projects will be saved. You will need to perform this with both versions of Eclipse.