31-40 Flashcards

1
Q

Is string a data type in Java?

A

String is not a primitive data type in java. When a string is created in java, it’s actually an object of Java.Lang.String class that gets created. After creation of this string object, all built-in methods of String class can be used on the string object.

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

Why Strings in Java are called as Immutable?

A

In java, string objects are called immutable as once value has been assigned to a string, it can’t be changed and if changed, a new object is created.

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

What’s the difference between an array and Vector?

A

An array groups data of same primitive type and is static in nature while vectors are dynamic in nature and can hold data of different data types.

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

What is multi-threading?

A

Multi threading is a programming concept to run multiple tasks in a concurrent manner within a single program. Threads share same process stack and running in parallel. It helps in performance improvement of any program.

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

Why Runnable Interface is used in Java?

A

Runnable interface is used in java for implementing multi threaded applications. Java.Lang.Runnable interface is implemented by a class to support multi threading.

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

What are the two ways of implementing multi-threading in Java?

A
  1. By using Java.Lang.Runnable Interface. Classes implement this interface to enable multi threading. There is a Run() method in this interface which is implemented.
  2. By writing a class that extend Java.Lang.Thread class.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When a lot of changes are required in data, which one should be a preference to be used? String or StringBuffer?

A

Since StringBuffers are dynamic in nature and we can change the values of StringBuffer objects unlike String which is immutable, it’s always a good choice to use StringBuffer when data is being changed too much. If we use String in such a case, for every data change a new String object will be created which will be an extra overhead.

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

What’s the purpose of using Break in each case of Switch Statement?

A

Break is used after each case (except the last one) in a switch so that code breaks after the valid case and doesn’t flow in the proceeding cases too.

If break isn’t used after each case, all cases after the valid case also get executed resulting in wrong results.

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

How garbage collection is done in Java?

A

In java, when an object is not referenced any more, garbage collection takes place and the object is destroyed automatically. For automatic garbage collection java calls either System.gc() method or Runtime.gc() method.

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