71-80 Flashcards

1
Q

Is JDK required on each machine to run a Java program?

A

JDK is development Kit of Java and is required for development only and to run a Java program on a machine, JDK isn’t required. Only JRE is required.

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

What’s the difference between comparison done by .equals method and == operator?

A

In Java, equals() method is used to compare the contents of two string objects and returns true if the two have same value while == operator compares the references of two string objects.

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

Is it possible to define a method in Java class but provide it’s implementation in the code of another language like C?

A

Yes, we can do this by use of native methods. In case of native method based development, we define public static methods in our Java class without its implementation and then implementation is done in another language like C separately.

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

How are destructors defined in Java?

A

In Java, there are no destructors defined in the class as there is no need to do so. Java has its own garbage collection mechanism which does the job automatically by destroying the objects when no longer referenced.

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

Can a variable be local and static at the same time?

A

No a variable can’t be static as well as local at the same time. Defining a local variable as static gives compilation error.

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

Can we have static methods in an Interface?

A

Static methods can’t be overridden in any class while any methods in an interface are by default abstract and are supposed to be implemented in the classes being implementing the interface. So it makes no sense to have static methods in an interface in Java.

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

In a class implementing an interface, can we change the value of any variable defined in the interface?

A

No, we can’t change the value of any variable of an interface in the implementing class as all variables defined in the interface are by default public, static and Final and final variables are like constants which can’t be changed later.

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

s it correct to say that due to garbage collection feature in Java, a java program never goes out of memory?

A

Even though automatic garbage collection is provided by Java, it doesn’t ensure that a Java program will not go out of memory as there is a possibility that creation of Java objects is being done at a faster pace compared to garbage collection resulting in filling of all the available memory resources.

So, garbage collection helps in reducing the chances of a program going out of memory but it doesn’t ensure that.

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

I want to re-reach and use an object once it has been garbage collected. How it’s possible?

A

Once an object has been destroyed by garbage collector, it no longer exists on the heap and it can’t be accessed again. There is no way to reference it again.

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