Interview QC Questions Part 2 Flashcards

1
Q

How have you used inheritance?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is polymorphism? Explain Method Overloading.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between an Error and an Exception?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the Scopes of Java variables? Explain Scopes.

A

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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Abstraction? What is the difference between an Interface and an abstract class?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where are variables stored in memory?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a wrapper class?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a package in java?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a Static method?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a relational database?

A

A relational database uses a structure that allows us to identify and access data in relation to another piece of data in the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is DDL?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is DML?

A

Data Manipulation Language

-Used to manipulate the data in Database objects like table, view, index ..etc,.
-INSERT, UPDATE, DELETE are the DML commands.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is DQL?

A

Data Query Language

-used to retrieve information from the database objects. it is for read only purpose.
– SELECT is the DQL or DRL command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is DCL?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is TCL?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the SQL sublanguages?

A

DDL- Data Definition Language
DML- Data Manipulation Language
DCL- Data Control Language
DQL- Data Query Language
TCL- Transaction Control Language

17
Q

Different SQL data types?

A

Integer, Big Integer, Double, Numeric, Serial

18
Q

SQL constraints? PK vs FK?

A
  • 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

19
Q

What is multiplicity?

A

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

20
Q

What is a sub query?

A

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.
21
Q

DROP vs DELETE vs TRUNCATE?

A

DROP - Delete a table
DELETE - delete records
TRUNCATE - delete the data in the table

22
Q

What is Maven?

A

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.

23
Q

What is JDBC? Steps need to take to do that?

A

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.

24
Q

What is the DAO design pattern

A

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.

25
Q

What is an SQL Injection? How do you prevent it?

A

An SQL Injection means injecting/inserting SQL code in a query via user-inputted data. It can occur in any applications using relational databases like Oracle, MySQL, PostgreSQL and SQL Server.

The simplest solution is to use PreparedStatement instead of Statement to execute the query.

For example, instead of concatenating username and password into the query, we provide them to query via PreparedStatement’s setter methods.

Now, the value of username and password received from the request is treated as only data so no SQL Injection will happen.

26
Q

What are aggregate functions?

A

Aggregate functions:

The Aggregate Functions in SQL perform calculations on a group of values and then return a single value. Following are a few of the most commonly used Aggregate Functions:

SUM()
Used to return the sum of a group of values.

COUNT()
Returns the number of rows either based on a condition, or without a condition.

AVG()
Used to calculate the average value of a numeric column.

MIN()
This function returns the minimum value of a column.

MAX()
Returns a maximum value of a column.

FIRST()
Used to return the first value of the column.

LAST()
This function returns the last value of the column.

27
Q

What are Scalar functions?

A

Scalar functions:
The Scalar Functions in SQL are used to return a single value from the given input value. Following are a few of the most commonly used Aggregate Functions:

LCASE()
Used to convert string column values to lowercase

UCASE()
This function is used to convert a string column values to Uppercase.

LEN()
Returns the length of the text values in the column.

MID()
Extracts substrings in SQL from column values having String data type.

ROUND()
Rounds off a numeric value to the nearest integer.

NOW()
This function is used to return the current system date and time.

FORMAT()
Used to format how a field must be displayed.

28
Q

What is a transaction?

A

A transaction is the logical work unit that performs a single activity or multiple activities in a database. Transactions may consist of a single read, write, delete, or update operations or a combination of these.

29
Q

How to retrieve data from more than one table at once?

A

You can merge data from two or more tables into a single column on a report by using the keyword UNION.

30
Q

SELECT * From Structures;

A

An asterisk (“ * “) can be used to specify that the query should return all columns of the queried tables. SELECT is the most complex statement in SQL, with optional keywords and clauses that include: The FROM clause, which indicates the table(s) to retrieve data from.

In the case of the following code:
SELECT * From Structures;

This line is stating that all all data from the structures column should be returned.

31
Q

What clauses do you use with a SELECT statement?

A

The Five Clauses of the SELECT Statement

SELECT – the columns in the result set.

FROM – names the base table(s) from which results will be retrieved.

WHERE – specifies any conditions for the results set (filter)

ORDER BY – sets how the result set will be ordered.

LIMIT – sets the number of rows to be returned.