Java Flashcards

1
Q

What are accessor methods?

A

Methods used to obtain information about an object.

Ex) the .length() method which returns the number of characters contained in the string object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe a nested if statement

A

A nested if statement allows you to use an if statement inside another if statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe usage of “this” : to refer to current class instance variable

A

If there is ambiguity between the instance variables and parameters, “this” keyword resolves the problem of ambiguity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe an if statement

A

An if statement consists of a Boolean expression followed by one or more statements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the 3 types of loops in Java?

A
  1. While loop
  2. For loop
  3. Do…while loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe Java

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is an interface?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe a switch statement

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are exceptions?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an Array?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe the “new” keyword

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe “this” : to invoke current class constructor

A

The this() constructor call can be used to invoke the current class constructor. It’s used to reuse the constructor (constructor chaining).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Describe using “super” to invoke parent class method

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are unchecked exceptions?

A

Errors, and runtime exceptions are unchecked. The compiler does not enforce (check) that you handle them explicitly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are decision making structures?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Describe using “super” to invoke parent class constructor

A

The super keyword can also be used to invoke the parent class constructor

17
Q

Describe a for loop

A

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.

18
Q

Describe “this” : to invoke current class method

A

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.

19
Q

Describe using “super” to refer to parent class instance variable

A

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.

20
Q

Describe the static keyword

A

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

21
Q

What does it mean to concatenate string?

A

To join multiple strings together.

Ex) the concat() method works with string literals.

22
Q

What are checked exceptions?

A

They are the ones that the compiler enforces that you handle them explicitly. Methods that generate checked exceptions must declare that they throw them.

23
Q

Describe static variable

A

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

24
Q

Describe loops in Java

A

Loop statements allow us to execute a block of code several number of times.

25
Q

Describe the usage of the “super” keyword

A

The super keyword in Java is a reference variable which is used to refer immediate parent class object

26
Q

Describe an if…else if statement

A

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

27
Q

What is a java package?

A

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

28
Q

Describe the “this” keyword

A

“this” is a reference variable that refers to the current object.

29
Q

What is an ArrayList

A

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.

30
Q

Describe a do…while loop

A

A do…while loop is similar to a while loop, except that a do..while loop is guaranteed to execute at least once.

31
Q

Describe the final keyword.

A

The final keyword in java is used to restrict the user. It can be used on a: variable, method, class

32
Q

What is a String in Java?

A

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.

33
Q

Name the 4 types of decision making statements

A
  1. if statement
  2. if…else statement
  3. nested if statement
  4. switch statement
34
Q

Describe a while loop

A

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.

35
Q

Describe an if…else statement

A

An if…else statement is an if statement followed by an else statement to be executed when the Boolean expression is false.