JAVA Flashcards

1
Q

explain JDK

A

It is the tool necessary to compile, document and package Java programs.
It contains JRE + development tools.

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

Explain JRE

A

JRE refers to a runtime environment in which Java bytecode can be executed.
It’s an implementation of the JVM which physically exists.

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

Explain JVM

A

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.

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

String args[] ?

A

It is the parameter passed to the main method.

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

JAVA Features

A

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

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

what is a Thread ?

A

A flow of execution is known as a Thread

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

What is a wrapper class ?

A

-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

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

What is a constructor ?

A
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a singleton

A

Singleton class is a class whose only one instance can be created. A class can be made singleton by making its constructor private.

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

What is the differrencce between arraylist , linkedList and vector ?

A

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.

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

What is the difference between a stack and a heap ?

A

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.

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

What are the packages ?

A

It creates a proper hierarchical structure which makes it easier to locate the related classes

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

Does java use pointers ?

A

Java doesn’t use pointers because they are unsafe and increases the complexity of the program.

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

What is JIT ?

A

JIT converts the bytecode into machine language and then JVM starts the execution.

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

What are the access modifiers?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a class ?

A

A class in Java is a blueprint which includes all your data. A class contains fields (variables) and methods to describe the behavior of an object.

17
Q

What is an object ?

A

It is an instance of a class. The object has state and behavior.The object of a class can be created by using thenewkeyword.

18
Q

What is Object Oriented Programming ?

A

-It is a system where programs are considered as a collection of objects

19
Q

Whart are the main concepts of OOP /Features :

A

a.Inheritance:Inheritance is a process where one class acquires the properties of another.+:reusability
b. Encapsulation:It is a mechanism of wrapping up the data and code together as a single unit.It is data hiding so the data in a class is hidden from other classes.
It can be achieved by Declaring all the variables in the class as private and writing public methods in the class to set and get the values of variables.
c. Abstraction(Interface / abstract classes):Abstraction is the methodology of hiding the implementation details from the user and only providing the functionality to the users.
In Java abstraction is achieved byinterfaces andabstract classes.
d. Polymorphism (overload /override):Polymorphism is the ability of a variable, function or object to take multiple forms.

20
Q

What is the Difference between a Local variable and an Instance variable ?

A
  • Local Varible: it is used inside a method, constructor, or ablock.
  • Instance Varible: is declared within a class, but outside a method. Every object of that class will create it’s own copy of the variable while using it.
21
Q

Methods

A

It is Used to represent the behavior of an object , it must have a return type , and it is possible to have the same name as the class.

22
Q

The final keyword ?

A

It is a non-access modifier

  • Final Variable : the variable’s value can’t be changes once assigned.
  • Final method : The method can’t be overriden by the inheriting class.
  • Final class : The class can’t be extended by any subclass but it can extends other class.
23
Q

The this() keyword ?

A
  • It can be used to refer to current class properties such as instance methods, variable, constructors, etc.
    • Itmust be the first line block .
24
Q

The super() keyword ?

A
  • It can be used to refer to class properties such as instance methods, variable, constructors of the parent class.
    • Itmust be the first line block .
25
Q

String Pool ?

A

-It is a collection of Strings which are stored in heap memory.
-Whenever a new object is created, String pool first checks whether the object is already present in the pool or not.
If it is present, then the same reference is returned to the variable else new object will be created in the String pool

26
Q

Canthiskeyword be used to refer static members?

A

Yes, It is possible but it is unnecessary to access static variables through objects

27
Q

Can we assign the reference tothisvariable?

A

No, this cannot be assigned to any value.If we try to do so, the compiler error will be shown

28
Q

No, because this() and super() must be the first statement in the class constructor.

A

Can you use this() and super() both in a constructor?