Interview Prep Flashcards
What is polymorphism?
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
What are the main features of Java?
portable, robust, secure, platform-independent, OOP language, supports multithread
What is an Array?
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
Where are Arrays created?
On the heap memory, not on the stack
What is the syntax to create an Array?
dataType[] arrayVariableName = new dataType[arraySize];
Is it possible to create an Array without giving it a size?
No - this will cause a compile-time error
What is a runtime error?
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
What are the basic principles of OOP?
Abstraction, Encapsulation, Inheritance, Polymorphism
What is abstraction in Java?
Abstraction means hiding the detailed information from the user. Abstraction can be achieved by interfaces and abstract classes.
What is inheritance in Java?
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.
What is an object in Java
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
What is method overloading?
When a method has the same name but a different number of arguments
Does Java support multiple inheritance?
No, but multiple inheritance can be gained by using interfaces
What is the difference between a method and a constructor?
A constructor is a method within a class with the same name as the class and no return type.
Can the main method be overloaded?
Yes
What is the difference between an error and an exception?
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.
What is the difference between static and non-static methods?
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.
What are the different ways to create threads in Java?
There are two ways:
- Implement Runnable interface
- By extending Thread class
What is synchronisation in Java?
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.
What is the final keyword used for?
We cannot change the value of a final variable. We are not able to inherit a final class and cannot override a final method.
What is meant by garbage collection in Java?
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.
What are the types of joins in SQL?
Cross join Inner join Left outer join Right outer join Full outer join
What is an inner join in SQL?
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.
What is a left outer join in SQL
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.