Semester Review
Chapters 1-7
Chapters from the text
• Chapter 1 Introduction
• Chapter 2 Java Applications (omit section 2.9)
• Chapter 3 Classes and Objects (omit sections 3.9 & 3.10)
• Chapter 4 Control Statements (omit sections 4.14 & 4.15)
• Chapter 5 Control Statements (omit sections 5.10 & 5.11)
• Chapter 6 Methods (omit sections 6.13 & 6.14)
• Chapter 7 Arrays (omit sections 7.13 & 7.14)
• Be sure to read the Wrap-Up at the end each chapter
Primitive types in Java
• Integers
– int and long
• Floating points
– float and double
• boolean—either true or false
• character
Classes and Objects
• Every class is also a type
• It is template that shows what objects of that type will be
• A class encapsulates the data members of a type together with the methods that manipulate the object
• An object is one instance of the class
Declaring variables
– Java stores primitives differently than objects
• The value of a primitive itself is stored in the variable location
• All objects store the address where they can be found, not the object itself
• This address is called a reference variable
• All objects are stored in dynamic memory
– The operating system sets aside space in dynamic RAM when requested by the executing program
– The request for space is made by the keyword new
I/O
• We used the Scanner class for input; it has several methods that can be called depending on the type of input the program is expecting
• For output, we used .printf( ), print( ), and println( ), preceeded by System.out
• printf( ) gives you more control over the formatting of output
• The concatenation sysbol “+” can be used with print( ) or println( )
Memory Concepts
• The executable program and space for the data it declares is stored in static RAM (the stack)
• As the program runs, declaring an object requires calling a constructor.
This call to a constructor asks the operating system for space in dynamic RAM (the heap) to store the object.
It returns the address of the space allocated.
Control structures
• Order of execution of a program is controlled by if/else statements and loops
Selection & repetition statements
• while loops and for loops
All loops must have
• An statement initialize a control variable
• A statement to terminate the loop
• A statement to change the control variable so the loop terminates
A for loop does all three of these things in the for parentheses
The programer must do all three separately with a while loop
Operators
• Arithmetic operators
• Relational operators
= = != < > <= >=
• Logical operators
And or not
Methods
• Every method must have
A return type
A method name
Parentheses for arguments
• A method may also have
An access specifier (public or private)
The keyword static
• The method call transfers information to the method, and receives information back from the method
Arrays
• An array is a data structure that holds a collection of related data of one type
• The individual elements of an array are named using the array name and a subscript in [ ]
• The subscript must be an integer, or an int variable
• Arrays are processed using for loops
Strings
• The most important thing to remember about Strings is that you cannot compare them with = =
• You must use dot equals
• If you want not equals, you use
!(obj1.equals(obj2))