8 Classes
Oracle Academy Section
Section 7: Create a Java Class
Lesson 1: Creating a Class
Lesson 2: Instantiating Objects
Lesson 3: Constructors
Section 7 Quiz 1 (Lessons 1-3)
Java Foundations Certification Exam Topics
Classes and Constructors
Create a new class including a main method
Use the private modifier
Describe the relationship between an object and its members
Describe the difference between a class variable, an instance variable, and a local variable
Develop code that creates an object's default constructor and modifies the object's fields
Use constructors with and without parameters
Key Resources
Language Companion - Pages 1-5 only, classes (CellPhone) gets, sets, constructors. IMPORTANT
Java Tutorials:
Udemy
Lecture 20: Method Parameters (14:25) class Robot, parameter, jump, move with multiple parameters, data type and order have to match, argument and parameter names don't have to match
Lecture 21 : Setters and this (10:58) class Frog, mutators, setName, setAge, making fields private, this.name = name, scope
Lecture 22: Constructors (10:19) class Machine, constructors with different parameter lists
Bucky's Room
Supplemental Resources
Codecademy - Object Oriented Java
Most Important Concepts / Code
A class is code.
An object is an instance of a class.
A class exists in a file on a hard drive.
An object exists in RAM.
A class is like a blueprint.
An object is like a house built from a blueprint.
A class is like a data type.
An object is like a variable.
A class can include fields and methods.
Fields are nouns, member variables, attributes, data, things the class "knows", almost always private.
Methods are verbs, member functions, actions, things the class "can do", almost always public.
Encapsulation: wrapping data and function together.
Data hiding: protect integrity by preventing unintended changes.
Use get (accessor) and set (mutator) methods to interact with fields.
Sets always have a void return type and accept an argument of the same data type as the field being set.
Gets always have a return type that is the same as the field being returned and do not accept any arguments.
public class CellPhone
{
private String manufacturer;
public void setManufacturer(String manufact) {
manufacturer = manufact;
}
public String getManufacturer() {
return manufacturer;
}
}
Creating an object looks like declaring a variable but requires the keyword new.
CellPhone myPhone = new CellPhone();
Creating an object automatically calls a constructor method.
You only need to write a constructor if you want certain code to happen every time an object gets created, such as fields to be initialized.
Access class methods by referencing the object name, then the dot operator (period), then the method name.
myPhone.setManufacturer("Motorola");
Hour 1
Quiz and Concepts Review
Classes and objects
Make a class
Hour 2
Constructors