AP Computer Science/Testing Java
Software Tools[edit]
To write and test Java, you will need to the appropriate tools. The two main tools you will need are the Java Software Development Kit (Java SDK or JDK) and an Integrated Development Environment (IDE). The JDK includes all the tools your computer will need to build and run Java programs. While a simple text editor could be good enough for writing Java code, the text editor cannot compile the code, or put the code together so that it can execute, or run on a computer. An IDE uses the SDK to compile Java code and turn it into an executable program. A popular and widely-used IDE with many features is Eclipse.
First Java Program[edit]
When you first learn any computer programming language, one of the first things you may learn to do is write a Hello World program, a program that simply prints the phrase "Hello, world!" on your computer screen. Create a new file titled "HelloWorld.java" using an IDE and type the following code in the file:
public class HelloWorld { public void main(String args[]) { System.out.println("Hello, world!"); } }
Now save this file and compile it using your IDE, then execute the program. This program should print the following message on your screen:
Hello, world!
Congratulations! You've just written your first Java program. Later sections of this book will explain what these words mean, how to write longer and more complex programs, and how to understand code that is already written.