Basics Flashcards

1
Q

What is the difference between JDK and JRE?

A

JDK (Java Development Kit) contains the tools and
libraries for development of Java programs. It also contains
compilers and debuggers needed to compile Java program,

JRE (Java Runtime Environment). This is included in JDK.
JRE provides libraries and JVM that is required to run a Java
program.

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

What is Java Virtual Machine (JVM)?

A

Java Virtual Machine (JVM) is an abstract machine that executes Java Bytecode. There are different JVM for different hardware and software platforms. So JVM is platform dependent. JVM is
responsible for loading, verifying and executing the Bytecode on a platform.

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

What are the different types of memory areas allocated by JVM?

A
  1. ClassLoader: It is a component of JVM used to load class files.
  2. Class (Method) Area: It stores per-class structures such as the runtime constant pool, field and method data, and the code for methods.
  3. Heap: Heap is created a runtime and it contains the runtime data area in which objects are allocated.
  4. Stack: Stack stores local variables and partial results at runtime. It also helps in method invocation and return value. Each thread creates a private JVM stack at the time of thread creation.
  5. Program Counter Register: This memory area contains the address of the Java virtual machine instruction that is currently being executed.
  6. Native Method Stack: This area is reserved for all the native methods used in the application.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is JIT compiler?

A

Just In Time compiler also known as JIT compiler is used for performance improvement in Java. It is enabled by default. It is compilation done at execution time rather earlier. Java has popularized the use of JIT compiler by including it in
JVM.

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

How Java platform is different from other platforms?

A

Java is a platform independent language. Java compiler converts Java code in to byte code that can be interpreted by JVM. There are JVM written for almost all the popular platforms in the world.

Java byte code can run on any supported platform in same way. Where as other languages require libraries compiled for a specific platform to run.

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

Why people say that Java is ‘write once and run anywhere’ language?

A

You can write Java code on Windows and compile it in Windows platform. The class and jar files that you get from Windows platform can run as it is on Unix environment. So it is a truly platform independent language.

Behind all this portability is Java byte code. Byte code generated by Java compiler can be interpreted by any JVM. So it becomes much easier to write programs in Java and expect those to run on any
platform.

Java compiler javac compiles java code and JVM java runs that code.

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

How does ClassLoader work in Java?

A

ClassLoader loads files from their physical file locations e.g.
Filesystem, Network location etc.
There are three main types of ClassLoaders in Java.
1. Bootstrap ClassLoader: This is the first ClassLoader. It loads classes from rt.jar file.

  1. Extension ClassLoader: It loads class files from jre/lib/ext location.
  2. Application ClassLoader: This ClassLoader depends on CLASSPATH to find the location of class files. If you specify your jars in CLASSPATH, then this ClassLoader will load them
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Do you think ‘main’ used for mainmethod is a keyword in Java?

A

No, main is just a name of method. There can be multiple methods with same name main in a class file. It is not a keyword in Java.

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

Can we write main method as public void static instead of public static void?

A

Any method has to first specify the modifiers and then the return value. The order of modifiers can
change.

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

In Java, if we do not specify any value for local variables, then what will be the default value of the local variables?

A

Java does not initialize local variables with any default value. So these variables will be just null by default.

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

What is the difference between byte and char data types in Java?

A

Major difference between them is that a byte can store raw binary data where as a char stores characters or text data.

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