Java Reference
In-Depth Information
FIGURE 2.1:
Creating a new Java project.
will create some default code. However, we will write all the code from scratch. Also, please
make sure that
Set As Main Project
is selected. This will guarantee that the new project
is the main project (i.e., the project that will be executed when the green forward arrow is
clicked). As a last step, click the
Finish
button.
Next, we need to create the Java files. For now, our code will consist of a single file.
In the project menu, expand the project
HelloWorld
and right-click on
Source Packages
.
Select
New
and then
Java Class
.Type
Main
as the name of the class. Enter
helloworld
as the package name; see Figure 2.3. Click the
Finish
button.
A new file is created. It should contain roughly the following text.
package
helloworld ;
public class
Main
{
}
The only difference between this file and the file you will see will be the
comments
.
Comments are usually written in a natural language, such as English. They are meant to be
read by other humans and not by computers. Comments have no effect on how the program
is executed. There are two ways to create comments. A one-line comment is created by
typing // followed by some text description. Consider the following code.
package
helloworld ;
public class
Main
{
public static void
main(String args [])
{
// start of program
}
}