Object
Entity with data and operations that can manipulate the data
Class
Entity that is either:
1.) Program with only static methods
2.) Custom data type for building objects
Method
A sequence of instructions the object follows to perform a task
Parameter
Information needed by the method to complete the task
Argument
Actual data passed to method
Return Value
The information a method provides
Void
Means NO information is returned
Variable
A storage location in computer’s memory
What are the 3 properties for a Variable?
1.) Type of data being stored
2.) Name (identifier)
3.) Contents (Actual data)
int
For storing integer data
int age = 17;
double
For storing precise number data
double gpa = 3.95;
String
A sequence of characters (text)
System.out.println("Plano West")
Simple Numeric Variables
Assignment Operator (=)
Assigns value (contents) to a variable
variable = value;
Variable Syntax
Declaration
Type name;
Initialization
name = value;
Combined (Declaration & Initialization)
Type name = value;
Identifier
Name of variable, class, or method
Rules for Identifiers
1.) May contain letters, digits (0-9), underscore ( _ ) and dollar sign ($) characters
2.) Cannot start with digit
3.) No spaces are permitted
4.) Cannot be a reserved word
5.) Letters are case-sensitive: west, West, and WEST are different!
Reserved Word
Words defined to have special meaning in Java (Ex: int, public, void)
Java Naming Conventions: Variables and Methods
Starts with first word in all lowercase, subsequent words capitalized: myDogSpot
Java Naming Conventions: Classes
Starts with uppercase letter, each word capitalized: PlanoWestWolf
Java Naming Conventions: Constants
All uppercase letters, separate words with : NUMBER_ONE
Comment
Information for humans (programmers) that the compiler ignores
Single-Line Comment
All information to the right of “//” is ignored
//Single-Line Comment
Multi-Line Comment
All information between “/*” and “*/” is ignored
/* This is
a multi-line comment
and is all ignored!
*/
Javadoc
Information can be extracted using tool to create documentation
Starts with “/**” and ends with “*/”
Uses special tags like @author, @param and @return
File Heading
A 6-item comment at the top of each source file
Method Comment Heading
Describes the parts of each method
Object Variables
Variable that contains the memory address, or reference, of the object
Its type is the name of a class
Declaring the Object
Designate a name for referring to the object
ClassType name;
Instantiation
Building (constructing) an object by calling on a class’ constructor
name = new ClassType();
Some constructors accept parameters – allowing us to specify initial values
Rock mossy = new Rock(Color.GREEN);
Some constructors accept multiple parameters
Location loc;
loc = new Location(5, 7);
Calling Methods
After instantiating your object, you can call, or invoke, its methods
Public Interface
The methods defined by a class for public use
API (Application Programming Interface)
Defines the public interface for classes and methods in the Java library
Return Method
A method that returns a value when called
Void Method
A method that does not return information
Accessor Method
Does not change the object’s data
Mutator Method
Changes the object’s data
Calling Methods With Objects
Calling Return Methods With Objects
Package
A grouping of logically-related classes
Import Statement
Identifies a class defined in a different package
Overload
Method is defined multiple ways
Concatenation
Joining two strings together to form a new string
int length()
Returns the number of characters (visible + white space) in the string
String school;
school = new String("Plano West");
int count = school.length();
// Returns as 10