Study Flashcards
- Difference between Object and Class
A class is a blueprint or template for creating objects. It defines properties (attributes) and behaviors (methods) that the objects created from it will have. An object, on the other hand, is an instance of a class. It’s a concrete entity with actual values for those properties and is capable of performing actions through its methods.
- Difference between Array and ArrayList
An array is a fixed-size collection of elements of the same type. Its size cannot be changed once created. An ArrayList, a part of Java’s Collections Framework, provides a more flexible way to handle collections of objects. It can dynamically resize itself and provides more methods for manipulating data, like adding or removing elements.This data type (especially in Java) allows for storage of different data types, whilst an array must be of a homogenous data type
- Difference between Inner Join and Left Join
In SQL, an inner join returns rows when there is a match in both tables being joined. A left join, however, returns all rows from the left table and the matched rows from the right table. If there is no match, the result is NULL on the right side.
- What is Normalization
Normalization is a process in database design to organize data to reduce redundancy and improve data integrity. It involves dividing large tables into smaller, related tables and linking them using relationships. The goal is to minimize duplication and avoid data anomalies.
- How to Write Code for a Constructor
A constructor is a special method in a class that is called when an object of that class is created. It typically initializes the object’s properties. In Java, a constructor has the same name as the class and no return type. For example, in a Person class, a constructor might look like this: public Person(String name) { this.name = name; }.
- What is Finally
In Java, finally is a block used in exception handling. It follows try and catch blocks and executes regardless of whether an exception is thrown or caught. It’s typically used for cleanup code, like closing file streams or releasing resources
- Can You Do Multiple Catch Blocks
Interview Response: Yes, you can have multiple catch blocks in Java. This allows you to handle different types of exceptions differently. Each catch block is matched in the order they are written and catches the specific exception it defines.
- Are Exceptions Caught in a Specific Order
Yes, exceptions are caught in the order in which catch blocks are defined. Java checks each catch block from top to bottom and the first catch block that matches the exception type gets executed. It’s important to catch more specific exceptions before more general ones.
- What is a Foreign Key?
A foreign key is a field (or collection of fields) in one table that uniquely identifies a row of another table. It’s used to establish and enforce a link between the data in two tables, essentially a reference to a primary key in another table.
- The Four Pillars of Object-Oriented Programming
- Encapsulation: Keeping the data (variables) and the code (methods) together in one unit (class), and restricting the access to the details of the implementation.
- Abstraction: Hiding complex implementation details and showing only the necessary features of an object.
- Inheritance: A mechanism where a new class can inherit properties and methods from an existing class.
- Polymorphism: The ability to process objects differently based on their data type or class.
Simplified Explanation: