CS49J Lesson 2 – Objects
Ch 1: 1.3-1.5 & Ch 2: 2.1-2.6

When you come in
- Connect to the Internet
- Log in to Piazza
- Start Eclipse or your IDE
- Navigate to laughton.com/obrien/sjsu/
cs49j/lessons and open this lesson
Activity - Homework Project
Record your participation in Piazza clicker question Lesson2 Q1
We are going to start at the beginning and set up hw1b together
- start your IDE,
- make a project.
- read the assignment to see what we need to do
- notice it shows syntax errors as you go
- look at the quick fixes but be careful
- run by right clicking on StringsForAll and choosing
Run as Java Application
- copy/paste the code into Codecheck
- Click submit
- upload report to Canvas - you will need to upload it again with the other two files
Activity - Deciphering Syntax Errors
Record your participation in Piazza clicker question Lesson2 Q2
One of the challenges in learning a new programming language is to be able to decipher syntax error messages
Let's practice
- Start a new project in your IDE
- Get the file, ErrorDeciphering.java
- Create a class with the file
- Look at the first error
- What does the error say? What do you think it means?
- Fix the error
- Look at the next error
- What does the error say? What do you think it means?
- Fix the error
- Repeat for all the errors
Activity - Accessor and mutators
Record your participation in Piazza clicker question Lesson2 Q3
- What is an accessor method?
- What is a mutator method?
- Look at the Rectangle class in the API class. Find an accessor. Find a mutator.
Activity - Accessors and mutators
Record your participation in Piazza clicker question Lesson2 Q4
Look at the String class in the API class. Find an accessor. Find a mutator.
Activity - Compiling
Record your participation in Piazza clicker question Lesson2 Q5
What is created when you compile a Java source file
- object code
- byte code
- You do not compile Java. It is an interpreted language
- None of the above
Concept - new operator
Objects are always created using the new operator
- This creates an object reference variable today
Day today;
no object has been created
- This creates an object of type Day
new Day();
- This creates an object and assigns it to a variable.
Day today = new Day();
Concept - creating a String object
- To create a String object
String cat = "Corky";
- What happened to the new operator?
Activity - Creating objects
Record your participation in Piazza clicker question Lesson2 Q6
Which statement creates a Rectangle object?
- Rectangle box;
- box = Rectangle(10, 20, 100, 50);
- new Rectangle(10, 20, 100, 50);