JAVA Flashcards
explain JDK
It is the tool necessary to compile, document and package Java programs.
It contains JRE + development tools.
Explain JRE
JRE refers to a runtime environment in which Java bytecode can be executed.
It’s an implementation of the JVM which physically exists.
Explain JVM
It is an abstract machine. It is a specification that provides a run-time environment in which Java bytecode can be executed.
JVM follows three notations: Specification,Implementation,andRuntime Instance.
String args[] ?
It is the parameter passed to the main method.
JAVA Features
There are the following features in Java Programming Language.
Object-Oriented: Objects that incorporates both data and behavior.(Inheritance /Encapsulation /Polymorphism /Abstraction), oop +: Reuse of code,security ,data redundancy …
But it isn’ t 100% object oriented because it uses primitves such as boolean, byte, char, int, float, double, long, short which are not objects.
• Portable: Thanks to 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:Java is a platform independent programming language. 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 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 Exception handling, etc. make it more robust.
• High Performance:Java is faster than other traditional interpreted programming languages because JIT (Just In Time compiler) enables high performance in Java. JIT converts the bytecode into machine language and then JVM starts the execution.
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
what is a Thread ?
A flow of execution is known as a Thread
What is a wrapper class ?
-Wrapper classes provide a way to use primitive data types (int,boolean, etc..) as objects.
Sometimes you must use wrapper classes, for example when working with Collection objects, such asArrayList, where primitive types cannot be used
What is a constructor ?
It is used to initialize an object. It must have the same name as that of the class. Also, it has no return type and it is automatically called when an object is created. There are two types of constructors: -Default Constructor it initializes the instance variables and objects with the default values -Parameterized Constructor it initializes the instance variables with the provided values. The constructor can be overloaded. If the user created a constructor with a parameter then he should create another constructor explicitly without a parameter. Every time, an object is created using thenewkeyword, the default constructor of the class is called. The constructor must not have an explicit return type. Does constructor return any value? // Ans:yes, The constructor implicitly returns the current instance of the class Can you make a constructor final? // Ans: No, the constructor can't be final. Can we make constructors static? // Ans : No compiler error becaus eit is invoked only when an object is created Can you use this() and super() both in a constructor? // Ans : No, because this() and super() must be the first statement in the class constructor.
What is a singleton
Singleton class is a class whose only one instance can be created. A class can be made singleton by making its constructor private.
What is the differrencce between arraylist , linkedList and vector ?
ArrayList vs LinkedList vs Vector
ArrayListis implemented as a resizable array. As more elements are added to ArrayList, its size is increased dynamically. It’s elements can be accessed directly by using the get and set methods, since ArrayList is essentially an array.
LinkedListis implemented as a double linked list. Its performance on add and remove is better than Arraylist, but worse on get and set methods.
Vectoris similar with ArrayList, but it is synchronized.
What is the difference between a stack and a heap ?
Memory:
-Stack memory is used only by one thread of execution.
-Heap memory is used by all the parts of the application.
Access :
-Stack memory can’t be accessed by other threads.
- Objectsstored in the heap are globally accessible.
Memory Management :
-Follows LIFO manner to free memory.
-Memory management is based on the generation associated with each object.
Lifetime :
-Exists until the end of execution of the thread.
-Heap memory lives from the start till the end of application execution.
Usage :
-Stack memory only contains local primitive and reference variables to objects in heap space. -
-Whenever an object is created, it’s always stored in the Heap space.
What are the packages ?
It creates a proper hierarchical structure which makes it easier to locate the related classes
Does java use pointers ?
Java doesn’t use pointers because they are unsafe and increases the complexity of the program.
What is JIT ?
JIT converts the bytecode into machine language and then JVM starts the execution.
What are the access modifiers?
- Public:The classes, methods, or variables which are defined as public, can be accessed by any class or method.
- Protected:Protected can be accessed by the class of the same package, or by the sub-class of this class, or within the same class.
- Default:Default are accessible within the package only. By default, all the classes, methods, and variables are of default scope.
- PrivateThe private class, methods, or variables defined as private can be accessed within the class only.