Java Interview Qs Flashcards

1
Q

Difference between JRE and JVM?

A

JRE is an implementation of the JVM - If you want to execute java you need the JRE Installed

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

Can you have multiple inheritance in java?

A

Only through interfaces.

Interface can extent multiple interfaces

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

write the main method?

A

Public static void main(String arg[])

//public and static so that Java can access it without initializing the class
//pass runtime arguments
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Java.lang(Object) imported by default?

A

yes

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

what are the access modifiers for class?

A

for class - public and default

public: access from anywhere/class in other packages
default: can only be accessed from classes in that package

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

what are access modifiers for members?

A

public: global access
private: only inside the class
protected: classes in the same packages and subclasses
default: classes in the same package

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

how can we optimize SQL?

A
  1. Specific columns to retrieve
  2. use limit
    ex/ SELECT name, produce FROM products LIMIT 10
  3. Use “add index” to a table
  4. Don’t use select *
    ** Index - data structure improves the s[eed of operations
    Insert and Update take longer than selects with indexed tables.(Need to insert/update index values as well)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

ORM?

A

Object/Relational Mapping

Helps application achieve persistence. Keeping state- object live on beyond the scope

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

what is the final keyword?

A
  • used as a keyword so class cannot be extended
  • using final on a method in a parent class so the child class cannot override it
  • used with variables so it can only be assigned once
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is the static keyword?

A

class level variables are global

methods can be static - access only static variables

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

what is finalize?

A

called by the garbage collector in the object class

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

what is a static block?

A

group of statements that gets executed when the class is loaded into memory by java class loader

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

what is a class loader?

A

use custom if you want a class at runtime or FTP server or another web service at runtime

ex/ bootstrap, extensions, system

loads bytecode into memory when we want to access any class

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

inheritance

A
  • used for code reusability

- a subclass can inherit the contents of a superclass

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

polymorphism

A

a concept where an object behaves differently in different situations

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

compile time polymorphism

A
circle{
    public void draw();
    public void draw (int r);
}
overloading - different arguments same method name
17
Q

runtime polymorphism

A
"is-a" relationship
subclass method overrides the superclass method - different implementation, with the same name
18
Q

Abstraction

A

the concept of hiding the internal details and describing things in simple terms(Encapsulation and inheritance)

19
Q

Encapsulation

A

Hiding data with access modifiers so that it’s only visible to that class

20
Q

Interfaces

A
  • provide a way to achieve abstraction
  • interface can implement a superclass
  • another class can implement an interface but another interface extends an interface
    • All attributes of interface are public, static, final
21
Q

Abstract class vs. Interface

A

abstract classes can have method implementations but interfaces cannot mostly used as a base for subclass

22
Q

Wrapper Classes

A

immutable/final
object representation of primitive types
byte,short,int,long,float, double, char, boolean

23
Q

super();

A

access superclass constructor

24
Q

this

A

reference to the current object

25
garbage collecting
the process of checking the heap for objects that are no longer referenced and deleting them
26
serialization
convert java object to a stream, the stream can be saved to a file stream data -> object is deserialization
27
"InstanceofKeyword"
Checks if an object belongs to a class or not
28
Is string a type or class
String is an object, its a class
29
Pass by value
Java is passed by value | method parameter values are copied to another variable and then copied object is passed in
30
Pass by reference
reference to the actual parameter is passed to the method
31
what is stored on the stack?
LIFO - main method, reference variable, static varaibles