Interview QC Questions Part 2 Flashcards
How have you used inheritance?
We once created a base Animal class with varying variables and attributes. We then created a Cat class that extended the base Animal class allowing us to call those attributes from the Animal class such as getEats or getNoOfLegs.
What is polymorphism? Explain Method Overloading.
Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.
If a class has multiple methods having same name but different in parameters, it is known as Method Overloading. Suppose we have a class called, “Animal” and two child classes, “Cat,” and “Dog.” If the Animal class has a method to make a noise, called, “makeNoise,” then, we can override the “makeNoise” function that is inherited by the sub-classes, “Cat” and “Dog,” to be “meow” and “bark,” respectively.
What is the difference between an Error and an Exception?
An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. Exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist.
What are the Scopes of Java variables? Explain Scopes.
Every variable used in a programming language holds a scope. The scope tells the compiler about the segment within a program where the variable is accessible or used.
- block scope (a local var within a for loop)
- method scope (method vars only exist within the method: static/instance)
- class, or static scope (vars changes reflected across all instances of a class; static keyword)
- instance, or object scope (instance variable is attached to individual objects created from the class)
What is Abstraction? What is the difference between an Interface and an abstract class?
Abstraction means showing only the relevant details to the end-user and hiding the irrelevant features that serve as a distraction. An abstract class allows you to create functionality that subclasses can implement or override. An interface only allows you to define functionality, not implement it
Where are variables stored in memory?
In Java all objects are dynamically allocated on Heap. When an Objects is allocated using new(), the object is allocated on Heap, otherwise the Object is allocated on a Stack if not global or static.
What is a wrapper class?
A Wrapper class is a class which contains the primitive data types (int, char, short, byte, etc).
Wrapper classes provide a way to use primitive data types as objects. These wrapper classes come under java.util package.
What is a package in java?
A java package is a group of similar types of classes, interfaces and sub-packages.
Package in java can be categorized in two form, built-in package and user-defined package.
There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.
Java package is used to categorize the classes and interfaces so that they can be easily maintained.
Java package provides access protection.
Java package removes naming collision.
What is a Static method?
In Java, a static method is a method that belongs to a class rather than an instance of a class. The method is accessible to every instance of a class, but methods defined in an instance are only able to be accessed by that object of a class.
What is a relational database?
A relational database uses a structure that allows us to identify and access data in relation to another piece of data in the database.
What is DDL?
Data Definition Language
– Used to define Database objects like TABLE, VIEW,SEQUENCE,INDEX,SYNONYM creation or modification or removing.
–CREATE,ALTER,DROP,TRUNCATE,RENAME are the DDL commands
What is DML?
Data Manipulation Language
-Used to manipulate the data in Database objects like table, view, index ..etc,.
-INSERT, UPDATE, DELETE are the DML commands.
What is DQL?
Data Query Language
-used to retrieve information from the database objects. it is for read only purpose.
– SELECT is the DQL or DRL command.
What is DCL?
Data Control Language
Data control statements are use to give privileges to access limited data or share the information between users.
-GRANT,REVOKE ,AUDIT,COMMENT, ANALYZE are the DCL commands.
What is TCL?
Transaction Control Language
-Transaction control statement are use to apply the changes permanently save into database.
-COMMIT, ROLLBACK, SAVEPOINT, ROLLBACK TO are the TCL commands.
What are the SQL sublanguages?
DDL- Data Definition Language
DML- Data Manipulation Language
DCL- Data Control Language
DQL- Data Query Language
TCL- Transaction Control Language
Different SQL data types?
Integer, Big Integer, Double, Numeric, Serial
SQL constraints? PK vs FK?
- Unique
- Not null
- Default
- Check
- Foreign Key
- Primary Key
Primary key used to ID a row or record, null values are not allowed.Foreign key a column in a table that refers to the primary key of another table
What is multiplicity?
Multiplicity is used to describe the way in which two classes are related to each other.
one to one
one to many
many to one
many to many
What is a sub query?
A subquery is a SQL query nested inside a larger query.
A subquery may occur in : - A SELECT clause - A FROM clause - A WHERE clause
You can use a subquery in a SELECT, INSERT, DELETE, or UPDATE statement to perform the following tasks:
- Compare an expression to the result of the query.
-Determine if an expression is included in the results of the query.
-Check whether the query selects any rows.
DROP vs DELETE vs TRUNCATE?
DROP - Delete a table
DELETE - delete records
TRUNCATE - delete the data in the table
What is Maven?
Maven is a build automation tool used primarily for Java projects. It’s purpose is to build, publish, and deploy several projects at once for better project management.
What is JDBC? Steps need to take to do that?
JDBC (Java Database Connectivity) is the Java API that manages connecting to a database, issuing queries and commands, and handling result sets obtained from the database.
JDBC acts as a bridge from your code to the database.
Steps to create a JDBC:
Register the Driver class
-The forName() method of Class class is used to register the driver class.
Create connection
-The getConnection() method of DriverManager class is used to establish connection with the database.
Create statement
-The createStatement() method of Connection interface is used to create statement. The object of statement is responsible to execute queries with the database.
Execute queries
-The executeQuery() method of Statement interface is used to execute queries to the database. This method returns the object of ResultSet that can be used to get all the records of a table.
Close connection
-By closing connection object statement and ResultSet will be closed automatically. The close() method of Connection interface is used to close the connection.
What is the DAO design pattern
The Data Access Object (DAO) pattern is a structural pattern that allows us to isolate the application/business layer from the persistence layer using an abstract API.
The API hides from the application all the complexity of performing CRUD operations in the underlying storage mechanism. This permits both layers to evolve separately without knowing anything about each other.