0% found this document useful (0 votes)
29 views8 pages

Viva Questions Java DBMS

Uploaded by

rohandora854
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views8 pages

Viva Questions Java DBMS

Uploaded by

rohandora854
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Viva Questions and Answers for Java and DBMS

Java Viva Questions and Answers

What is Java?
Java is a high-level, platform-independent, object-oriented programming language.

What is the main feature of Java?


Its platform independence, achieved through the use of the Java Virtual Machine (JVM).

What is the main() method?


It is the entry point of a Java program. The signature is: public static void main(String[]
args)

What is the purpose of the public keyword in main()?


It makes the main() method accessible to the JVM.

Why is main() static?


It allows the JVM to call it without creating an object of the class.

What are Java tokens?


Tokens are the smallest elements of a program, such as keywords, literals, identifiers, and
operators.

What are literals in Java?


Literals are constant values assigned to variables, e.g., numbers, characters, or strings.

What are data types in Java?


Data types specify the type of data a variable can hold. Examples include int, float, char, and
boolean.

What is the size of an int in Java?


4 bytes (32 bits).

What is the difference between float and double?


float is a single-precision 32-bit type, while double is a double-precision 64-bit type.

What are control flow statements?


They control the execution of statements, including if, else, switch, loops (for, while, do-
while), and branching (break, continue).

What is a loop in Java?


A loop is used to execute a block of code repeatedly.
What is the syntax of a for loop?
for (initialization; condition; update) { // code }

What is the difference between while and do-while loops?


while checks the condition before executing the loop body, while do-while checks the
condition after executing the loop body.

What is an array?
An array is a collection of elements of the same type stored in contiguous memory locations.

How do you declare an array in Java?


int[] arr; // declaration
arr = new int[5]; // allocation

What is the default value of an array element?


- Numeric types: 0
- boolean: false
- Object references: null

What is a class?
A class is a blueprint for creating objects, defining their properties and behavior.

What is an object?
An object is an instance of a class containing data (fields) and methods to manipulate that
data.

How do you create an object in Java?


ClassName obj = new ClassName();

What is inheritance in Java?


Inheritance is a mechanism where one class acquires properties and methods of another
class using the extends keyword.

What are the types of inheritance in Java?


Single, Multilevel, and Hierarchical. Java does not support multiple inheritance with classes.

What is the super keyword?


It is used to refer to the immediate parent class.

What is polymorphism?
The ability of an object to take many forms, achieved through method overloading and
overriding.

What is method overloading?


Having multiple methods with the same name but different parameters.
What is method overriding?
Redefining a parent class method in the child class with the same signature.

What is an interface?
An interface is a reference type in Java containing abstract methods. It is implemented using
the implements keyword.

What is an abstract class?


A class that cannot be instantiated and may contain abstract methods.

What is the difference between an abstract class and an interface?


An abstract class can have both abstract and concrete methods, while an interface only has
abstract methods (prior to Java 8).

What are access modifiers in Java?


Access levels for classes and members: public, protected, default, and private.

What is encapsulation?
Encapsulation is bundling data and methods operating on that data within a single unit
(class).

What is the purpose of constructors?


Constructors initialize an object. They have the same name as the class and no return type.

What is the default constructor?


A no-argument constructor automatically provided if no other constructors are defined.

What are exceptions?


Exceptions are events that disrupt the normal flow of a program.

What is exception handling?


Exception handling manages exceptions using try, catch, finally, throw, and throws.

What is the difference between throw and throws?


throw is used to explicitly throw an exception, while throws declares exceptions a method
might throw.

What is a checked exception?


An exception checked at compile-time, e.g., IOException.

What is an unchecked exception?


An exception checked at runtime, e.g., ArithmeticException.

What are assertions in Java?


Assertions check assumptions in code using the assert keyword.
DBMS Viva Questions and Answers

What is DBMS?
DBMS (Database Management System) is software for managing databases.

What is a database?
A database is an organized collection of data.

What is RDBMS?
Relational Database Management System, where data is stored in tables with relationships.

What is a table?
A table is a collection of rows and columns.

What is SQL?
Structured Query Language is used to interact with databases.

What are DDL commands?


Data Definition Language commands, e.g., CREATE, ALTER, DROP.

What are DML commands?


Data Manipulation Language commands, e.g., INSERT, UPDATE, DELETE.

What is a primary key?


A unique identifier for table rows.

What is a foreign key?


A key linking one table to another.

What is normalization?
Process of organizing data to reduce redundancy.

What is a schema?
A schema is the structure of a database, defined formally.

What is a query?
A query is a request for data or information from a database.

What is the difference between DELETE and TRUNCATE?


DELETE removes specific rows with conditions, while TRUNCATE removes all rows in a
table without conditions.

What is a view?
A view is a virtual table based on the result of a SQL query.

What is a transaction?
A transaction is a unit of work performed against a database.
What are ACID properties?
Atomicity, Consistency, Isolation, and Durability - properties ensuring reliable transactions.

What is indexing?
Indexing improves the speed of data retrieval operations on a table.

What is a join?
A join combines rows from two or more tables based on a related column.

What are the types of joins in SQL?


Inner Join, Left Join, Right Join, Full Join.

What is a subquery?
A query nested inside another query.

What is a constraint?
A constraint limits the type of data that can go into a table, e.g., PRIMARY KEY, FOREIGN
KEY, UNIQUE, NOT NULL.

What is a trigger?
A trigger is a procedure executed automatically in response to certain events on a table.

What is the difference between WHERE and HAVING?


WHERE filters rows before grouping, while HAVING filters after grouping.

What is the purpose of the GROUP BY clause?


It groups rows with the same values in specified columns.

What is a cursor?
A cursor is a database object used to retrieve, manipulate, and navigate through query
results.

What is the difference between CHAR and VARCHAR?


CHAR is a fixed-length datatype, while VARCHAR is variable-length.

What is a stored procedure?


A stored procedure is a set of SQL statements saved to be executed together.

What is a deadlock?
A deadlock occurs when two or more transactions wait for each other to release resources,
preventing further progress.

What is the difference between DROP and DELETE?


DROP removes the entire table, while DELETE removes specific rows.
1. What is a candidate key?

A candidate key is a minimal set of attributes that can uniquely identify a tuple in a table.

2. What is a composite key?

A composite key is a key that consists of two or more attributes to uniquely identify a
record.

3. What is a surrogate key?

A surrogate key is a unique identifier for a record, often generated by the system, and has
no business meaning.

4. What is the difference between primary key and unique key?

A primary key uniquely identifies records and does not allow NULL. A unique key ensures
uniqueness but can allow a single NULL value.

5. What are aggregate functions in SQL?

Aggregate functions perform calculations on multiple rows, returning a single value.


Examples include SUM, AVG, MAX, MIN, and COUNT.

6. What is the difference between clustered and non-clustered indexes?


• A clustered index determines the physical order of data in a table. A table can have only
one clustered index.
• A non-clustered index does not alter the physical order but maintains a separate
structure for faster queries.
7. What is the difference between INNER JOIN and OUTER JOIN?
• INNER JOIN: Returns rows with matching values in both tables.
• OUTER JOIN: Returns all matching rows, plus non-matching rows from one or both
tables (LEFT, RIGHT, FULL).
8. What is the AUTO_INCREMENT property?

It is used to generate a unique number automatically whenever a new row is inserted into a
table.

9. What are constraints?

Constraints enforce rules at the table or column level to maintain data integrity. Examples
include NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, and CHECK.

10. What is the difference between a database and a data warehouse?


• A database stores current transactional data.
• A data warehouse stores historical and aggregated data for analysis.

11. What are triggers in SQL?


Triggers are stored procedures that automatically execute in response to specific events
(e.g., INSERT, UPDATE, DELETE) on a table or view.

12. What is an ER diagram?

An Entity-Relationship (ER) diagram is a graphical representation of entities and their


relationships in a database.

13. What is referential integrity?

Referential integrity ensures that foreign key values in a child table match primary key
values in the parent table.

14. What is the difference between ROLLBACK and COMMIT?


• ROLLBACK: Undoes changes made during a transaction.
• COMMIT: Permanently saves changes made during a transaction.
15. What is a self-join?

A self-join is a join where a table is joined with itself.

16. What is a cross join?

A cross join produces a Cartesian product of two tables, pairing each row from the first table
with all rows from the second.

17. What are subqueries and their types?


• A subquery is a query nested inside another query. Types include:
• Single-row subquery: Returns one row.
• Multi-row subquery: Returns multiple rows.
• Correlated subquery: Depends on the outer query.

18. What is denormalization?

Denormalization is the process of combining normalized tables to improve query


performance at the cost of redundancy.

19. What is the difference between SQL and NoSQL?


• SQL: Relational databases, structured data, fixed schema.
• NoSQL: Non-relational databases, unstructured data, dynamic schema.

20. What is a database cursor?

A cursor is a database object used to retrieve and manipulate rows returned by a query one
at a time.
21. What is a transaction log?

A transaction log records all transactions performed on a database to ensure durability and
recovery in case of a failure.

22. What is the difference between CHECK and DEFAULT constraints?


• CHECK: Ensures values meet specific conditions.
• DEFAULT: Assigns a default value to a column if no value is provided.

23. What is a materialized view?

A materialized view stores the results of a query physically on disk, unlike a regular view,
which is virtual.

24. What are the differences between OLTP and OLAP?


• OLTP: Online Transaction Processing, optimized for read/write operations.
• OLAP: Online Analytical Processing, optimized for complex queries and reporting.
25. What is the purpose of the LIMIT clause?

The LIMIT clause restricts the number of rows returned by a query.

26. What is a phantom read?

A phantom read occurs when new rows are added by another transaction after a query is
executed in the current transaction.

27. What is the difference between EXISTS and IN?


• EXISTS: Checks for the existence of a subquery’s result.
• IN: Matches values in a list or result of a subquery.
28. What is a database partition?

Partitioning divides a table into smaller parts for better performance and manageability.

29. What is a database cluster?

A database cluster consists of multiple databases managed as a single entity to ensure high
availability and scalability.

30. What are stored functions?

Stored functions are similar to stored procedures but return a single value and are often
used in expressions.

You might also like