Round 1: Online Assessment (Aptitude + Coding + English Passage)
1. Which of these access specifiers can be used for an Interface?
a) Public
b) Protected
c) private
2. Name the method used by the Comparator Interface.
a) compareTo()
b) compare()
c) compareto()
d) None of these
3. How many String objects are created in the following piece of code?
public class ImmutableString Objects
{
public static void main(String[] args)
{
}
}
String s1 = "iByte";
String s 2=s1;
//Statement 1 //Statement 2 s 2=s1.
("Code's"); //Statement 3 s 2=s2+
"theopentutorials.com"; //Statement 4
options
a) Zero
b)One
c)Three
d) Five
e) None of the above
4. Predict the output of below Java code:
public class Test34 { public static
void main(String[] args)
{
// TODO Auto-generated method stub
int b * 1 = 80 ; int b * 2 = 10 ;
int b3; b3=++ b * 1b * 1 / 100
+++b2;
System.out.println("b3 = " + b3);
}
}
Options:
a) 51
b) 175
c) 176
d) 76
5. Which of the following is false? (Choose multiple)
1. Serialization cannot be done if Serializable interface is not implemented.
2. Serialization writes data in byte format.
3. Composite objects cannot be serialized until all the objects are Serializable.
4. Serialization compresses the data while serializing.
Options:
a) Only 4
b) 1 and 4
c) 2 and 3
d) Only 2
6. Which of the following is true?
1. Private variables are not serialized.
2. Transient variables are not serialized.
3. Volatile variables are not serialized. 4. Static Variables are not serialized
a) Only 1
b) 1 and 2
c) 2 and 4
d) 3 and 4
7. What will be the output of the following program?
public class SuperClass
{ protected byte doStuff (byte byteValue) throws NumberFormatException {
}
return (byte) (byteValue * 2); public static void
main(String[] args) throws Exception
{ // TODO Auto-generated method stub SuperClass s = new SubClass();
System.out.println("Value Printed is " + s.doStuff ((byte) 2)); }
}
public class SubClass extends SuperClass
{
protected byte doStuff(byte byteValue) { } return (byte) (byteValue * 3);
Options:
a) Program will not compile
b) Program will compile but will throw Runtime Exception
c) It will print "Value Printed is 4"
d) It will print "Value Printed is 6"
8. Predict the cutput of below Java code abstract class TestAbstract{ String
my_name; String myName() { my_name = "Laurus"; return my_name; } abstract
void display();
}
public class Test extends TestAbstract { public
static void main(String[] args)
{ // TODO Auto-generated method stub Test t = new Test(); t.display();
}
void display()
}
System.out.print("My name is " + n);
String n myName();
Options:
a) Compilation error as class cannot be declared as abstract.
b) Program compiles but leads to runtime exception.
c) Compilation error occurs as the abstract class Test Abstract contains a
nonabstract method.
d) Program will compile and execute successfully and prints "My Name is Laurus" el
None of these
9. What will be the output of the following program?
public class Foo
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println("Finally");
}
}
Options:
a) Finally
b) The code runs with no output.
c) Compilation fails.
d) An exception is thrown at runtime.
10. If the given input array is sorted or nearly sorted, which of the following
algorithm gives the best performance?
a) Insertion sort
b) Selection sort
c) Quick sort
d) Merge sort
11.Suppose a binary tree is constructed with n nodes, such that each node has
exactly either zero or two children. The maximum height of the tree will be?
a) (n+1)/2
b) (n-1)/2
c) n/2-1
d) (n+1)/2-1
12. The program which loads the main operating system or runtime environment
for the computer after it performs the self-tests is known as
a) boot
b) startup
c) None of the above.
13. The result of evaluating the postfix expression 5, 4, 6, +, *, 4, 9, 3, /, +, * is?
a) boot loader
b) 600
c) 350
d) 650
14.Predict the output of below Java Code:
public static void main(String args[]) throws Exception public class TestClass
{
{
if (1+1+1+1+1+1+1 == 7)
{
System.out.print("TRUE");
}
Else
Total Time Allocated for all 3 sections: 60 min
{
System.out.print("FALSE");
}
}
}
Options:
a) FALSE
b) 0
c) 1
d) TRUE
15. Which of the following is a correct way of initializing a BigInteger Variable?
a) BigInteger bd = 100000;
b) BigInteger bd = new (100000):
c) BigInteger bd
d) BigInteger bd new BigInteger("100000"); new BigInteger(100000);
Section 2 (2 marks each)
(Suggested time for this Section 25 minutes)
16. Bhanu spends 30% of his income on petrol on scooter. 1½ of the remaining
on house rent and the balance on food. If he spends Rs.300 on petrol then what
is the expenditure on house rent?
a) Rs.525
b) Rs.1000
c) Rs.675
d) Rs.175
Ans:1050
17. If the numerator of a fraction is increased by 25% and denominator
decreased by 20%, the new value is 5/4, what is the original value?
a) 3/5
b) 4/5
c) 7/8
d) 3/7
18. The length of a rectangle is increased by 60%. By what % would the width
have to be decreased to keep the area unchanged?
a) 30%
b) 60%
c) 75%
d) 37.5%
19. A student's grade in a course is determined by 6 quizzes and one
examination. If the examination counts thrice as much as each of the quizzes,
what fraction of final grade is determined by the examination?
a) 1/6
b) 1/5
c) 1/3
d) 1/4
20. Joe's father will be twice his age 6 years from now. His mother was twice his
age 2 years before. If Joe will be 24 two years from now, what is the difference
between his father's and mother's age?
a) 4
b) 6
c) 8
d) 10
21. A report consists of 20 sheets each of 55 lines and each such line consists of
65 characters. This report is retyped into sheets each of 65 lines such that each
line consists of 70 characters. The % reduction in the number of sheets
is closest to
a) 20
b) 5
c) 30
d) 35
22. A ship leaves on a long voyage. When it is 18 miles from the shore, a
seaplane, whose speed is 10 times that of the ship, is sent to deliver mail.
How far from the shore does the seaplane catch up with the ship? Time
Allocated for all 3 sections: 60 min
a) 24 miles
b) 25 miles
c) 22miles
d) 20 miles
23. Anand finishes a work in 7 days; Bittu finishes the same job in 8 days and
Chandu in 6 days. They take turns to finish the work. Anand on the first day,
Bittu on the second and Chandu on the third day and then Anand again and so
on. On which day will the work get over?
a) 3rd
b) 6th
c) 9th
d) 7th
24. If the distance traveled (s) in time (t) by a particle is given by the formula
s = 1+ 2t+3t2+4t3, then what is the distance traveled in the 4th second of its
motion?
a) 141m
b) 171m
c) 243m
d) 313m
25. A man is facing north-west. He turns 90 degrees in the clockwise direction
and then makes an about turn. He then turns another 135 degrees counter
clockwise. Which direction is he facing now?
a) South-East
b) South-West
c) West
d) East
Section 3 (1 mark each) (Suggested time for this Section 15 minutes)
Directions (Questions 26-30) Read the information given below and answer the
questions that follow:
I. A, B, C, D, E and F are six members of a family.
II. One couple has parents and their children in the family.
III. A is the son of C and E is the daughter of A..
IV. D is the daughter of F who is the mother of E.
26. Which of the following pairs is the parent of the couple?
a) AB
b) BC
c) CF
27. Who are the male members in the family?
a) A and C
28. Which of the following pairs is the parent of the children
a) BC
b) B and A
b) CF
d) None of these ans (A and F)
c) A, B and C
d) Cannot be determined ? d) None of these
b) BF
29. How many female members are there in the family?
a) Two
b) Three
c) Four
30. What relation do D and E bear to each other?
a) Sister and Brother
b) Mother and Son
d) Cannot be determined
c) Sisters
d) None of these
Read the passages below and answer the questions that follow:
PASSAGE A: Ether injected into gallbladder to dissolve cholesterol based gallstones.
This type one-day treatment is enough for gallstones not for calcium stones. This
method is alternative to surgery for millions of people who are suffering from this
disease.
For each of the statement 36 to 39, based on passage A, choose one of the following
options for the answers -
a) True
31. Calcium stones can be cured in one day:
b) False
32. Hundreds of people contains calcium stones:
33. Surgery is the only treatment to calcium stones:
b) Can't say
34. Ether will be injected into the gallbladder to cure the cholesterol based gall stones:
PASSAGE B: In the past helicopters were forced to ground or crash because of the
formation of the ice on the rotors and engines. A new electronic device has been
developed which can detect the water content in the atmosphere and warns the pilot if
the temperature is below freezing temperature about the formation of the ice on the
rotors and wings. Helicopters are safest to fly in bad weather because they can slow
down, stop and/or fly backwards or sideways. Over 3 million lives have been saved by
helicopters in both peacetime and wartime operations
For each of the statement 40 to 43, based on passage B, choose one of the following
options for the answers -
a) True
b) False
c) Can't say
35. The electronic device can avoid formation of the ice on the wings.
36. There will be the malfunction of rotor & engine because of formation of ice.
37. The helicopters were to be crashed or grounded.
38. There is only one device that warns about the formation of ice.
39. Helicopters are safer to fly in bad weather than Good weather conditions.
40. 3 Million equals to 300 Lakhs.
Round 2: Technical Interview
1) Tell me about yourself
2) What is Java?
Java is a high-level, object-oriented programming language used to build
applications that can run on any device with a Java Virtual Machine (JVM). It is
known for its platform independence, security, and large library support.
3) Why Java is platform independent?
Java is platform independent because it uses the **Java Virtual Machine (JVM)**.
When Java code is written, it is compiled into **bytecode**, which can run on any
system that has a JVM, regardless of the underlying operating system. This allows
Java programs to work on different platforms without modification, following the
principle of "write once, run anywhere."
4) Difference between abstract and interface
5) Explain shadow & deepcopy
1. Shadow Copy (Shallow Copy):
• Definition: A shallow copy creates a new object, but it does not copy the nested
objects (or elements) within it. Instead, it copies references to the original nested
objects.
• Behavior: Changes made to the nested objects in the shallow copy will reflect in
the original object, and vice versa, because both the original and the copied
object share the same references to the nested objects.
2. Deep Copy:
• Definition: A deep copy creates a new object and also recursively copies all the
nested objects. This means that the original object and the copied object are
completely independent of each other.
• Behavior: Changes made to the nested objects in the deep copy do not affect the
original object, as they are fully copied.
6) Explain garbage collection
Garbage Collection is a process in Java (and many other programming languages)
that automatically manages memory by reclaiming memory occupied by objects
that are no longer needed or referenced. It helps prevent memory leaks and
ensures efficient use of system resources.
Summary:
• Garbage Collection in Java is an automatic process that frees memory by
reclaiming memory from objects that are no longer in use.
• It helps in preventing memory leaks, improving memory management, and
optimizing performance by running in the background.
• The Garbage Collector identifies and removes unreachable objects, ensuring
that the program does not run out of memory.
7) What is normalization
Normalization is a process in database design used to organize data in a way that
reduces redundancy and dependency. It involves structuring the data into
multiple related tables to ensure that each piece of information is stored in only
one place, making the database more efficient and easier to maintain.
8) SQL joins and its types
SQL Joins are used to combine data from two or more tables based on a related
column between them. The most common reason for using joins is to retrieve data
that is stored across multiple tables in a relational database.
9) Delete a table syntax
The SQL DELETE statement is used to remove rows from a table, while the DROP
statement is used to remove the entire table from the database.
a) DELETE Statement (To delete rows from a table)
DELETE FROM table_name
WHERE condition;
b) DROP Statement (To delete a table)
DROP TABLE table_name;
Key Differences:
• DELETE: Removes rows but retains the table and its structure.
• DROP: Removes both the rows and the structure (i.e., the table itself).
Make sure to use DROP carefully, as it permanently deletes the table and cannot be
undone. DELETE is safer, as you can still restore the data if needed (assuming you
have backups or a transaction log).
10) Explain the method to create a list?
In Java, a **List** is an ordered collection of elements that allows duplicates and
can be resized dynamically. The most common implementation of the `List`
interface is the `ArrayList` class. You can also use other classes like `LinkedList`,
depending on your requirements. Below is an explanation of how to create and use
a `List` in Java.
### 1. **Using `ArrayList` to Create a List**
The `ArrayList` is part of the `java.util` package, and it provides a dynamic array to
store elements. You can create and manipulate the `ArrayList` using various
methods provided by the `List` interface.
#### **Steps to Create a List in Java using `ArrayList`**:
**Step 1:** Import the required package.
```java
import java.util.ArrayList;
import java.util.List;
```
**Step 2:** Create an instance of `ArrayList` (or any class that implements the
`List` interface).
```java
List<String> list = new ArrayList<>();
```
- Here, `String` is the type of elements stored in the list. You can replace it with
other data types as needed.
**Step 3:** Add elements to the list using the `add()` method.
```java
list.add("Java");
list.add("Python");
list.add("C++");
```
**Step 4:** Access elements in the list using the `get()` method (or iterate over the
list).
```java
System.out.println(list.get(0)); // Prints "Java"
```
**Step 5:** Print or use the list as needed. You can print the list directly using
`System.out.println()`.
```java
System.out.println(list); // Prints [Java, Python, C++]
```
### **Example Code:**
```java
import java.util.ArrayList;
import java.util.List;
public class CreateListExample {
public static void main(String[] args) {
// Step 1: Create a List using ArrayList
List<String> languages = new ArrayList<>();
// Step 2: Add elements to the List
languages.add("Java");
languages.add("Python");
languages.add("C++");
// Step 3: Access elements using get() method
System.out.println("First language: " + languages.get(0)); // Output: Java
// Step 4: Iterate through the list (optional)
for (String language : languages) {
System.out.println(language);
}
// Step 5: Print the entire list
System.out.println("Languages list: " + languages); // Output: [Java, Python,
C++]
}
}
```
### 2. **Other Ways to Create a List**
You can also use other types of lists like `LinkedList`, which is another
implementation of the `List` interface. The method for creating a `LinkedList` is
similar to that of `ArrayList`.
#### **Using `LinkedList`**:
```java
import java.util.LinkedList;
import java.util.List;
List<String> linkedList = new LinkedList<>();
linkedList.add("Java");
linkedList.add("Python");
linkedList.add("C++");
```
### **Differences Between `ArrayList` and `LinkedList`:**
- **ArrayList**: Best for fast random access (index-based access). It is backed by a
dynamic array and can be slower for insertions and deletions in the middle of the
list due to the need to shift elements.
- **LinkedList**: Better for frequent insertions and deletions from the middle of the
list. It is backed by a doubly linked list, making traversal slower but more efficient
for certain operations like inserting or deleting elements.
### 3. **List Initialization with Elements (Java 9 and later)**
Java 9 introduced a convenient method to create immutable lists directly, known
as the `List.of()` method.
```java
List<String> languages = List.of("Java", "Python", "C++");
System.out.println(languages); // Output: [Java, Python, C++]
```
- This method creates a list that cannot be modified (immutable). Any attempt to
modify the list will throw an `UnsupportedOperationException`.
### **Common Methods of the List Interface**:
- `add(E e)` – Adds an element to the list.
- `get(int index)` – Retrieves an element at the specified index.
- `remove(int index)` – Removes the element at the specified index.
- `size()` – Returns the number of elements in the list.
- `contains(Object o)` – Checks if a particular element exists in the list.
- `clear()` – Removes all elements from the list.
### Summary:
- To create a list in Java, you typically use **`ArrayList`** or **`LinkedList`**, both
of which implement the **`List`** interface.
- The **`ArrayList`** is the most commonly used class for creating dynamic arrays.
- Lists can be created, modified, and accessed using various built-in methods such
as `add()`, `get()`, `remove()`, and `size()`.
11) Explain the final keyword
In Java, the final keyword is used to indicate that a particular variable, method,
or class cannot be modified. It provides a way to make certain parts of the code
immutable, ensuring that they cannot be changed once they are set. The final
keyword can be used in different contexts, such as for variables, methods, and
classes.
Key Points About final Keyword:
• final variables: Value cannot be changed once assigned.
• final methods: Cannot be overridden by subclasses.
• final classes: Cannot be subclassed.
• final parameters: Cannot be modified within the method.
Why Use the final Keyword?
• Immutability: It ensures that certain variables, methods, or classes are
immutable and cannot be changed, which is useful in cases where constant
values, method behavior, or class inheritance should not be modified.
• Performance: In some cases, marking methods or variables as final may help
the Java Virtual Machine (JVM) optimize performance.
12) Questions on SQL commands & html tags
1. What is the difference between INNER JOIN and OUTER JOIN?
• INNER JOIN: Returns only the rows where there is a match in both tables. If
there is no match, the row is not included.
• OUTER JOIN: Returns all rows from one table and the matched rows from the
other table. If there is no match, the result will contain NULL for columns from
the table that has no match.
o LEFT OUTER JOIN: Returns all rows from the left table and the matched
rows from the right table.
o RIGHT OUTER JOIN: Returns all rows from the right table and the
matched rows from the left table.
o FULL OUTER JOIN: Returns all rows when there is a match in one of the
tables.
2. What is the difference between DELETE, TRUNCATE, and DROP?
• DELETE: Removes rows from a table based on a condition. It is a DML (Data
Manipulation Language) operation and can be rolled back.
• TRUNCATE: Removes all rows from a table but does not log individual row
deletions. It is a DDL (Data Definition Language) operation and cannot be rolled
back in most databases.
• DROP: Deletes the entire table, including its structure, from the database. It is a
DDL operation and cannot be rolled back.
3. What is the purpose of GROUP BY in SQL?
• GROUP BY is used to group rows that have the same values in specified
columns into summary rows, such as finding the sum or average. Often used
with aggregate functions like COUNT(), SUM(), AVG(), MAX(), and MIN().
4. What is HAVING in SQL?
• HAVING is used to filter records after the GROUP BY operation. Unlike the
WHERE clause, which filters rows before grouping, HAVING filters groups after
the aggregation.
5. What are the different types of indexes in SQL?
• Clustered Index: Sorts the data rows in the table based on the index key. A
table can have only one clustered index.
• Non-clustered Index: Does not affect the order of the rows in the table. A table
can have multiple non-clustered indexes.
HTML Tags
Here are some commonly asked questions on HTML tags:
1. What is the difference between <div> and <span> in HTML?
• <div>: A block-level element that is used to group content and structure the
page layout. It takes up the full width of its parent container.
• <span>: An inline element that is used to group content for styling purposes
without affecting the flow of the document.
2. What is the use of the <a> tag in HTML?
• The <a> (anchor) tag is used to create hyperlinks to other pages, files, locations,
or any URL.
3. What is the purpose of the <form> tag in HTML?
• The <form> tag is used to collect user input through various form controls like
text boxes, checkboxes, radio buttons, etc. It sends the data to the server for
processing.
4. What is the difference between <ol> and <ul> in HTML?
• <ol>: Represents an ordered list where the list items are automatically
numbered.
• <ul>: Represents an unordered list where the list items are typically marked
with bullet points.
5. What is the purpose of the <img> tag in HTML?
• The <img> tag is used to display images on a webpage. It does not have a closing
tag, and the image is specified with the src attribute, which contains the image
URL.
6. What is the use of the <meta> tag in HTML?
• The <meta> tag provides metadata about the HTML document, such as
character encoding, author, viewport settings, and other details like description
and keywords for SEO.
7. What is the purpose of the <head> tag in HTML?
• The <head> tag contains meta-information about the HTML document, such as
the title, links to stylesheets, scripts, and metadata.
8. What is the difference between the <strong> and <em> tags in HTML?
• <strong>: Represents important text that should be displayed with emphasis,
typically bolded.
• <em>: Represents emphasized text, typically italicized, indicating stress or
importance.
13) OOPS concepts – Inheritance & Interface
Object-Oriented Programming (OOP) is a programming paradigm that uses objects
and classes to organize software design. Two important OOP concepts are
Inheritance and Interface. Let's break down each one:
1. Inheritance in OOP
Inheritance is the mechanism by which one class can acquire the properties and
behaviors (methods) of another class. It allows for the creation of a new class
based on an existing class, promoting code reuse and a hierarchical class
structure.
• Base Class (Parent Class): The class whose properties and methods are
inherited.
• Derived Class (Child Class): The class that inherits from the base class.
Key Points about Inheritance:
• Reusability: Inheritance allows you to reuse the code of an existing class.
• Extensibility: A subclass can extend the functionality of a parent class by
adding new methods or overriding existing ones.
• Single Inheritance: Inheritance can be one-to-one, where one subclass inherits
from a single superclass.
• Multiple Inheritance: In some languages (not Java), a class can inherit from
multiple classes. However, in Java, multiple inheritance is not supported
directly through classes, but interfaces can be used to achieve this.
Types of Inheritance:
• Single Inheritance: A subclass inherits from one superclass.
• Multilevel Inheritance: A subclass is derived from another subclass.
• Hierarchical Inheritance: Multiple subclasses inherit from a single superclass.
• Multiple Inheritance: A subclass inherits from more than one superclass
(possible through interfaces in Java).
2. Interface in OOP
An interface is a contract that a class must follow. It is a collection of abstract
methods (methods with no implementation) that a class must implement.
Interfaces allow different classes to share common methods but allow each class to
implement the methods in its own way.
Key Points about Interfaces:
• Abstract Methods: An interface only defines method signatures, without any
body (implementation).
• Multiple Inheritance: A class can implement multiple interfaces, allowing it to
inherit behavior from multiple sources.
• No Constructor: An interface cannot have constructors, as it cannot be
instantiated.
• Access Modifiers: All methods in an interface are implicitly public, and the
implementing class must provide a public implementation.
• No Instance Variables: An interface cannot have instance variables (fields), but
it can have constants.
When to Use Inheritance vs Interface?
• Use Inheritance:
o When there is a natural "is-a" relationship.
o When a subclass should share functionality of a superclass but also
needs to add or override certain behavior.
• Use Interface:
o When you need to define a contract for multiple classes to follow.
o When you want to implement multiple behaviors across unrelated classes.
o When you want to provide common functionality for different classes
without enforcing a class hierarchy.
14) Questions based on projects mentioned in the resume
15) Difference between Linear & Binary search
16) DSA concepts & Collection concepts
1. Data Structures (DS):
Data structures are ways to store and organize data in a computer so that
operations like access, insertion, deletion, and updating can be performed
efficiently.
Types of Data Structures:
• Linear Data Structures: Data elements are arranged in a linear order.
Examples:
o Array: A collection of elements identified by index or key. Fixed size.
o Linked List: A linear collection of elements (nodes), where each node
points to the next.
o Stack: Follows LIFO (Last In First Out) principle; operations like push and
pop.
o Queue: Follows FIFO (First In First Out) principle; operations like
enqueue and dequeue.
• Non-Linear Data Structures: Data elements are not arranged sequentially.
o Tree: Hierarchical structure with nodes. Examples: Binary Tree, AVL
Tree, Binary Search Tree.
o Graph: A collection of nodes (vertices) connected by edges. Can be
directed or undirected.
2. Algorithms (A):
An algorithm is a step-by-step procedure for solving a problem. It takes an input,
processes it, and provides an output.
Important Algorithm Concepts:
• Sorting Algorithms: Used to arrange elements in a specific order (ascending or
descending).
o Examples: Quick Sort, Merge Sort, Bubble Sort, Insertion Sort.
• Searching Algorithms: Used to find a specific element in a collection.
o Examples: Linear Search, Binary Search.
• Graph Algorithms: Used to traverse or search through graphs.
o Examples: Depth-First Search (DFS), Breadth-First Search (BFS),
Dijkstra’s Algorithm.
• Dynamic Programming: A method for solving complex problems by breaking
them down into simpler subproblems.
o Example: Fibonacci series, Knapsack problem.
• Greedy Algorithms: A method of solving optimization problems by making the
locally optimal choice at each step.
o Example: Kruskal’s or Prim’s Algorithm for Minimum Spanning Tree
(MST).
• Divide and Conquer: An algorithmic technique where the problem is divided
into smaller subproblems that are solved recursively.
o Example: Merge Sort, Quick Sort.
Complexity Analysis:
• Time Complexity: Measures the time an algorithm takes to complete as a
function of the input size (Big O notation).
• Space Complexity: Measures the memory required by an algorithm as a
function of the input size.
Collection Concepts in Java:
Java's Collections Framework provides a set of classes and interfaces that
implement commonly reusable collection data structures. It allows developers to
handle groups of objects more efficiently.
Key Collection Interfaces:
1. List: An ordered collection that can contain duplicate elements. Provides
methods for positional access to elements.
o Implementations: ArrayList, LinkedList, Vector.
2. Set: A collection that does not allow duplicate elements.
o Implementations: HashSet, LinkedHashSet, TreeSet.
3. Queue: A collection used to hold elements before processing. Follows FIFO (First
In First Out) principle.
o Implementations: LinkedList, PriorityQueue, ArrayDeque.
4. Map: A collection that maps keys to values, where each key is associated with
one value. Does not allow duplicate keys.
o Implementations: HashMap, TreeMap, LinkedHashMap.
Collection Classes:
1. ArrayList: A resizable array that allows fast random access and modification.
o Example: List<String> list = new ArrayList<>();
2. LinkedList: A doubly-linked list implementation of the List and Queue
interfaces. It allows fast insertion and deletion but slower random access.
o Example: List<String> list = new LinkedList<>();
3. HashSet: A collection that implements the Set interface and does not allow
duplicates. It is based on hash tables.
o Example: Set<Integer> set = new HashSet<>();
4. HashMap: A collection that implements the Map interface. It stores key-value
pairs and does not allow duplicate keys.
o Example: Map<String, Integer> map = new HashMap<>();
5. PriorityQueue: A queue where elements are ordered by their natural ordering or
by a comparator provided at queue construction time.
o Example: Queue<Integer> pq = new PriorityQueue<>();
Important Collection Operations:
1. Add: Insert an element into the collection.
o Example: list.add(element);
2. Remove: Remove an element from the collection.
o Example: list.remove(element);
3. Contains: Check if an element is present in the collection.
o Example: set.contains(element);
4. Size: Get the number of elements in the collection.
o Example: set.size();
5. Iterate: Traverse through the collection.
o Example: for (String item : list) { System.out.println(item); }
6. Clear: Remove all elements from the collection.
o Example: list.clear();
17) What is truncate
Truncate refers to the process of removing or shortening data, often by cutting off
part of it. This term is commonly used in different contexts, including databases,
programming, and data manipulation. Here's what it means in various scenarios:
1. In Databases (SQL):
In SQL, the TRUNCATE command is used to remove all rows from a table
without deleting the table structure itself. Unlike the DELETE statement, which
can be used with conditions (where clauses), TRUNCATE is a faster operation that
does not generate individual row delete statements or fire triggers. It essentially
resets the table.
• Syntax:
TRUNCATE TABLE table_name;
2. In Programming:
In programming, truncate refers to cutting off or limiting a number or string to a
certain length. It is often used when you want to reduce the size of data.
• For numbers: Truncating a floating-point number means removing the decimal
part (without rounding).
o Example:
▪ Truncate 7.89 to get 7 (discarding the decimal part).
• For strings: Truncating a string means cutting it off after a certain number of
characters.
o Example:
▪ Truncate the string "Hello, world!" to 5 characters: "Hello".
3. In File Systems:
In file systems, truncate can refer to reducing the size of a file by cutting off its
content. This operation typically removes data from the end of the file, effectively
reducing its size.
• For example, truncating a file to a certain length would delete all content beyond
that point.
Summary:
• In SQL: The TRUNCATE command removes all data from a table but keeps the
structure intact.
• In Programming: Truncating usually means reducing a number or string to a
smaller size by removing unnecessary parts.
• In File Systems: Truncating a file means cutting it down to a specified size,
typically removing content from the end.
18) what is Exception Handling
Exception Handling is a mechanism in programming languages (like Java,
Python, C++) that handles runtime errors (exceptions) in a graceful manner,
ensuring that the program doesn't abruptly terminate. It allows the programmer to
detect, catch, and respond to exceptions (errors) that occur during the execution of
a program.
Key Concepts in Exception Handling:
1. Exception: An event that disrupts the normal flow of the program. It occurs
during the execution and may be due to various reasons, such as invalid input,
network failure, or arithmetic errors (like division by zero).
2. Try-Catch Block:
o Try Block: The code that might cause an exception is placed inside the
try block.
o Catch Block: The catch block is used to handle exceptions that occur in
the try block. If an exception occurs, control is transferred to the catch
block.
3. Finally Block: A block of code that will always execute, whether or not an
exception occurs, used for clean-up activities (like closing file streams or
database connections).
4. Throw: Used to explicitly throw an exception in your code.
5. Throws: A keyword used in method declarations to indicate that a method may
throw an exception. It helps in delegating the exception handling to the calling
method.
How Exception Handling Works:
1. Exception Occurrence: An exception occurs in the try block.
2. Transfer to Catch Block: The program control is transferred to the
corresponding catch block that can handle that type of exception.
3. Finally Block: After the execution of the try-catch blocks, the finally block (if
any) is executed.
4. Program Continuation: If handled correctly, the program continues to execute
without termination. Otherwise, it might terminate depending on how the
exception is handled.
19) Full OOPS concepts
20) Collections & Normalization
21) What is byte code
Bytecode is a low-level, platform-independent representation of a program's source
code, typically generated by compiling high-level code like Java. It is not machine code
specific to any processor but is instead executed by a virtual machine (such as the
Java Virtual Machine, JVM). Bytecode is an intermediate code between the human-
readable source code and the machine-readable machine code.
22) Explain CRUD operations
**CRUD** stands for **Create**, **Read**, **Update**, and **Delete**. These are
the four basic operations used to interact with databases and perform standard
data manipulation tasks in software applications. CRUD operations are
fundamental in relational databases, RESTful APIs, and other data-driven
applications.
### **The 4 CRUD Operations:**
1. **Create**:
- **Purpose**: Adds new records (or data entries) into a database.
- **SQL Command**: `INSERT`
- **Example**: Adding a new student record to the "students" table.
**Example SQL**:
```sql
INSERT INTO students (name, age, grade)
VALUES ('John Doe', 21, 'A');
2. **Read**:
- **Purpose**: Retrieves or reads data from the database without modifying it.
- **SQL Command**: `SELECT`
- **Example**: Fetching all student records from the "students" table.
**Example SQL**:
```sql
SELECT * FROM students;
3. **Update**:
- **Purpose**: Modifies existing records or data entries in the database.
- **SQL Command**: `UPDATE`
- **Example**: Updating the grade of a specific student in the "students" table.
**Example SQL**:
```sql
UPDATE students
SET grade = 'B'
WHERE name = 'John Doe';
4. **Delete**:
- **Purpose**: Removes records or data entries from the database.
- **SQL Command**: `DELETE`
- **Example**: Deleting a student record from the "students" table.
**Example SQL**:
```sql
DELETE FROM students
WHERE name = 'John Doe';
### **CRUD Operations in a Database Context:**
- **Create**: Inserting new records into a database.
- **Read**: Querying the database to retrieve records (usually through `SELECT`
queries).
- **Update**: Modifying existing data within the database.
- **Delete**: Removing data from the database.
### **CRUD in Programming and APIs**:
In software development, especially when building **RESTful APIs**, CRUD
operations represent the basic functions that an API should perform on resources
(data). For example:
- **Create**: POST request (e.g., create a new user)
- **Read**: GET request (e.g., retrieve user data)
- **Update**: PUT or PATCH request (e.g., update user details)
- **Delete**: DELETE request (e.g., delete a user)
### **Summary**:
- **Create**: Insert new data.
- **Read**: Retrieve or view data.
- **Update**: Modify existing data.
- **Delete**: Remove data.