Chapter 2 Java Fundamentals Goals Introduce the Java syntax necessary to write programs Be able to write a program with user input and console output Evaluate and write arithmetic expressions Use a few of Java's types such as and int double 2.1 Elements of Java Programming The essential building block of Java programs is the In essence, a Java class is a sequence class. of characters (text) stored as a file, whose name always ends with Each class is comprised .java. of several elements, such as a class heading (public and methods—a class class-name) collection of statements grouped together to provide a service. Below is the general form for a Java class that has one method: Any class with a method, including those with only main. main a method, can be run as a program. main A simple Java program (only one class) General Form: Comments: any text that follows // on the same line // package-name.class-name; import class-name public class { public static void main(String[] args) { variable declarations and initializations messages and operations such as assignments } } General forms describe the syntax necessary to write code that compiles. The general forms in this textbook use the following conventions: Boldface elements must be written exactly as shown. This includes words such as and symbols such as and). public static void main [, ], (, Italicized items are defined somewhere else or must be supplied by the programmer.
Chapter 2 Java Fundamentals Goals Introduce the Java syntax necessary to write programs Be able to write a program with user input and console output Evaluate and write arithmetic expressions Use a few of Java's types such as int and double 2.1 Elements of Java Programming The essential building block of Java programs is the class. In essence, a Java class is a sequence of characters (text) stored as a file, whose name always ends with .java. Each class is comprised of several elements, such as a class heading (public class class-name) and methods—a collection of statements grouped together to provide a service. Below is the general form for a Java class that has one method: main. Any class with a main method, including those with only a main method, can be run as a program. General Form: A simple Java program (only one class) // Comments: any text that follows // on the same line import package-name.class-name; public class class-name { public static void main(String[] args) { variable declarations and initializations messages and operations such as assignments } } General forms describe the syntax necessary to write code that compiles. The general forms in this textbook use the following conventions: Boldface elements must be written exactly as shown. This includes words such as public static void main and symbols such as [, ], (, and). Italicized items are defined somewhere else or must be supplied by the programmer.
227Sum15.docx