Interview Prep Flashcards

1
Q

What is polymorphism?

A

Using the same method to do different things eg when extending a class. For example, the Animal class might contain the method makeSound() and the Pig class which extends the Animal class might use the makeSound() method to print “oink” by overriding this method

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

What are the main features of Java?

A

portable, robust, secure, platform-independent, OOP language, supports multithread

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

What is an Array?

A

All elements have the same data type. Arrays are a fixed same and this size cannot be changed once declared. Accessing an invalid index will cause an exception

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

Where are Arrays created?

A

On the heap memory, not on the stack

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

What is the syntax to create an Array?

A

dataType[] arrayVariableName = new dataType[arraySize];

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

Is it possible to create an Array without giving it a size?

A

No - this will cause a compile-time error

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

What is a runtime error?

A

A runtime error occurs when a program does not contain any syntax errors but features a command the computer can not perform, such as dividing by 0

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

What are the basic principles of OOP?

A

Abstraction, Encapsulation, Inheritance, Polymorphism

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

What is abstraction in Java?

A

Abstraction means hiding the detailed information from the user. Abstraction can be achieved by interfaces and abstract classes.

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

What is inheritance in Java?

A

Inheritance allows a Java class or interface to inherit properties and behaviour from another class or interface. Inheritance can be gained by implementing interfaces or extending classes.

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

What is an object in Java

A
An object is an instance of a class. A class is a blueprint for an object, containing its basic properties and behaviour. The new keyword is used to instantiate a class and make an object.
For example, Animal.java has a class named Animal. Animal animal = new Animal() is an object or instance of this class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is method overloading?

A

When a method has the same name but a different number of arguments

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

Does Java support multiple inheritance?

A

No, but multiple inheritance can be gained by using interfaces

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

What is the difference between a method and a constructor?

A

A constructor is a method within a class with the same name as the class and no return type.

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

Can the main method be overloaded?

A

Yes

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

What is the difference between an error and an exception?

A

Error is generated by the environment at runtime. The exception is generated by the application intentionally or mistakenly. An exception can be checked or unchecked, but the error is only unchecked.

17
Q

What is the difference between static and non-static methods?

A

Static methods belong to a class but non-static methods belong to an object. You don’t need to instantiate a class to access the static methods, but you have to instantiate the class to get access to non-static methods.

18
Q

What are the different ways to create threads in Java?

A

There are two ways:

  1. Implement Runnable interface
  2. By extending Thread class
19
Q

What is synchronisation in Java?

A

Synchronization is a technique to control access of a method with multiple threads at the same time. If we declare a method synchronized, then only one thread can use this method at a time. This is used for Thread safety.

20
Q

What is the final keyword used for?

A

We cannot change the value of a final variable. We are not able to inherit a final class and cannot override a final method.

21
Q

What is meant by garbage collection in Java?

A

Cleaning an object from memory which is not used is called garbage collection. It’s an important feature of Java and does not need to be done manually because Java does this automatically.

22
Q

What are the types of joins in SQL?

A
Cross join
Inner join
Left outer join
Right outer join
Full outer join
23
Q

What is an inner join in SQL?

A

An inner join retrieves data where the records from the first table are equal to the records from the second table, based on a set condition.

24
Q

What is a left outer join in SQL

A

When using this type of join, you will retrieve all the rows from the first (or left) table and the matching rows from the second (or right) table. If there is no matching row in the second table, you will get a NULL value.

25
Q

What is a full outer join in SQL?

A

Using this join will result in retrieving all the rows from the first table and all the rows from the second table. If there are non-matching rows, both from the first and second tables, they will be shown as a NULL value.

26
Q

What is a cross join in SQL?

A

This type of join means that every row from one table is joined to every row from another table. It multiplies rows. If you’re working with a huge amount of data, this is not advisable. This type of join is also called the Cartesian product.