Final- Java Chap 2 Gaddis Flashcards
A Java source code file contains one or more Java…
classes
Rule: If more than one class is in a source code file…
only one of them may be public
The public class and the filename of the source code file…
must match
Each Java class can be separated into…
parts
to compile vs to run
to compile:
javac Simple.java
to run:
java Simple
curly braces
contain all of the data and methods for a class. They open on the line after the class header
after the class header and the opening curly bracket, there is a…
method header and an opening curly bracket for the method
method headers look like this:
public statis void main (String[] args)
{
The application begins
after the method header
Between the curly brackets of the method are…
all the actions to be completed during said method
Java statement that is executed when the program runs
is indented and within the curly brackets of the method.
ex: System.out.println(“Programming rocks!”);
Ignored by compilers
comments
the class header communicates that
other classes can use it (public), that it is a java class (class), and the name (Simple)
curly braces
define the scope of a class or method
In this method:
public static void main(String[] args)
args is…
a variable name that can be programmer defined
The method
is the line of code that the java command will run first. It starts the program
Every Java application must have a
main method
When the program runs, the statements within the main method will be
executed
Semi-colons only end lines that…
are java statements. Not comments or java framework like class headers or method headers
A .java file may contain many classes but may only have…
one public class
If a .java file has a public class, the class must have…
the same name as the file.
//
marks the beginning of a single line comment. Anything after the // on the line will be ignored by the compiler
( )
used in a method header to mark the parameter list
{ }
encloses a group of statements, such as the contents of a class or a method
” “
Encloses a string of characters, such as a message that is to be printed on the screen
;
marks the end of a complete programming statement