Chapter 3: Using Classes and Objects

Similar documents
We now start exploring some key elements of the Java programming language and ways of performing I/O

A variable is a name for a location in memory A variable must be declared

Using Classes and Objects. Chapter

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string

Using Java Classes Fall 2018 Margaret Reid-Miller

Formatting Output & Enumerated Types & Wrapper Classes

COMP-202 Unit 8: Basics of Using Objects

Classes and Objects Part 1

Chapter 2: Data and Expressions

CSCI 2010 Principles of Computer Science. Basic Java Programming. 08/09/2013 CSCI Basic Java 1

Chapter 2: Data and Expressions

More on variables and methods

Objectives of CS 230. Java portability. Why ADTs? 8/18/14

The Math Class (Outsource: Math Class Supplement) Random Numbers. Lab 06 Math Class

static int min(int a, int b) Returns the smaller of two int values. static double pow(double a,

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 6, Name:

Primitive Data Types: Intro

H212 Introduction to Software Systems Honors

Chapter 4 Classes in the Java Class Libraries

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name:

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 11, Name: KEY

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 2, Name:

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 1, Name: KEY A

Data Conversion & Scanner Class

ECE 122. Engineering Problem Solving with Java

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

ECE 122 Engineering Problem Solving with Java

Using Classes and Objects

Object-Based Programming. Programming with Objects

Full file at

Objects and Classes 1: Encapsulation, Strings and Things CSC 121 Fall 2014 Howard Rosenthal

Class API. Class API. Constructors. CS200: Computer Science I. Module 19 More Objects

CS 302: Introduction to Programming

Object-Oriented Programming

Using Classes and Objects Chapters 3 Creating Objects Section 3.1 The String Class Section 3.2 The Scanner Class Section 2.6

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Final Examination

CSC Algorithms and Data Structures I. Midterm Examination February 25, Name:

Lab5. Wooseok Kim

STUDENT LESSON A10 The String Class

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Final Examination

Mathematical Functions, Characters, and Strings. CSE 114, Computer Science 1 Stony Brook University

Lab5. Wooseok Kim

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 9, Name: KEY

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java

Chapter 3 Using Classes and Objects

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 25, Name: KEY A

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 26, Name: Key

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2010) - All Sections Midterm Examination

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Midterm Examination

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous

Midterm Exam 2 Thursday, November 15th, points (15% of final grade) Instructors: Jim Williams and Marc Renault

Computational Expression

Computer Science 145 Midterm 1 Fall 2016

Computational Expression

CHAPTER 7 OBJECTS AND CLASSES

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

Overloaded Methods. Sending Messages. Overloaded Constructors. Sending Parameters

Mathematical Functions, Characters, and Strings. CSE 114, Computer Science 1 Stony Brook University

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

AP Computer Science A

COMP102: Test. 26 April, 2006

CHAPTER 7 OBJECTS AND CLASSES

Learning objectives: Objects and Primitive Data. Introduction to Objects. A Predefined Object. The print versus the println Methods

TeenCoder : Java Programming (ISBN )

To define methods, invoke methods, and pass arguments to a method ( ). To develop reusable code that is modular, easy-toread, easy-to-debug,

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline

Midterms Save the Dates!

Packages & Random and Math Classes

F1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept

Chapter 5 Methods. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Chap. 3. Creating Objects The String class Java Class Library (Packages) Math.random() Reading for this Lecture: L&L,

Chapter. Let's explore some other fundamental programming concepts

Methods CSC 121 Fall 2016 Howard Rosenthal

Hello World. n Variables store information. n You can think of them like boxes. n They hold values. n The value of a variable is its current contents

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner

Using Classes and Objects

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

COMP-202 Unit 5: Basics of Using Objects

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Strings. Strings and their methods. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

Methods CSC 121 Spring 2017 Howard Rosenthal

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Multiple Choice Using Object Methods

Java By Abstraction - Test-B (Chapters 1-6)

Introduction to Programming Using Java (98-388)

PIC 20A Number, Autoboxing, and Unboxing

Full file at

Class Library java.lang Package. Bok, Jong Soon

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

CS110: PROGRAMMING LANGUAGE I

STUDENT LESSON A7 Simple I/O

Java Basic Introduction, Classes and Objects SEEM

OBJECT ORIENTED PROGRAMMING IN JAVA

Transcription:

Chapter 3: Using Classes and Objects CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 3: Using Classes and Objects CS 121 1 / 51

Chapter 3 Topics Intro to Object-Oriented Programming Using Classes and Objects The Graphics class The Scanner class The Random class Formatting output The Math class The String class Wrapper classes and autoboxing Chapter 3: Using Classes and Objects CS 121 2 / 51

Brief Intro to Object-Oriented Programming Java is an object-oriented programming language. Objects can be used to represent real-world things. Objects have state and behaviors. Dog state: name, breed, color, age, hungry, etc. behavior: walk, run, bark, lick, fetch String "Hello World!" state: length, characters behavior: get length, equals, sub-string, compare to, to upper case, etc. Chapter 3: Using Classes and Objects CS 121 3 / 51

Classes Objects are defined by classes. Multiple objects can be created from the same class. Variables represent the object s state (attributes, properties). Methods define behaviors (functions, actions). Chapter 3: Using Classes and Objects CS 121 4 / 51

Classes and Objects We can think of a class as the blueprint of an object. One blueprint to create several similar, but different, houses. Chapter 3: Using Classes and Objects CS 121 5 / 51

Classes and Objects An object is an instance of a class. Objects are encapsulated, meaning the state and behaviours are wrapped together as a single unit. Encapsulation is one of the four fundamental Object-Oriented Programming (OOP) concepts. The other three are inheritance, polymorphism, and abstraction. (You will see these in CS 221). Chapter 3: Using Classes and Objects CS 121 6 / 51

Encapsulation A visual example of encapsulation of the String object. An analogy of a real-world object that uses encapsulation. Chapter 3: Using Classes and Objects CS 121 7 / 51

Using Classes and Objects For now, we will be using classes that other people have created. After we grasp the basic concepts of how to use them, then we will see how to write our own classes. Chapter 3: Using Classes and Objects CS 121 8 / 51

The Java API The Java API is the standard class library that provides a large collection of pre-built classes that we can use in our programs. API = Application Programming Interface Before writing our own classes, we will practice using several classes that are part of the Java API. The classes of the Java API are organized into packages. Java comes with hundreds of packages and tens of thousands more can be obtained from third-party vendors. Java API docs: http://docs.oracle.com/javase/8/docs/api/ Chapter 3: Using Classes and Objects CS 121 9 / 51

Selected Java Packages Package java.lang java.util java.io java.awt java.swing java.net java.security Provides Fundamental classes Various useful utility classes Classes for variety of input/output functions Classes for creating graphical user interfaces and graphics Lightweight user interfaces that extend AWT capabilities Networking operations Encryption and decryption Chapter 3: Using Classes and Objects CS 121 10 / 51

Import Declarations When you want to use a class from a Java API package, you need to import the package. import java.awt.graphics; To import all classes in a package, you can use the wild card character (*). import java.awt.*; All classes in the java.lang package are automatically imported into all programs. This includes String and System (among others) Chapter 3: Using Classes and Objects CS 121 11 / 51

Declaring and Instantiating Objects We must declare and initialize our objects before we can use them. This is very similar to what we did with primitive data type variables, except we must also instantiate our objects. int coursenumber = 121; Color grass = new Color (0, 255, 0); For example, we use the new operator to instantiate a new Color object, which is an instance of the Color class. If we don t use the new operator, and just declare an object, this does not create an instance of the class. Color color ; // this variable refers to // nothing ( aka. null )!! Chapter 3: Using Classes and Objects CS 121 12 / 51

Instantiating an Object String coursename = new String (" CS 121 "); // more on Strings in a minute Color grass = new Color (0, 255, 0); When we use the new operator, this calls the class constructor a special method that sets up the object. The new object is an instance of the class blueprint. Chapter 3: Using Classes and Objects CS 121 13 / 51

Instantiating String Objects (a special case) We don t have to use the new operator to create a String. String coursename = new String (" CS 121 "); // is the same as String coursename = " CS 121 "; This is only supported for String objects (because they are so frequently used). The Java compiler creates the object for us as a convenience. Chapter 3: Using Classes and Objects CS 121 14 / 51

Reference Variables vs. Primitive Variables Primitive variables and object variables store different information. Primitive variables (e.g. int, char, boolean) contain the value itself. int coursenumber = 121; The variable referring to an object is known as a reference variable. String coursename = new String (" CS 121 "); It holds the address (aka. reference) of where the actual object data is stored in memory. We sometimes say it points to the object. Chapter 3: Using Classes and Objects CS 121 15 / 51

Reference Variables: The Hulk Chapter 3: Using Classes and Objects CS 121 16 / 51

Assignment Revisited Recall: The act of assignment takes a copy of a value (the Right-Hand-Side) and stores it in the target variable (the Left-Hand-Side). For primitive types, the value of the variable is copied. Chapter 3: Using Classes and Objects CS 121 17 / 51

Assignment Revisited For objects, the address of the object is copied. Chapter 3: Using Classes and Objects CS 121 18 / 51

Aliases Two or more references that refer to the same object are aliases of each other. A single object can be accessed using multiple references. This is useful, but can cause issues if not managed properly. Changing an object through one reference changes it for all of its aliases, because there is really only one object stored in memory. Chapter 3: Using Classes and Objects CS 121 19 / 51

Garbage Collection If there are no variables that refer to an object, the object is inaccessible and referred to as garbage. Java performs automatic garbage collection in the background, reclaiming the memory used by garbage objects for future use. In some languages, the programmer is responsible for freeing the memory used by garbage objects. Chapter 3: Using Classes and Objects CS 121 20 / 51

Invoking Methods of an Object After we instantiate an object, we can use the dot operator to invoke its methods (or behaviors). Invoking an object s method can be thought of as asking the object to do something. Methods may return values that can be used in an assignment or expression. String coursename = new String (" CS 121 "); int length = coursename. length (); // the value of length will be 6 Chapter 3: Using Classes and Objects CS 121 21 / 51

Invoking Methods of an Object Methods may also accept parameters that provide additional information that it may need to perform the requested behavior. String coursename = new String (" CS 121 "); String newcourse = coursename. replace ('1', '2'); // the value of newcourse will be " CS 222" char first = coursename. charat (0) ; // the value of first will be 'C' Chapter 3: Using Classes and Objects CS 121 22 / 51

In-Class Exercise What is the difference between a class and an object? Objects are encapsulated. What does this mean? What does it mean to instantiate an object? Write one line of code to instantiate a Scanner to read from System.in. What is a reference variable? What is the value of a reference variable if the object it is supposed to refer to is not instantiated? How do you tell an object to perform an action/behavior? Chapter 3: Using Classes and Objects CS 121 23 / 51

Intro to Java Graphics The Graphics class from the java.awt package is a useful class for drawing shapes on a canvas. See the Intro to Graphics notes for details on how to use the Graphics class. Chapter 3: Using Classes and Objects CS 121 24 / 51

The Scanner class The first tool, or class, we will use from the Java API is the Scanner. It is used when we want our programs to interact with our users. The Scanner class is part of the java.util class library. It must be imported. import java.util.scanner; It provides methods for reading input values of various types. A Scanner object can read input from various sources (e.g. keyboard, file) See Java 8 API docs: http://docs.oracle.com/javase/8/ docs/api/java/util/scanner.html Chapter 3: Using Classes and Objects CS 121 25 / 51

Using the Scanner Create a new Scanner object that reads from the keyboard. Scanner scan = new Scanner(System.in); The new operator creates a new Scanner object. The System.in object represents keyboard input. After the object is created, we can invoke various input methods it provides. Chapter 3: Using Classes and Objects CS 121 26 / 51

Example Example: Convert TempConverter.java to interactive program. Example: Echo.java Chapter 3: Using Classes and Objects CS 121 27 / 51

Input Tokens By default, white space is used to separate input elements (called tokens). White space includes Space characters ( ) Tab characters ( \t ) New line characters ( \n and \r ) The next, nextint, nextdouble, etc. methods of the Scanner class read and return the next input tokens. See Scanner documentation for more details. Chapter 3: Using Classes and Objects CS 121 28 / 51

Example Example: GasMileage.java Chapter 3: Using Classes and Objects CS 121 29 / 51

The Random Class The Random class provides methods that generate pseudorandom numbers. The class is part of the java.util package. True random numbers are usually generated from nature or physical processes. Give some examples of physical processes that generate random numbers: Flipping a coin Rolling dice Shuffling playing cards Brownian motion of molecules in a liquid Pseudorandom numbers are generated using algorithms that start with a seed value. The values generated pass statistical tests. There are two main advantages of pseudorandom numbers: Unlimited supply Reproducibility Random numbers are used in simulations, security, testing software, design, games and many other areas. Chapter 3: Using Classes and Objects CS 121 30 / 51

Selected Methods in the Random class Random Random() Constructor: creates a new pseudorandom generator Random Random(long seed) Constructor: with a seed value to be able to reproduce random sequence int nextint(int bound) returns a random number over the range 0 to bound-1 int nextint() returns a random number over all possible values of int double nextdouble() returns a double random number between 0.0 (inclusive) and 1.0 (exclusive) Chapter 3: Using Classes and Objects CS 121 31 / 51

Using the Random Class Import the class, construct an instance and then use the appropriate methods. import java.util.random; Random generator = new Random(); System.out.println(generator.nextInt(10)); System.out.println(generator.nextInt(10)); Use the constructor with a seed argument to create a pseudorandom number sequence that is the same each time: import java.util.random; long seed = 12345; //arbitrary number! Random generator = new Random(seed); System.out.println(generator.nextInt(10)); System.out.println(generator.nextInt(10)); Example: DiceRoll.java, RandomNumbers.java Chapter 3: Using Classes and Objects CS 121 32 / 51

In-Class Exercises 1. Given an Random object named generator, what range of values are produced by the following expressions? generator.nextint(25) generator.nextint(10) + 1 generator.nextint(50) + 100 generator.nextint(10) - 5 generator.nextint(21) - 10 2. Write an expression using generator that produces the following range of random values: 0 to 12 1 to 100 15 to 20-10 to 0 3. Create a random color using the Color class and the Random class. 4. Create a random position within a grid of width, w, and height, h, using the Random class. Chapter 3: Using Classes and Objects CS 121 33 / 51

Formatting Output (1) The java.text package provides several classes to format values for output. In this course, we will focus on classes for formatting numbers. NumberFormat: formats numerical values (e.g. currency or percentage). DecimalFormat: (a sub-class of NumberFormat) formats decimal values based on a pattern. The following code snippets that show the usage of the NumberFormat class. The import statement will be at the top of the Java source file. import java. text. NumberFormat ; NumberFormat currfmt = NumberFormat. getcurrencyinstance (); double amount = 1150.45; System. out. println (" Amount : " + currfmt. format ( amount )); NumberFormat percfmt = NumberFormat. getpercentinstance (); double passrate =.8845; System. out. println (" Amount : " + percfmt. format ( passrate )); Example: BasicNumberFormat.java, Purchase.java Chapter 3: Using Classes and Objects CS 121 34 / 51

Formatting Output (2) The DecimalFormat allows us to format values based on a pattern. For example, we can specify the number should be rounded to three digits after the decimal point. Uses Half Even Rounding to truncate digits: round towards the nearest whole neighbor unless both whole neighbors are equidistant, in which case, round towards the even neighbor. See here for details: http://docs. oracle.com/javase/8/docs/api/java/math/roundingmode.html A code snippet that shows the usage: import java. text. DecimalFormat ; DecimalFormat fmt = new DecimalFormat (" 0.### "); double amount = 110.3424; System. out. println (" Amount : " + fmt. format ( amount )); // shows 110.342 We can change the rounding mode with the setroundingmode method: fmt. setroundingmode ( RoundingMode. CEILING ); System. out. println (" Amount : " + fmt1. format ( amount )); // shows 110.343 Example: BasicDecimalFormat.java Chapter 3: Using Classes and Objects CS 121 35 / 51

Formatting Output (3) Commonly used symbols in the pattern: 0 digit (int, short, byte) # digit, zero shows as absent. decimal separator, grouping separator (for large numbers) E show in scientific notation Example: CircleStatsDecimalFormat.java We can set minimum and maximum limits on integer and fractional digits. For more information, see the javadocs for the DecimalFormat class. Chapter 3: Using Classes and Objects CS 121 36 / 51

In-Class Exercise What do the following patterns accomplish? 1. "##.###" 2. "00.###" 3. "###,###" 4. "000,000" Chapter 3: Using Classes and Objects CS 121 37 / 51

Formatting Output (4) The class Formatter from the java.util package provides an alternative way of formatting output that is inspired by the printf method in C language. import java. util. Formatter ; Formatter fmt = new Formatter ( System. out ); double area = 1150.45; fmt. format (" The area is %f\n", area ); Here the %f is a conversion template that says to format the variable area as a floating point number and insert in the output. Various conversions are available for printing a wide variety of types. Convenience methods exist in the System.out object to use Formatter class methods. System. out. printf (" The area is %f\n", area ); We can also format a String object, which often comes in handy. String output = String. format (" The area is %f\n", area ); In each case, the underlying method used is the same. Chapter 3: Using Classes and Objects CS 121 38 / 51

Selected printf Style Formatting Conversions Commonly used conversions: %d decimal (int, short, byte) %ld long %f floating point (float, double) %e floating point in scientific notation %s String %b boolean Some examples of variations on the default formatting: %10d use a field 10 wide (right-aligned for numeric types) %8.2f use a field 8 wide, with two digits after the decimal point %-10s left justified string in 10 spaces (default is right justified) Note that if the output doesn t fit in the number of spaces specified, the space will expand to fit the output. Examples: CircleStatsFormatter.java, CircleStatsPrintfTable.java, PrintfExample.java, Chapter 3: Using Classes and Objects CS 121 39 / 51

The Math Class The Math contains methods for basic mathematical operations like exponentiation, square root, logarithm and trigonometric functions. Part of the java.lang package so no need to import. The methods in the Math class are static methods (also known as class methods). Static methods can be invoked using the class name no Math object needs to be instantiated. For example: double value = Math.sin(Math.PI) + Math.cos(Math.PI); Examples: Quadratic.java, TrigDemo.java Chapter 3: Using Classes and Objects CS 121 40 / 51

Selected Methods in the Math class static int abs(int num) static double sqrt(double num) static double ceil(double num) static double floor(double num) static double log(double num) static double log10(double num) static double pow(double num, double power) static double min(double num1, double num2) static double max(double num1, double num2) static int min(int num1, int num2) static int max(int num1, int num2) static double sin(double angleinradians) static double cos(double angleinradians) static double tan(double angleinradians) static double toradians(double angleindegrees) static double todegrees(double angleinradians) Chapter 3: Using Classes and Objects CS 121 41 / 51

The String Class In Java, strings are immutable: Once we create a String object, we cannot change its value or length. The String class provides several useful methods for manipulating String objects. Many of these return a new String object since strings are immutable. For example: String babyword = " googoo "; String str = babyword. touppercase (); See javadocs for String for list of available methods: http://docs.oracle.com/javase/8/docs/api/java/ lang/string.html Chapter 3: Using Classes and Objects CS 121 42 / 51

Selected Methods in String class int length() char charat (int index) String tolowercase() String touppercase() String trim() boolean equals(string str) boolean equalsignorecase(string str) int compareto(string str) String concat(string str) String replace(char oldchar, char newchar) String substring(int offset, int endindex) returns a string that equals the substring from index offset to endindex - 1 int indexof(char ch) int indexof(string str) returns the index of the first occurrence of character ch or string str Chapter 3: Using Classes and Objects CS 121 43 / 51

String Representation The String class represents a string internally as a series of characters. These characters have an index that we can use to refer to a specific character. We can use the charat(int index) method to get the character at the index position. char ch = babyword.charat(0); char ch = babyword.charat(4); Chapter 3: Using Classes and Objects CS 121 44 / 51

String Examples Example: StringPlay.java What output is produced by the following code? String babywords = "googoo gaagaa"; System.out.println(babyWords.length()); System.out.println(babyWords.toUpperCase()); System.out.println(babyWords.substring(7, 10)); System.out.println(babyWords.replace( g, m )); System.out.println(babyWords.length()); Chapter 3: Using Classes and Objects CS 121 45 / 51

Wrapper Classes (1) The java.lang package contains wrapper classes corresponding to each primitive type. byte short int long float double char boolean void Byte Short Integer Long Float Double Character Boolean Void See below for the relationship between the wrapper object and the primitive type: An object of a wrapper class can be used any place where we need to store a primitive value as an object. Chapter 3: Using Classes and Objects CS 121 46 / 51

Wrapper Classes (2) The wrapper classes contain useful static methods as well as constants related to the base primitive type. For example, the minimum int value is Integer.MIN_VALUE and the maximum int value is Integer.MAX_VALUE. Example: PrimitiveTypes.java For example, the parseint method converts an integer stored as a String into an int value. Here is a typical usage to convert input from a user to an integer. Scanner scan = new Scanner(System.in); String input = scan.nextline(); int num = Integer.parseInt(input); Chapter 3: Using Classes and Objects CS 121 47 / 51

Wrapper Classes (3) Selected methods from the Integer class. Integer(int value) Constructor: builds a new Integer object that stores the specified value. static parseint(string s) Returns an int value corresponding to the value stored in the string s. static tobinarystring(int i) static tooctalstring(int i) static tohexstring(int i) Returns the string representation of integer i in the corresponding base. Similar methods and many more are available for all the wrapper classes. Explore the javadocs for the wrapper classes. Chapter 3: Using Classes and Objects CS 121 48 / 51

Autoboxing Autoboxing is the automatic conversion of a primitive value to a corresponding wrapper object. Integer obj; int num = 100; obj = num; The assignment creates the corresponding wrapper Integer object. So it is equivalent to the following statement. obj = new Integer(num); The reverse conversion (unboxing) also happens automatically as needed. Chapter 3: Using Classes and Objects CS 121 49 / 51

Summary Understand the difference between primitive type variables and reference variables. Creating and using objects. Using String, Math, Random, Scanner classes. Formatting output using NumberFormat, DecimalFormat and Formatter classes. Wrapper classes and autoboxing: Byte, Short, Integer, Long, Float, Double, Character, Boolean Chapter 3: Using Classes and Objects CS 121 50 / 51

Exercises Read Chapter 3. Recommended Homework: Exercises: EX 3.2, 3.3, 3.4, 3.6, 3.7, 3.11, 3.12. Projects: PP 3.2, 3.3, 3.5. Chapter 3: Using Classes and Objects CS 121 51 / 51