Section 1 Flashcards
Explain the difference between JDK, JRE, and JVM
JDK stands for Java Development Kit and is the development platform for developing Java applications. It includes the JRE, the interpreter (java), the compiler (javac), an archiver (jar), and a documentation generator (javadoc).
JRE stands for Java Runtime Environment. It is a standalone component used to run Java programs. It communicates between the Java program and the operating system.
JVM stands for Java Virtual Machine and is a specification that facilitates a run-time environment in which Java’s bytecode can be implemented.
What makes Java a platform-independent programming language?
Java is platform-independent because it uses a virtual machine. Java programs are compiled into bytecode. Bytecode is effectively platform-independent. The JVM converts this bytecode into bytecode for the machine’s operating system.
Would it be correct to say that Java is not 100% Object-oriented?
Yes, it would be correct to say that Java is not 100% object-oriented because it utilizes eight kinds of primitive data types:
boolean, byte, short, char, int, long, float, double
These data types are not objects, although wrapper classes can be used to create objects of each class.
What is a constructor in Java?
A constructor in Java is a special method that is used to initialize objects. The constructor is called when an object of a class is created. The constructor has the same name as the class. It calls a default constructor if there is no constructor available in the class. In such a case, the Java compiler provides a default constructor by default.
Can we mark constructors as final?
Declaring the constructor as final is not possible.
What is a class in Java?
In Java, classes are templates used for object creation, and to define certain object data types and their methods.
What is Java?
Java is a high-level, object-oriented, robust, secure programming language, platform-independent, high-performance, Multithreaded, and portable programming language. It was developed by James Gosling
in June 1991. It can also be known as the platform as it provides its own JRE and API.
List the features of Java Programming language
Object-Oriented: Java follows the object-oriented paradigm which allows us to maintain our code as the combination of different types of objects that incorporate both data and behavior.
Portable: Java supports read-once-write-anywhere approach. We can execute the Java program on every machine. Java program (.java) is converted to bytecode (.class) which can be easily run on every machine.
Platform Independent: It is different from other programming languages like C and C++ which needs a platform to be executed. Java comes with its platform on which its code is executed. Java doesn’t depend upon the operating system to be executed.
Secured: Java is secured because it doesn’t use explicit pointers. Java also provides the concept of ByteCode and Exception handling which makes it more secured.
Robust: Java is a strong programming language as it uses strong memory management. The concepts like Automatic garbage collection, Exception handling, etc. make it more robust.
Multithreaded: We can write Java programs that deal with many tasks at once by defining multiple threads. The main advantage of multi-threading is that it doesn’t occupy memory for each thread. It shares a common memory area. Threads are important for multi-media, Web applications, etc.
Dynamic: Java is a dynamic language. It supports dynamic loading of classes. It means classes are loaded on demand. It also supports functions from its native languages, i.e., C and C++.
What do you understand by Java virtual machine?
The Java virtual machine is an abstract (virtual) computer defined by a specification. It is a part of the java runtime environment. It enables a computer to run Java programs that are compiled into Java bytecode.
How many types of memory areas are allocated by JVM?
Class(Method) Area: Class Area stores per-class structures such as the runtime constant pool, field, method data, and the code for methods.
Heap: It is the runtime data area in which the memory is allocated to the objects
Stack: Java Stack stores frames. It holds local variables and partial results, and plays a part in method invocation and return. Each thread has a private JVM stack, created at the same time as the thread. A new frame is created each time a method is invoked. A frame is destroyed when its method invocation completes.
Program Counter Register: PC (program counter) register contains the address of the Java virtual machine instruction currently being executed.
Native Method Stack: It contains all the native methods used in the application.
What is JIT compiler?
The Just-In-Time compiler is used to improve performance. It compiles parts of the bytecode that have similar functionality at the same time, and hence reduces the amount of time needed for compilation. Here the term “compiler” refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU.
What gives Java its ‘write once and run anywhere’ nature?
The bytecode. Java compiler converts the Java programs into the class file (Byte Code) which is the intermediate language between source code and machine code. This bytecode is not platform specific and can be executed on any computer.
What is classloader?
Classloader is a subsystem of JVM which is used to load class files. Whenever we run the java program, it is loaded first by the classloader. There are three built-in classloaders in Java.
Bootstrap ClassLoader: This is the first classloader which is the superclass of Extension classloader. It loads the rt.jar file which contains all class files of Java Standard Edition like java.lang package classes, java.net package classes, java.util package classes, java.io package classes, java.sql package classes, etc.
Extension ClassLoader: This is the child classloader of Bootstrap and parent classloader of System classloader. It loads the jar files located inside $JAVA_HOME/jre/lib/ext directory.
System/Application ClassLoader: This is the child classloader of Extension classloader. It loads the class files from the classpath. By default, the classpath is set to the current directory. You can change the classpath using “-cp” or “-classpath” switch. It is also known as Application classloader.
If no arguments are provided on the command line when running a program, what will the value stored in the String array passed into the main() method, empty or NULL?
Empty, not null
What is the default value of local variables?
Local variables are not initialized to any default value, neither primitives nor object references.