Embed
Email

Java_tutorial

Document Sample

Categories
Tags
Stats
views:
1
posted:
11/19/2011
language:
English
pages:
6
Steps to compile and run Java programs using NetBeans

The software to be installed prior to writing a Java program is



1. The J2SE Development Kit (JDK)

For Microsoft Windows, Solaris OS, and Linux: http://java.sun.com/javase/6/download.jsp



2. NetBeans IDE 6.0 or higher version

http://www.netbeans.info/downloads/index.php



An Integrated Development Environment (IDE) is a software application that provides

comprehensive facilities to computer programmers for software development. An IDE normally consists

of a Source code Editor, a compiler, build automation tools and a debugger.



Please follow the steps to Create, Build and Run applications in the IDE (Integrated Development

Environment)



Create a project in NetBeans IDE:



Creating an IDE project enables us to create an environment to build and run the applications. It

eliminates configuration issues normally associated with developing on the command line.



Steps:



1. Start NetBeans IDE by clicking on the NetBeans IDE application icon or by going to Start > All

Programs > NetBeans IDE item or typing the NetBeans IDE item in the Start Menu.

2. In the IDE, go to File > New Project

3. In the New project wizard, under the Categories pane, select the Java category. Select the Java

Application under the Projects pane and Click “Next”.









4. The New Java Application dialog box appears and in the Name and Location Page of the wizard

a. Enter the Project Name

b. Enter/ Browse the Location of the Project

c. Enter the Project Folder

5. Leave the Set as Main Project checkbox selected and click Finish as illustrated in the figure

above.

6. Now that the Project is created and opened in the IDE, the following components can be seen

a. The Projects window which contains a tree view of the components of the project that

includes source files, libraries etc.

b. The Source Editor window which contains the code for the program. The entire program

should be written in the source editor.

c. The Navigator window which can be used to quickly navigate between the elements

within the selected class









To compile a sample program for instance say the HelloWorld program, type the code at the

“//TODO code application logic here”. The following screenshot shows the process.

7. To save the program, go to main menu and choose File > Save



Compiling the Source File:



The IDE invokes the Java programming language compiler (javac), which takes your source file

and translates its text into instructions that the Java virtual machine can understand. The instructions

contained within this file are known as bytecodes.



Steps:



1. To compile the source code, choose Build > Build Main Project from the IDEs main menu.

2. The output for the build process can be viewed by choosing Window > Output > Output from

the IDEs main menu.

a. If the compilation is successful, the output window notifies of the successful compilation

b. If the compilation is unsuccessful, make changes to the code in the editor window and

compile the source file again.

Running the Source File:



1. From the IDE menu bar, choose Run > Run Main Project.









Steps to compile and run Java programs using the Command prompt

1. The program to be compiled and run can be written either in a Text Editor or a Notepad and

saved according to the specifications.

For example: Let us create a simple Program to print “HelloWorld”



Let us consider the following code written in a notepad



public class HelloWorld

{

public static void main (String [] args)

{

System.out.println(“HelloWorld”);

}

}



2. Save the file as HelloWorld.java

3. Open the command prompt.

4. Set the path to the directory where the “HelloWorld” program is saved.

5. To Compile the program the command is javac Filename .java

Suppose the program is saved as HelloWorld.java in the file directory FirstProgram in C drive

The command to compile the program is:

C:\FirstProgram>javac HelloWorld.java

Here the javac creates a class file HelloWorld.class file. Both the HelloWorld.java and

HelloWorld.class can be found in the directory specified.



6. To run the program the command is java filename

For the example we considered it is

C:\FirstProgram>java HelloWorld



Related docs
Other docs by Stariya Js @ B...
Lab2_Fishing_lab_pack
Views: 0  |  Downloads: 0
JMK sample legal brief
Views: 1  |  Downloads: 0
DriveQ
Views: 0  |  Downloads: 0
cybersecurity_reform_-_senate_bill_eyes
Views: 0  |  Downloads: 0
Opening and Marketing
Views: 0  |  Downloads: 0
Making_it_Work_notes
Views: 0  |  Downloads: 0
First Announcement 7th ISFS_
Views: 0  |  Downloads: 0
as90173
Views: 0  |  Downloads: 0
VNAfashionshow2010
Views: 0  |  Downloads: 0
By registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!