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.
Describe using “super” to invoke parent class constructor
The super keyword can also be used to invoke the parent class constructor
Describe a for loop
A for loop is a repetition control structure that allows you to efficiently write a loop that needs to be executed a specific number of times.
It’s useful when you know how many times a task is to be repeated.
INITIALIZATION - allows you to declare and initialize any loop control variables.
BOOLEAN - evaluated to determine control.
BODY - after the body is executed after a true statement, control jumps back to the update statement and the boolean expression is evaluated again.
Describe “this” : to invoke current class method
You may invoke the method of the current class by using the “this” keyword. If this isn’t used, the compiler will automatically add this keyword while invoking the method.
Describe using “super” to refer to parent class instance variable
We can use super keyword to access the data member or field of parent class. It is used if parent class and child class have same fields.
Describe the static keyword
The static keyword is used for memory management. The static keyword belongs to the class than an instance of the class. It can be: variable, method, block, nested class
What does it mean to concatenate string?
To join multiple strings together.
Ex) the concat() method works with string literals.
What are checked exceptions?
They are the ones that the compiler enforces that you handle them explicitly. Methods that generate checked exceptions must declare that they throw them.
Describe static variable
The static variable can be used to refer to the common property of all objects. It makes your program memory efficient.
For ex. The company name of employees, college name of students
Describe loops in Java
Loop statements allow us to execute a block of code several number of times.
Describe the usage of the “super” keyword
The super keyword in Java is a reference variable which is used to refer immediate parent class object
Describe an if…else if statement
An if statement that is followed by an else…if statement, which is useful to test various conditions using a single if…else if statement
What is a java package?
A java package is a group of similar types of classes, interfaces ,and sub-packages. They are used to categorize the classes and interfaces so that they can be easily maintained.
Can be built-in or user-defined. Ex) lang, util, sql
Describe the “this” keyword
“this” is a reference variable that refers to the current object.
What is an ArrayList
An arraylist is part of collection framework and is in the java.util package. Can be useful in programs where lots of manipulation in the array is needed.
Describe a do…while loop
A do…while loop is similar to a while loop, except that a do..while loop is guaranteed to execute at least once.
Describe the final keyword.
The final keyword in java is used to restrict the user. It can be used on a: variable, method, class
What is a String in Java?
Strings are a sequence of characters. They are treated as objects. The Java platform provides the String class to create and manipulate strings.
The String class is immutable, so once it is created, it cannot be changed.
Name the 4 types of decision making statements
- if statement
- if…else statement
- nested if statement
- switch statement
Describe a while loop
A while loop statement repeatedly executes a target statement as long as a given condition is true. When the condition becomes false, program control passes to the line immediately following the loop.
Describe an if…else statement
An if…else statement is an if statement followed by an else statement to be executed when the Boolean expression is false.