Java Programming

 

         

 

Friday, January 17th

 

Driver Class code

Section 4: Lesson 2 - Object and Driver Classes Programs and questions due today!

Review of Accessor/Getter and Mutator/Setter Methods - how many variables do you have? That is how many accessor - mutator methods you will need.

Creating a constructor with parameters

Review of Lesson 2
Keywords
Driver Class - slide 39-42
Object Class - slide 27
Java API
Default Constructor - slides 29-34
Constructor with Parameters - 35-38

• 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()

Complete Section 4: Lesson 2 - Object and Driver Classes practice questions.

Complete Section 4: Lesson 2 - Object and Driver Classes Programs - show these to me for teacher check. Before you leave class today all of lesson two should be finished and you should have shown me your two programs, Student and Person classes with their driver classes. 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 .....

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.

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.

 

Homework

Install Eclipse on your home computer if you would like to be able to work on your java at home.

 

What

Objectives for Section 4 Lesson 3
In this lesson, you will learn how to:
• Use simple types in Java code
• Specify literals for the simple types and for strings
• Demonstrate two or more ways to initialize variables
• Describe the scope rules of a method
• Understand type conversion in expressions
• Apply casting in Java code
• Use the arithmetic operators
• Use the relational and logical operators
• Use the assignment operator
• Understand type conversion in expressions
• Write a program that utilizes at least one math method
• Begin to understand and navigate the Java API
• Understand a small sample of Java classes and methods

 

Why

Accurate calculations, and determining the path of program execution when using logic and relational operators, is important. If a conversion from one currency type to another is to be performed correctly, the arithmetic calculations will need to be implemented in the correct
sequence and using the exact logic order.

 

How

By completing the slides, quiz and practice exercises.