What is Java Development Kit & what does it include?
In order to start writing the code in Java, we need to install Java Dev. Kit
JDK includes:
- Compiler - will compile for Java a source code into java-byte code, which isn’t unique machine code & will be executed by Java Virtual Machine (JVM)
- Java Runtime Environment (JRE) contains JVM & core java libraries
- Tools for Java development (archiver, docs generator, etc.)
What is a method?
A method is a set of codes which is referred to by name & runs when it’s called. Each method has its own name. We need method to reuse the code: define the code once & use it many times
What is a main method?
Main method is a special method that actually runs the program. Everything in the main method will be executed when we run the program from top to bottom
What is a constructor?
It’s a special method to create an object
What’s a default constructor?
If we don’t define any constructors by ourselves java will provide one default (empty) constructor.
What is the difference between the constructor & the method?
What is the difference between local & instance variables?
What are the OOP concepts in Java you know?
Object Oriented Programming. In Java, we have 4 concepts:
Encapsulation, Inheritance, Abstraction, Polymorphism.
What’s an encapsulation in java and how do we achieve it?
It’s data protection(hiding) mechanism from the client code. We make instance variables as private and we provide public getters and setters. use pojo class
What’s inheritance in java?
Can you give an example of using the inheritance in your project?
It is a process where one class can inherit visible properties and methods from another class. Parent-child relationship (super class - subclass relationship). Inheritance is used for not creating the object. Using extends keyword
What’s abstraction in java?
When we focus on what object does instead of how it does it by hidding implementation details. We achvieve abstraction by using abstract method.
What’s polymorphism in java?
Polymorphism is the ability of the object to take many different forms.
List list = new ArrayList<>();
list = newLinkedList<>();
What’s POJO?
Plain Old Java Object. Usually, encapsulated objects referred as POJO.
What’s super class?
It’s parent class in inheritance.
What’s the class which every class will inherit from? Why?
java.lang.Object. To give generic behaviors for every object. For example, equals, hashCode, toString.
How many classes we can extend at once?
Just one because java supports only single type inheritance.
*** Java doesn’t support multiple inheritance.
Why Java doesn’t support multiple inheritance?
Java doesn’t support multiple inheritance in classes because of “Diamond Problem”.
Due to this Java does not support multiple inheritance i.e., you cannot extend more than one other class
What’s the difference between method overriding and method overloading?
What does ‘this’ and ‘super’ keyword mean in java?
Access modifiers
Method Arguments
Arguments are used to provide the data to the method.
Methods can have multiple arguments with different types
What is variable?
Variable is a container that can hold piece of information. There are different type of variables for different data types in Java.
What kind of logical operators do you know? And how do they work?
Logical operators are used to check whether an expression is true or false. They are used in decision making.
&& (Logical AND) expression1 && expression2
true only if both expression1 and expression2 are true
|| (Logical OR) expression1 || expression2
true if either expression1 or expression2 is true
! (Logical NOT) !expression
true if expression is false and vice versa
What’s a static keyword in Java?
public FileHelper {
public static String path = “ABC”;
public static String readContent() {
…
return