Vehicle Class
Vehicle Driver Class
Section 4: Lesson 2 - Object and Driver Classes Vocabulary Due TODAY! 15 points but they must be correct!
Review of Lesson 2
Driver Class
Object Class
Java API
Constructors
• Accessors (getters): Methods that return (get) the value
of each class variable.
• Mutators (setters): Methods that change (set) the value
of each class variable.
toString()
Code Blocks format - just like an essay format { }
Programmer Created Classes - no main method - will NOT run, must be called by another class - a Driver class
The Driver (Test) class has a main method and within that main method it calls the methods of the programmer created class.
BOTH files must be in the same package to work!
Accessor/getter and Mutator/setter methods
- required so the Driver Class can access the data in the Object Class.
Java Key Words and camelCase
Variable names are short but meaningful in lower
camel case.
• Constant names are declared in uppercase letters with
the final modifier.
• Constructors are named the same as the class name.
• Methods are verbs named in lower camel case.
Section 4: Lesson 2 - Object and Driver Classes Vocabulary:
- A group of related Java classes.
-
Sections of code that are enclosed inside a set of curly braces. {}
-
First letter uppercase and the first letter of each internal word capitalized. Example: SavingsAccount
-
A named value that does not change.
-
First letter lowercase and the first letter of each internal word capitalized. Example: studentFirstName
- A class that contains a main method.
-
A code statement in a Java class file that includes java code from another package or class.
-
A class that defines instances of objects to be used in another class.
-
Code that is preceded by //. Comments are used to clarify programming logic. Comments are ignored by the compiler.
-
A word that has a special function in the Java language, and cannot be used as names for classes, methods, or variables.
-
The library of Java classes available to import into a programmer-created class.
-
The outline of an object, including class variables, constructors, and methods.
-
A special kind of method that is a template for an object.
-
Values that are sent into a method or constructor to be used in a calculation or substituted with values from the class.
-
Values, such as numbers, characters, or booleans. References to objects, such as a BankAccount object.
- Keywords used to specify the accessibility of a class (or type) and its members. Ex: public, private, protected, default
-
A block of code inside a class that is used to change or access information about the class.
Complete Section 4: Lesson 2 - Object and Driver Classes Programs - show these to me for teacher check. Show me your two programs, Student and Person classes with their driver classes. I will also be checking the answers to your questions. See the Oracle curriculum.
The output of the StudentDriver class should be in the following form:
Student Name: Caron Newman
Student ID: 123456789
Student Status: Active
This program was created by .....
Introduction to Lesson 3:
Java is a Type intensive programming language - what are the primitive types? - these types are NOT objects. They are blocks of memory that store data of the type you specify. (slide 7)
Do NOT worry about binary and hex literals, these are used to improve performance but this is beyond this course at this time.
Type Casting - this you should know about.
Create a JavaPractice project and then a JavaPractice class - use this file just to try out a small blocks of java code - have this open as you read through the text and try out some of the code examples they show. Now try the Type Casting code - copy and paste.
Variable Names - slide 15-16. - don't be old school - use names that make sense and explain what is happening in the code.
Constant Names - ALL CAPS and use the keyword final before the type - final double PI = 3.141592; Once declared the value of PI cannot be changed.
Scope of a Variable - very important concept
1. Scope of a parameter ( the value passed into a method) - only in the body of the method
2. Scope of a local variable - only within the block of code where it was declared
3. Scope of a local variable in a for loop - only in the for loop
* if you want the variable to be accessible after the loop then declare it before the for loop
4. Scope of a method or field of a class - anywhere in the class - class scope
Scope Tutorial 1
Complete Section 4 Lesson 3: Data Types and Operators vocabulary
- Named primitive or object storage mechanisms defined in a program. The assigned value may or may not (constants) change.
-
Symbols are used to do addition, subtraction, multiplication, division, and modular arithmetic in math expressions and formulas.
-
The group of Java data types that do not use the keyword new when declared or initialized. Primitive Data Types store the value in the same place in memory as the variable name.
-
The smallest java primitive type (1 byte) that can hold an integer value.
-
This data type (8 bytes) is the largest integer type.
- The formatting and naming standards that most programmers follow.
-
This Java primitive data type (4 bytes) can hold integer values.
-
This Java primitive data type (8 bytes) is the largest primitive that can hold a decimal value.
-
When a variable is assigned a value for the first time.
-
This Java primitive data type (4 bytes) can be initialized with a decimal number preceding letter f. Example: float x = 3.5f;
-
Can be any number, text, or other information that represents a value; used to initialize a primitive type.
-
A Java statement when a variable is defined but not necessarily assigned a value. Example: int x;
-
This word describes the mathematical precedence that a variable has in a Java program.
-
A java primitive data type (2 bytes) that can hold single character values. Example: “a”, “#”, or “X”
-
Used to describe the block of code where a variable exists in a program. A block of code is denoted by {}.
-
The process of explicitly modifying one data type to become a different data type.
-
A concept where a number is always rounded down to the nearest integer.
-
The equals sign “=” used in a Java statement to assign a value to a variable.
-
The process of modifying one data type to become a different data type, this may be implicit or explicit.
-
A Java primitive data type (2 bytes) that holds integer numbers within a shorter range than an int.
-
A one-bit java primitive type that can hold the value true or false.
Complete Section 4 Lesson 3: Data Types and Operators slides
Complete Section 4 Lesson 3: Data Types and Operators practice
Show me your TriangleArea calculator, MathPractice and your FieldTrip programs.