Java Interview Qs Flashcards Preview

Java Interview Questions 1 > Java Interview Qs > Flashcards

Flashcards in Java Interview Qs Deck (31)
Loading 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

2
Q

Can you have multiple inheritance in java?

A

Only through interfaces.

Interface can extent multiple interfaces

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
4
Q

Java.lang(Object) imported by default?

A

yes

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

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

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)
8
Q

ORM?

A

Object/Relational Mapping

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

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
10
Q

what is the static keyword?

A

class level variables are global

methods can be static - access only static variables

11
Q

what is finalize?

A

called by the garbage collector in the object class

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

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

14
Q

inheritance

A
  • used for code reusability

- a subclass can inherit the contents of a superclass

15
Q

polymorphism

A

a concept where an object behaves differently in different situations

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
Q

garbage collecting

A

the process of checking the heap for objects that are no longer referenced and deleting them

26
Q

serialization

A

convert java object to a stream, the stream can be saved to a file

stream data -> object is deserialization

27
Q

“InstanceofKeyword”

A

Checks if an object belongs to a class or not

28
Q

Is string a type or class

A

String is an object, its a class

29
Q

Pass by value

A

Java is passed by value

method parameter values are copied to another variable and then copied object is passed in

30
Q

Pass by reference

A

reference to the actual parameter is passed to the method

31
Q

what is stored on the stack?

A

LIFO - main method, reference variable, static varaibles