Exam 2 study guide
Float
A 32 bit decimal number
Double
A 64 bit decimal number
HAS-A
A Has-A relationship simply means that an instance of one class has a reference to an instance of another class or another instance of the same class. For example, a car has an engine, a dog has a tail and so o
A class
A collection of data and access functions
String
A double quoted text
Char
A single letter and single quote text
Which statement is not True about the Classes?
All classes must include a main() method
An Object
An instance of a class
Which of the following statement is not True? In order to reduce the dependency, we should decrease the number of attributes We should minimize the dependency as much as possible Abstraction is a technique for structuring computer programs Abstraction reduces things down to the simplest components possible
Answer: In order to reduce the dependency, we should decrease the number of attributes
Bytecode
Compiled Java source code.
Hierarchical Inheritance
Contains one base (Super or Parent) class and multiple derived classes of the same base class Class A <-- Class B and Class C
Type casting
Converting data from one type to another double --> int float --> int (3.1 --> 3) a lose of 0.1 etc etc
Who is the JRE intended for?
End users
What is the result of the following code? int num = 6.45;
Error
Java uses _______________ for much of its error handling
Exceptions
Example of a subclass:
Extend computer graded quiz that has a multiple choice question. Choice question IS-A Question• Its objects store the various choices for the answer• Add method for adding possible answers.• display method needs to be changed.
Class is the base class (super class) of all classes in java.
False
In JAVA, we can compare int variable with a boolean variable
False
In Java, you declare the type of a variable in your code, and you can change the type of that variable later on.
False
Java is short for "JavaScript".
False
Mutator methods don't change the data of the object
False
String is a mutable class
False
The value of a string variable can be surrounded by single quotes
False
We can only construct one object per class
False
Within Java, you need to code your program so that under certain conditions it will skip the current iteration of a for loop. What can be used to accomplish this?
continue
IS-A
IS-A Test = True Then you may consider inheritance. Assume Vehicle is the parent class and you want to create a car class. IS-A car a vehicle? Yes then yes, consider inheritance
REVIEW SLIDE 7-14
REVIEW SLIDE 7-14
Which of the following statements is not True? There can be multiple variables referencing same object A reference is the location in memory that an object resides References are mutable The value of an object variable is a reference
References are mutable
The "Super" keyword
Similar to the "This" keyword. Can be used to access any data member from the superclass. Can be used at the variable, method, and constructor level.
Methods
Small functions that aid in abstraction within classes
How are interpreted languages are executed?
Source Code --> Interpreter --> Output
The process of compiling and running a Java program.
Source Code: Hello.java --> Compiler: javac Hello.java --> Bytecode: Hello class --> Interpreter: Java hello.java --> Output.
Which data structure is used to store the values of functions calls? (Hints: multiple function calls...... function calls another function and it calls another function.....)
Stack
An example of a Dog Object
State: - Weight - Sex - Age - Name - Color Functionality: - Bark() - Eat() - Sleep()
Which of the following statement is not True about JAVA object?
The object can have only one type of data
Inheritance
The process of which a subclass can inherit the superclass methods and behavior
Why OOP, Security
The purpose of OOP is to bind together the data and the functions that operate on them -no other part of the code can access this data except that function.
Which of the following statement is not True about JAVA?
The white spaces and the indentation is important
Functionality
Things an Object does How the Object behaves
A static variable belongs to the class, not any object of the class
True
Accessor method does not change the internal data of the object on which it is invoked.
True
An immutable class has no mutator methods
True
Do - while loop is guaranteed to run at least one time
True
Every variable in JAVA need a data type
True
There is no need to create the object to call the static methods.
True
Whenever we create a method, it should be either an accessor or mutator method, not both.
True
Boolean
True or False
Overriding
Two methods with the same name and the same parameter types
Overloading
Two methods with the same name, but different parameters, or parameter types
Which of the following is true about the public access modifier? Variables, methods and constructors which are declared public can be accessed by any class lying in same package Variables, methods and constructors which are declared public can be accessed by only the accessor methods of that class Variables, methods and constructors which are declared public can be accessed by any class Variables, methods and constructors which are declared public in the superclass can be accessed only by its child class
Variables, methods and constructors which are declared public can be accessed by any class
Abstraction hides __________?
complexity
If you want your condition to depend upon two conditions BOTH being True, what is the proper notation to put between the two Boolean statements?
&&
An Object is something that:
- Has Data - Has operations - Listens for and responds to messages - Has behavior - Has functionality - Is a description of something - Is a "thing" - Is reusable - Has a state - Has a funcitonality
A State
Data that describes everything about how an Object exists at a given time; using it's properties and attributes a snapshot of an Object
Type Conversion (Narrow Conversion)
If we want to assign a value of a larger data type to a smaller data type we perform explicit type casting or narrowing. This is useful for incompatible data types where automatic conversion cannot be done. Here, target type specifies the desired type to convert the specified value to. Double --> Float --> Long --> Int --> Short --> Byte
JDK (Java Development Kit)
Includes the development tools, such as the Java compiler, Javadoc, Jar and a debugger.
Subclass, Inherited Class, Derived Class
Inherits all fields and methods from the superclass
Constructors are used to ____________
Initialize a newly created object
Primitive Types
Integral Types: int, long, short, byte Floating point types: Double, float Character: char Truth: boolean Literals: 36L (suffix L = long), 2.4F (F= float) Character constants: 'a', '\n', '\x2122'
Which of the following statement is not true about JAVA?
It is an interpreted language
Why OOP, helpful
It is easier to manage the complexity of large software systems
Final keyword in variable declaration
It makes sure that whichever variable you made final cannot be altered in the future
Who developed Java
James Gosling at Sun Microsystems in 1995
________________ is used to run the bytecode on each platform.
Java Virtual Machine (JVM)
JVM?
Java virtual machine is used to run the bytecode on each platform. It is like a virtual computer that handles things like math and memory management
Which statement is not True about local variables?
Local variables can be used in any other method
Which of the following is not an exception type? Error Memory Checked Runtime
Memory
Why OOP, Maintance
Modular design allows us to update a specific part of the system only
What is the correct way to create an object called myObj of MyClass?
MyClass myObj = new MyClass();
Should a class Quiz inherit from the class Question? Why or why not?
No! - A quiz is not a question; it HAS questions.
OOP
Object Oriented Programming
An example of a house Object
Object state: - Address - Square feet - Year built Functionality: - Doors open/close - Air conditioner/heater - Lights on/off
OOD
Object-oriented design
Encapsulate state and related functionality
Objects
Why OOP, Reusability
Objects can be reused within and across applications and this lowers the development cost and increase the speed of the development process
Compound statements
Only the first statement will be reached if there are no curly brackets
Two or more methods with the same name in the same class with different arguments is called as ___________
Overloading
Which of the following statement is not True? A class depends on another class if its methods use that class in any way We should place code for producing output/consuming input inside the constructor method Always strive to decouple input and output from classes' work We should reduce the dependency as much as possible
We should place code for producing output/consuming input inside the constructor method
Multilevel Inheritance
When one class (Class A) is the super class then has another class that extends it (Class B) which also has another class that extends it (Class C) Class A <- Class B <- Class C
Type Conversion (Automatic Type Conversion)
When you assign a value of one data type to another, the two types might not be compatible with each other. If the data types are compatible, then Java will perform the conversion automatically known as Automatic Type Conversion Byte --> Short --> Int --> Long --> Float --> Double
Common inheritance error: replication
When you replicate a variable or field from a super/parent class
Single Level Inheritance
Where there are two classes, one super class and one subclass. Class A <- Class B
Int
Whole non-decimal numbers
WORA?
Write Once, Run Anywhere
Which of the following statement is True? You must initialize the local variables Local variables belongs to the class Instance variables belongs to method Object references are set to zero
You must initialize the local variables
To declare an array in Java, define the variable type with:
[]
Which statement is used to stop a loop?
break
Which keyword is used to create a class in Java?
class
Which of the following statement is True about JAVA exceptions?
finally block always executes
The specialized Classes are said to
inherit the public methods and public and private instance variables of the general Class
A derived Class automatically has all the
instance variables and public methods that the base Class has, and it can have additional methods and/or instance variables as well
How do you create a variable with the numeric value 5?
int x=5;
Why is inheritance advantageous?
it allows Classes to be Reused, without having to copy it into the definitions { } of the derived Classes
OOA
object-oriented analysis
When the child class declares a method that has the same type arguments as a method declared by its parent class is called as _____________
overriding
A ____________ of a method is any externally observable data modification (state change)
side effect
_______ is a keyword which is used to access the methods or member variables of the parent class
super
JRE (Java Runtime Environment)
the JVM plus code for all the libraries that are included by default with Java.
_______ refers to the object a method is being called on.
this
How to declare a variable
type variableName = value;