Intro to Java
Using Objects
Implementing Classes
Data Types
Discussion
100

What is the purpose of machine code and high-level programming languages?

Machine code – binary instructions understood by a CPU; enter code directly to memory in a numerical way

High-level – programming in human-readable forms; compiled into machine code

100

Explain what a type and value are.

Type – all values have a type (int, String, PrintStream), determines the characteristics of its possible values and the operations performed

Value – the contents of what is being held within the variable

100

Write an example:

How do you declare a method within a class?

Example:

public double checkBalance(double amount)

(Access modifier/visibility, return type, name, parameter list)

100

What is the difference between a floating-point number and an integer?

Integers – a regular whole number (48)

Floating-point – Continuous numbers (48.77777777777777778)

100

As a team:

What is a program, an algorithm, and pseudocode?

Program - a list of instructions to tell the computer what to do.

Algorithm - instructions given to the computer; a clearly-defined sequence of steps needed to complete a task

Pseudocode - an easy to read version of what your code does

200

What is a logic error?

Occurs when a program doesn't behave the way you expect or want it to, much more difficult to diagnose because Java's compiler doesn't report them

200

As a team:

What are the purpose, characteristics, and naming rules of a variable?

Purpose – Storage locations in memory for values you wish to manipulate later

Characteristics – name, type, and value

Declaring variables and naming rules – choose types appropriate for needs, make names clear and concise; names may contain letters, numbers, underscores, and $ signs; names cannot start with a numbers; cannot use Java's reserved words as names.

200

As a team, write an example:

How do you declare a constructor in a class named BankAccount? What about multiple constructors?

public BankAccount()

public BankAccount(double initialBalance)

(Similar to a regular method, but omit the return type; constructor's name must match the class's; multiple constructors are allowed as long as they all use different parameter lists)

200

As a team:

What are the five arithmetic operators in Java?


Addition (+)

Subtraction (-)

Multiplication (*)

Division (/)

Modulus-returns the remainder of dividing x by y (%)

200

What is the purpose of the Java API documentation?

Describes how software entities interact with each other, describes all standard classes as well as properties & methods

300

As a team:

What are Java's basic coding rules?

Case-sensitive class, method, and variables names

Whitespace doesn't matter

Statements must end with a semi-colon

Methods must be defined inside a class; bodies enclosed in curly braces

300

Explain what a class, object and method all are.


Class - type of object

Object - used to represent complex values

Method - sequence of instructions that act on the properties of the object to which it belongs

300

How do you create single-line, multi-line, and Javadoc comments?

// - single

/* - starts a multi-line

/** - generates Javadocs

*/ - ends a multi-line or Javadoc

300

How do you declare constants in Java, and when do you use them?

Add the FINAL reserved word before the variable's name to make it a constant.

If you attempt to change the constant later within the program, the compiler will report an exception

300

What is encapsulation and what are the benefits of it?

Notion of hiding implementation details while providing a public interface. Benefits: simplifies work, easier to diagnose programming errors, easier to change inner workings

400

What is a syntax error?

Noticeable mistakes or miscalculations within code that the compiler catches.

Examples: unknown variable names, using reserved words (public, private, string, etc.), forgetting to end with a semicolon

400

Explain the difference between primitive data type and object storage within variables

Variables of primitive data types hold actual numeric values, NOT references. Primitive values require less storage, so more efficient to store them right in the variable

Variables of object types always hold references (links, addresses) to an object's memory location.

400

Explain what a local variable is.

Local variables are set up inside the body of methods, scope of such a variable is within the method that is was declared

400

What is a numeric overflow and how does it relate to the memory ranges of types?

Numeric overflows occur when a number value becomes too large to fit in the designated memory range

400

Explain the difference between public and private access of class members

Public access - any code within a Java application can read/change the values of public variables, or call public methods of a class

Private access - only objects of the same class can access private variables and methods

500

What are the roles of the Java Virtual Machine (JVM) and Java Development Kit (JDK)?

Java Virtual Machine (JVM) - the virtual CPU that runs Java programs; Verifies all instructions before executing, excellent error reporting

Java Development Kit (JDK) -  the Java Runtime Engine (JRE) + compiler and other tools to build and run programs

500

What is the difference between accessor & mutator methods?

Accessor - returns data from an object WITHOUT CHANGING THE OBJECT

Mutator - modifies the data of an object

500

Under what circumstances do you use the this keyword?

Can implicitly or explicitly be used for clarity as to which variable is being referenced with instance variables; allows an object to refer to itself

500

As a team:

What are the 8 fundamental data types and their storage capabilities?

Int – 4 bytes

Byte – 1 byte

Short – 2 bytes

Long – 8 bytes

Double – 8 bytes

Float – 4 bytes

Char – 2 bytes

Boolean – 1 bit

500

Discuss casting vs. rounding. What do you have to be careful about when casting?

Casting converts numbers from one type to another.

Rounding makes decimals move to the closest integer.

BE CAREFUL: casting to an int discards the decimal portion of a floating-point number and it doesn’t round up.