Java Reference
In-Depth Information
information to humans that can be ignored by the computer. Here, a comment is used to indicate
the purpose of the class. Singleā€line comments begin with // and function the same way.
3. Next, you have a class declaration class MyFirstApplication , and you'll find the body of the class
between curly brackets: { and } .
4. First in your class is the declaration of your main method: public static void main (String[]
args) . Remember from Chapter 2 that the main method is the entry point for execution. When a
program runs, it will start from the main method.
5. Inside the main method, between an inner set of curly brackets, you find the statements to be
executed. In this small example, there is only one statement: System.out.println("I've coded,
compiled, and run my first Java program!"); . This statement prints the text you see
between parentheses to the standard output.
6. The last two lines contain the closing bracket of the main method and the closing bracket of the
class.
7. Now, the command prompts need to be explained. First, the cd prompt changes the current direc-
tory so the .java file can be located.
8. The dir prompt simply displays the current contents of the directory. You used it to check if the
.java and .class files were located in the current directory.
9. Then you pointed Windows to your Java compiler, called javac , and instructed it to com-
pile your .java file. This may be confusing, because you need to first locate your compiler.
However, if the compiler was located in the current directory, you could have just typed javac
MyFirstApplication.java , and it would find both without needing the whole path.
10. Finally, you used the java -cp prompt to run your program. This executes the program as
explained in Steps 1-6. You should have seen the text I've created, compiled, and run my
first Java program! printed to the command window after you pressed Enter.
You may have already encountered some difficulties in the previous Try It Out. If you typed the
program yourself, it's possible you introduced some small typos that prevented your code from
properly compiling or running. You may have had trouble accessing the correct directory for reading
or writing your files. Integrated Development Environments can make this easier as they allow you
to write, compile, and run in the same place. They also check for errors as you type and remind you
when you misspell something or forget a punctuation mark. In the next sections, you learn about
some different IDEs and what they offer you as a developer.
choosing an ide
IDEs offer many tools and conveniences compared to coding in text editors and compiling from
the command line. Due to the popularity of Java, you can choose from dozens of IDEs. This topic
introduces three: Eclipse, NetBeans, and IntelliJ IDEA. Why these three? First, they are very popu-
lar, which means it's easier to find support from online communities. Second, they are all available
as open source software, so you can download and use them for free. (IntelliJ IDEA does have a
paid Ultimate Edition, which offers enhanced support for some more advanced features.) Finally,
 
Search WWH ::




Custom Search