Java Flashcards
What are accessor methods?
Methods used to obtain information about an object.
Ex) the .length() method which returns the number of characters contained in the string object.
Describe a nested if statement
A nested if statement allows you to use an if statement inside another if statement.
Describe usage of “this” : to refer to current class instance variable
If there is ambiguity between the instance variables and parameters, “this” keyword resolves the problem of ambiguity.
Describe an if statement
An if statement consists of a Boolean expression followed by one or more statements.
What are the 3 types of loops in Java?
- While loop
- For loop
- Do…while loop
Describe Java
A general purpose computer-programming language that is class-based and object-oriented. It’s designed to write once and run anywhere, meaning that compiled Java code can run on all platforms without the need for recompilation.
What is an interface?
An interface is a reference type in Java. It’s similar to a class. It’s a collection of abstract methods. It contains behaviors that a class implements.
Describe a switch statement
A switch statement allows a variable to be tested for equality against a list of values.
Each values is a case, and the variable being switched on is checked for each case.
What are exceptions?
Exceptions are events that occur during the execution of programs that disrupt the normal flow of instructions
An object that wraps around an error event that occurred within a method. Can be checked, unchecked, or errors
What is an Array?
An array is a collection of similar types of elements that have a contiguous memory location. We can only store a fixed set of elements in a Java array.
Describe the “new” keyword
The “new” operator instantiates a class by dynamically allocating memory for a new object and returning a reference to that memory. This reference is then stored in a variable.
The new operator is also followed by a call to a class constructor, which initializes the new object. A constructor defines what occurs when an object of a class is created.
When you declare a class in Java, you are just creating a new data type. A class provides the blueprint for objects. You can create an object from a class.
Describe “this” : to invoke current class constructor
The this() constructor call can be used to invoke the current class constructor. It’s used to reuse the constructor (constructor chaining).
Describe using “super” to invoke parent class method
The super keyword can also be used to invoke parent class method. It should be used if subclass contains the same method as the parent class. in other words, it is used if method is overridden.
What are unchecked exceptions?
Errors, and runtime exceptions are unchecked. The compiler does not enforce (check) that you handle them explicitly.
What are decision making structures?
They have one or more conditions to be evaluated or tested by the program, along with statements to be executed if the condition is true, and optionally other statements to be executed if the statement is false.