Exception handling, Lambda expressions, GC, Selected Classes Flashcards

1
Q

System.exit(0)

A

Whenever we are using System.exit(0) then JVM will be terminated.

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

LocalDate
LocalTime
LocalDateTime

A

LocalDate,LocalTime and LocalDateTime are immutable ojects. Hence if we are trying to modify the content, then a new object will be created and in the existing object there are no changes.

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

Predicate

A

you only need to know how to implement lambda expressions that
use the Predicate interface. Remember the one method in the interface called test()? It
takes any one reference type parameter and returns a boolean.

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

Lambda syntax

A

a -> a.canHop()

■ Specify a single parameter with the name a
■ The arrow operator to separate the parameter and body
■ A body that calls a single method and returns the result of that method

(Animal a) -> { return a.canHop(); }

■ Specify a single parameter with the name a and stating the type is Animal
■ The arrow operator to separate the parameter and body
■ A body that has one or more lines of code, including a semicolon and a return statement

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

If catch block and finally block throws exceptions

A

If catch block and finally block throws exceptions, then only finally block thrown exception(most recently raised exception) will be displayed to the console.

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

ArrayList methods
set()

A

The set() method changes one of the elements of the ArrayList without changing the size. The method signature is as follows:

E set(int index, E newElement)

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

== Vs. .equals()

A

Calling == on String objects will check whether they point to the same object in the pool.

Calling == on StringBuilder references will check whether they are pointing to the same StringBuilder object.

Calling equals() on String objects will check whether the sequence of characters is the same.

Calling equals() on StringBuilder objects will check whether they are pointing to the same object rather than looking at the values inside.

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

String s = new String(“Bahubali”);
StringBuilder sb = new
StringBuilder(“Bahubali”);
System.out.println(s==sb);

A

To use == operator between object references, compulsory there should be some relation between argument types (either parent to child or child to parent or same type), otherwise we will get compile time error.
In the above example there is no relation between String and StringBuilder. Hence we will get compile time error saying: incomparable types: String and StringBuilder

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

public class Test
{
public static void m1() throws Exception
{
System.out.print(“A”);
throw new TestException();
}
public static void main(String[] args)
{
try
{
m1();
}
catch (TestException e)
{
System.out.println(“B”);
}
finally
{
System.out.println(“C”);
}

} }
A

m1() throws Exception and hence compulsory inside main method we should handle exception, but we are handling TestException. Hence we will get compile time error saying: unreported exception Exception; must be caught or declared to be thrown

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

ArrayList (3 rules)

A
  • ArrayList is mutable object.
  • ArrayList not having fixed size.Based on our requirement, we can increase or decrease the size.
  • ArrayList can hold both homogeneous and heterogeneous elements.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

If try,catch and finally blocks contains separate return statements

A

then finally block return statement will get more priority.

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

ArrayList method
remove()

A

The remove() methods remove the first matching value in the ArrayList or remove the element at a specified index. The method signatures are as follows:

boolean remove(Object object)
E remove(int index)

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

java.lang.Object
|
java.lang.Throwable
|
—————————————
| |
java.lang.Exception |
| |
| java.lang.Error
|
java.lang.RuntimeException

A

exception hierarchy

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