Java Interview Qs Flashcards
Difference between JRE and JVM?
JRE is an implementation of the JVM - If you want to execute java you need the JRE Installed
Can you have multiple inheritance in java?
Only through interfaces.
Interface can extent multiple interfaces
write the main method?
Public static void main(String arg[])
//public and static so that Java can access it without initializing the class //pass runtime arguments
Java.lang(Object) imported by default?
yes
what are the access modifiers for class?
for class - public and default
public: access from anywhere/class in other packages
default: can only be accessed from classes in that package
what are access modifiers for members?
public: global access
private: only inside the class
protected: classes in the same packages and subclasses
default: classes in the same package
how can we optimize SQL?
- Specific columns to retrieve
- use limit
ex/ SELECT name, produce FROM products LIMIT 10 - Use “add index” to a table
- 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)
ORM?
Object/Relational Mapping
Helps application achieve persistence. Keeping state- object live on beyond the scope
what is the final keyword?
- 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
what is the static keyword?
class level variables are global
methods can be static - access only static variables
what is finalize?
called by the garbage collector in the object class
what is a static block?
group of statements that gets executed when the class is loaded into memory by java class loader
what is a class loader?
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
inheritance
- used for code reusability
- a subclass can inherit the contents of a superclass
polymorphism
a concept where an object behaves differently in different situations