This tutorial will cover:
- Introduction to Eclipse
- Getting Started with Eclipse
- Choosing a Perspective
- Creating a Project
- Creating a Java Program
- Compiling and Running a Java Program
- Run Java Applications from the Command Line
Introduction to Eclipse
Eclipse is a multi-language software development environment comprising an integrated development environment (IDE) and an extensible plug-in system. It is written primarily in Java and can be used to develop applications in Java and, by means of various plug-ins, other languages including C, C++, COBOL, Python, Perl, PHP etc. The IDE is often called Eclipse ADT for Ada, Eclipse CDT for C/C++, Eclipse JDT for Java and Eclipse PDT for PHP.
- Download Eclipse (i.e. eclipse-SDK-3.0.1-win32.zip) from http://download.eclipse.org/eclipse/downloads/
- Extract Eclipse (eclipse-SDK-3.0.1-win32.zip) and copy to C:\eclipse. It can be uninstalled by removing the directory (there is no entry in the registry).
- Eclipse directorywill be
- C:\eclipse\configuration\ Plug in configuration directory
- C:\eclipse\features\ Features directory
- C:\eclipse\plugins\ Plug in directory
- C:\eclipse\eclipse.exe Eclipse executable file
- Start and Close Eclipse. You just need to execute (double click) eclipse.exe file in the eclipse directory. When you start first time, you can select a workspace. The workspace is to store your projects in the directory. You may select C:\eclipse\workspace or elsewhere.
- Click a workbench icon to start using eclipse.
- To close Eclipse, click [x] button, or select [File] -> [Exit] from menu.
Note: You must install JDK 1.5 before installing Eclipse. JDK 1.5 can be downloaded from http://java.sun.com/j2se/1.5/download.html. Eclipse can run on any platform with a Java Virtual Machine.
Getting Started with Eclipse
Suppose that you have installed Eclipse files in c:\eclipse. To start Eclipse, double-click on the eclipse icon in the c:\eclipse folder, as shown in Figure 2.
The Workspace Launcher window now appears, as shown in Figure 3.
Enter c:\smith in the Workspace field and click OK to display the Eclipse UI, as shown in Figure 4. (If the workspace already contains projects, the projects will be displayed in the UI.) Workspace is actually a directory that stores your project files.
Choosing a Perspective
A perspective defines the initial set and layout of views in the window. Perspectives control what appears in certain menus and toolbars. For example, a Java perspective contains the views that you would commonly use for editing Java source files, while the Debug perspective contains the views you would use for debugging Java programs. You may switch perspectives, but you need to specify an initial perspective for a workspace. To create Java programs, set the Java perspective by choosing Window, Open Perspective, Java from the main menu, as shown in Figure 5.
The new UI is shown in Figure 6.
Creating a Project
To create a project, choose File -> New -> Project to display the New Project wizard, as shown in Figure 7. Select Java Project and click Next to display New Java Project wizard, as shown in Figure 7. Type myjavaprograms in the Project name field. As you type, the Directory field becomes c:\smith\myjavaprograms. Make sure that you selected the options Create project in workspace and Use project folder as root for sources and class files. Click Finish to create the project.
Creating a Java Program (or Class)
Now you can create a program in the project by choosing File, New, Class to display the New Java Class wizard, as shown in Figure 9.
Type Welcome in the Name field. Check the option public static void main(String args). Click Finish to generate the template for the source code Welcome.java, as shown in Figure 10.
NOTE: You may use a package by entering a package name in the Package field in Figure 10. Since the source code in the book does not use packages, the Package field is left blank to match the code in the book.
Type System.out.println(“Welcome to Java”); in the main method.
NOTE: As you type, the code completion assistance may automatically come up to give you suggestions for completing the code. For instance, when you type a dot (.) after System and pause for a second, Eclipse displays a popup menu with suggestions to complete the code, as shown in Figure 10. You can then select the appropriate item from the menu to complete the code.
Compiling and Running a Program
By default, your source code is dynamically compiled as you type. For example, if you forgot to type the semicolon (;) to end the statement, as shown in Figure 12, you will see the red wriggly line in the editor pointing to the error. To run the program, right-click the class in the project to display a context menu, as shown in Figure 13. Choose Run, Java Application in the context menu to run the class. The output is displayed in the Console pane, as shown in Figure 14.
Run Java Applications from the Command Line (Optional Step)
You also can run program standalone directly from the operating system. Here are the steps in running the Welcome application from the DOS prompt.
1. Start a DOS window by clicking the Windows Start button, Programs, MS-DOS Prompt in Windows.
2. Type the following commands to set up the proper environment variables for running Java programs in the DOS environment in Windows:
3. Type cd c:\smith\myjavaprograms to change the directory to c:\smith\myjavaprograms.
4. Type java Welcome to run the program. A sample run of the output is shown in Figure 15
NOTE: You can also compile the program using the javac command at the DOS prompt, as shown in Figure 15.
Popular Posts (last 30 days)
- Attendance Management System 730 view(s)
- JAVA Graphical User Interface (GUI) 244 view(s)
- Circular Linked Lists 219 view(s)
- Graph Implementation in C++ 202 view(s)
- Advanced Java Tutorial (For Intermediate) 174 view(s)
- Applications of Stack in data structures 171 view(s)
- File Handling using Input-Output Streams in Java 168 view(s)
- Linked lists in C++ 119 view(s)
- Top 3 open source voice broadcasting softwares 113 view(s)
- Sockets and Network Programming in Java 106 view(s)