Using Objects Java Primitive Data Types primitive integral

Using Objects

Java Primitive Data Types primitive integral byte char short int boolean long floating point float Begin with lowercase letters double

Java Reference Types Reference types: 1. String 2. Class name

String Methods • int n = greeting. length(); • String big. River = river. to. Upper. Case();

What is: Java Syntax? ?

Variables variable name data type int total; int count, temp, result; Multiple variables can be created in one declaration

What Does a Variable Declaration Do? int age. Of. Dog; 4 bytes for age. Of. Dog

Variables initial value in the declaration int sum = 0; int base = 32, max = 149;

Assignment age. Of. Dog = 10;

Variable Declarations and Assignment of Values VARIABLE DECLARATIONS ASSIGNMENT STATEMENTS

Identifiers • Rules for identifiers in Java?

package movetester; import java. awt. Rectangle; public class Move. Tester { public static void main(String[] args) { Rectangle box = new Rectangle(5, 10, 20, 30); // Move the rectangle where x becomes 20 and y becomes 35 box. translate(15, 25); // Print information about the moved rectangle System. out. println(box. get. X()); System. out. print("y: "); System. out. println(box. get. Y()); System. out. println("Expected: 35"); } }

l Packages • package areatester;

We work with Objects A fundamental entity in Java. Objects are “things”

java. lang. Object: the root of java classes

Class Object �Class encapsulates objects ◦ work together (behavior) ØObjects have properties:

Home. Work P 2. 1 - Programming Exercise

Graphical User Interfaces GUI Objects

frame Graphical User Interfaces (GUI): Demonstrates the object concep 0 t! Content pane used to display objects in a frame

01: import javax. swing. JFrame; 02: 03: public class Empty. Frame. Viewer 04: { 05: public static void main(String[] args) 06: { 07: JFrame frame = new JFrame(); 08: 09: frame. set. Size(300, 400); 10: frame. set. Title("An Empty Frame"); frame. set. Default. Close. Operation(JFrame. EXIT_ON_CLOSE); 12: 14: 15: } frame. set. Visible(true); } Example: Frame Viewer

Jframe 1. Point to object frame = new JFrame (name); (creates a class instance)

See Sun site for greater detail Sun. java

Lab 2: Graphical Fun 1. Using the example in your text book on page 64; Section 2. 13: a. Create your own Face. Viewer Class with a main method that will show a JComponent. b. Adjust your Frame to be square c. The frame title must contain your name. 2. Using the Face. Component example as a guide (page 64; Section 2. 13): a. Create an Animal Viewer and draw an animal of your choice. b. Draw a string that describes the animal c. Set colors as desired

Output ◦ Two classes - tested ◦ Upload to the appropriate dropbox Lab Completion

Object Lessons?
- Slides: 25