Sie sind auf Seite 1von 4

Summary of Chapter 1

1. form: You learned how to write a class definition in Java. Every class definition has the following

The <class name> must be a single word and always begins with a capital letter. 2. The class definition will contain one or more method definitions, one of the method definitions

must be named main and is known as the main method definition. The main method definition looks like:

The main method definition is where the computer begins to execute the program. 3. A simple Java program will look like:

In the above example, the name of the class definition is Simple, and the class definition contains one method definition named main.

4.

Any time you want to do some (possibly complicated) work in Java, call a method to do the

work. In this course, almost all of the work your programs will do will be accomplished by calling

methods. Think of a method like a bit of hidden Java code that makes the computer do some work.
We will look at some of the methods that are called in Chapter 1 below.

5.

Key Programming Concept: Output

One of the key concepts in programming is known as Output. Any time a programmer wants the computer to display information on the screen, your program must do Output. There are 2 simple ways of doing Output in Java and both ways are illustrated in Chapter 1. Each way of doing output is accomplished by calling a method. a. Call the println( ) method to display information in the Output window.

The above program calls the println( ) method to display the String I am so %&#$@ happy! in the output window. Notice that you can put any characters you want in a String. When you call the println( ) method, anything that you put between the parentheses will be displayed in the output window on one line println is pronounced print line. b. Call the print( ) method to display information in the Output window.

In the above program, if you changed the name of the method to print instead of println, then after displaying the String, the cursor would stay at the end of the String (it wouldnt advance to the next line).

c.

Call the showMessageDialog( ) method to display information in a pop-up dialog box.

The above program will not compile because the class JOptionPane will have a red underline. This is because the code for the JOptionPane class must be imported into your program.

In NetBeans, just right-click anywhere in your code and select Fix Imports. This will automatically put the following line at the top of your program and then your code will compile.

When you run the program you will see the Output:

Das könnte Ihnen auch gefallen