Java Reference
In-Depth Information
Chapter 2
Writing Java Programs
In this chapter, you will learn
How to write, compile, and run Java programs using command prompts and the NetBeans
integrated development environment (IDE)
CLASSPATH for running Java programs
How to set the
Briefly about the Java Virtual Machine (JVM) and the Java Platform
What is a Java Program?
A Java program, which is written using the Java programming language, is a set of instructions to be executed by a
computer to perform a task. In this chapter, you will write a simple Java program that prints a message on the console,
for example, a command prompt on Windows. This chapter explains only the basics involved in writing a Java
program. A detailed explanation of all aspects of a Java program will be covered in subsequent chapters.
Writing a Java program involves three steps:
Writing the source code
Compiling the source code
Running the compiled code
You can write Java programs using a text editor of your choice, such as Notepad on Windows, vi editor on UNIX,
etc. The source code is compiled into object code, also known as bytecode, using a Java compiler. The compiled code
(object code or bytecode) is run by a JVM. You can also use an IDE such as NetBeans to write Java programs. This
chapter shows how to write Java programs using both a text editor and the NetBeans IDE.
System Requirements
You need to have the following software installed on your computer:
Java Development Kit 8
NetBeans IDE 7.4 or later
It is not necessary to have NetBeans to use the programs in this topic. However, the NetBeans IDE makes working
with Java programs easy. You can use any other IDE, for example, Eclipse, JDeveloper, IntelliJ IDEA, etc. The source
code for this topic contains a NetBeans project. If you use an IDE other than NetBeans, you will have to copy the
contents of the src directory, from the source code bundle for this topic, to the source code directory created for the
project by your IDE.
 
Search WWH ::




Custom Search