Chapter 1 Primitive Java
import java.io.*; /* an example program */ public class Example1 { public static void main (String[] args) { System.out.println("Hello World!"); }
Jargon and Syntax Review zclass - data fields and methods that describe the state and behavior of an object zmethod - a section of code that provides behavior for an object zcomments - notes to programmers that are ignored by the compiler. /* */ and //
Identifiers za name we make up zmust start with a letter zfollowed by any combination of letters, digits, and some “special” characters zcan not be a keyword zshould be meaningful
Primitive Types zbyte zshort zint zlong z float z double z char z boolean
Typed Constants zType determined by compiler
Reference Types zAll non-primitive types zstores a “reference” to a memory address where the object is located
Declarations int i; String s; long size = 5; String name = “George”;
OPERATORS assignment= compound assignment+= *= etc. binary arithmetic+ - / % unary++ -- binary relational== > = <= logical&& || !
Control Structures zSequence zSelection zRepetition
Some Loop Patterns zRead/process loop zSentinel controlled loop zCounted loop
Creating a Loop é Initialization é Termination é Body