FSS Fresher Interview Questions with Answers

FSS Fresher Interview Questions with Answers 

This blog explains about FSS Fresher Interview Questions with Answers . It is given below :

__________________________________________________________1. Explain all the OOPs concepts with example and proper syntax ?

Object means a real-world entity such as a pen, chair, table, computer, watch, etc. Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. It simplifies the software development and maintenance by providing some concepts:

  • Object Oriented Programming is a programming concept that works on the principle that objects are the most important part of your program. It allows users create the objects that they want and then create methods to handle those objects. Manipulating these objects to get results is the goal of Object Oriented Programming.
  • Object Oriented Programming popularly known as OOP, is used in a modern programming language like Java

       Core OOPS concepts are:

  1. Abstraction
  2. Encapsulation
  3. Polymorphism
  4. Inheritance

 It simplifies the software development and maintenance by providing some concepts:

  • Object Oriented Programming popularly known as OOP, is used in a modern programming language like Java

Encapsulation

Encapsulation is the technique used to implement abstraction in object oriented programming. Encapsulation is used for access restriction to a class members and methods.

Abstraction

Abstraction is the concept of hiding the internal details and describing things in simple terms. For example, a method that adds two integers. The method internal processing is hidden from outer world. There are many ways to achieve abstraction in object oriented programming, such as encapsulation and inheritance.

Polymorphism

Polymorphism is the concept where an object behaves differently in different situations. There are two types of polymorphism – compile time polymorphism and runtime polymorphism.

Compile time polymorphism is achieved by method overloading. For example, we can have a class as below.

public class Circle {

      public void draw(){

            System.out.println(“Drwaing circle with default color Black and diameter 1 cm.”);

      }

      public void draw(int diameter){

            System.out.println(“Drwaing circle with default color Black and diameter”+diameter+” cm.”);

      }

      public void draw(int diameter, String color){

            System.out.println(“Drwaing circle with color”+color+” and diameter”+diameter+” cm.”);

      }

}

Inheritance

Inheritance is the object oriented programming concept where an object is based on another object. Inheritance is the mechanism of code reuse. The object that is getting inherited is called superclass and the object that inherits the superclass is called subclass.

 a simple example of inheritance in java.

 package com.journaldev.java.examples1;

 class SuperClassA

{

       public void foo(){

            System.out.println(“SuperClassA”);

      }

      }

 class SubClassB extends SuperClassA{

                  public void bar(){

            System.out.println(“SubClassB”);

      }

      }

 public class Test {

      public static void main(String args[]){

            SubClassB a = new SubClassB();

                        a.foo();

            a.bar();

      }

}

Association

Association is the OOPS concept to define the relationship between objects. Association defines the multiplicity between objects. For example Teacher and Student objects. There is one to many relationship between a teacher and students. Similarly a student can have one to many relationship with teacher objects. However both student and teacher objects are independent of each other.

Aggregation

Aggregation is a special type of association. In aggregation, objects have their own life cycle but there is an ownership. Whenever we have “HAS-A” relationship between objects and ownership then it’s a case of aggregation.

Composition

Composition is a special case of aggregation. Composition is a more restrictive form of aggregation. When the contained object in “HAS-A” relationship can’t exist on it’s own, then it’s a case of composition. For example, House has-a Room. Here room can’t exist without house.

__________________________________________________________________________

2. Explain about MY SQL Queries – Joints , DML , DDL , Stored procedure

A SQL Join statement is used to combine data or rows from two or more tables based on a common field between them. Different types of Joins are:

  • INNER JOIN
  • LEFT JOIN
  • RIGHT JOIN
  • FULL JOIN

The simplest Join is INNER JOIN.

INNER JOIN: 

The INNER JOIN keyword selects all rows from both the tables as long as the condition satisfies. This keyword will create the result-set by combining all rows from both the tables where the condition satisfies i.e value of the common field will be same.
Syntax:

SELECT table1.column1,table1.column2,table2.column1,….

FROM table1

INNER JOIN table2

ON table1.matching_column = table2.matching_column;

table1: First table.

table2: Second table

matching_column: Column common to both the tables.

Note: We can also write JOIN instead of INNER JOIN. JOIN is same as INNER JOIN.

LEFT JOIN:

This join returns all the rows of the table on the left side of the join and matching rows for the table on the right side of join. The rows for which there is no matching row on right side, the result-set will contain null. LEFT JOIN is also known as LEFT OUTER JOIN.

RIGHT JOIN:

RIGHT JOIN is similar to LEFT JOIN. This join returns all the rows of the table on the right side of the join and matching rows for the table on the left side of join. The rows for which there is no matching row on left side, the result-set will contain null. RIGHT JOIN is also known as RIGHT OUTER JOIN.

FULL JOIN: 

FULL JOIN creates the result-set by combining result of both LEFT JOIN and RIGHT JOIN. The result-set will contain all the rows from both the tables. The rows for which there is no matching, the result-set will contain NULL values.

These SQL commands are mainly categorized into four categories as discussed below:

  1. DDL(Data Definition Language) : DDL or Data Definition Language actually consists of the SQL commands that can be used to define the database schema. It simply deals with descriptions of the database schema and is used to create and modify the structure of database objects in database.

Examples of DDL commands:

  • CREATE– is used to create the database or its objects (like table, index, function, views, store procedure and triggers).
  • DROP– is used to delete objects from the database.
  • ALTER-is used to alter the structure of the database.
  • TRUNCATE–is used to remove all records from a table, including all spaces allocated for the records are removed.
  • COMMENT–is used to add comments to the data dictionary.
  • RENAME –is used to rename an object existing in the database.
  1. DML(Data Manipulation Language) :
  2.  The SQL commands that deals with the manipulation of data present in database belong to DML or Data Manipulation Language and this includes most of the SQL statements.

Examples of DML:

  • SELECT– is used to retrieve data from the a database.
  • INSERT– is used to insert data into a table.
  • UPDATE– is used to update existing data within a table.
  • DELETE– is used to delete records from a database table.
  1. DCL(Data Control Language) : 
  2. DCL includes commands such as GRANT and REVOKE which mainly deals with the rights, permissions and other controls of the database system.

Examples of DCL commands:

  • GRANT-gives user’s access privileges to database.
  • REVOKE-withdraw user’s access privileges given by using the GRANT command
  • TCL(transaction Control Language) : TCL commands deals with the transaction within the database.

Examples of TCL commands:

      • COMMIT– commits a Transaction.
      • ROLLBACK– rollbacks a transaction in case of any error occurs.
      • SAVEPOINT–sets a savepoint within a transaction.
  • SET TRANSACTION–specify characteristics for the transaction.

Definition of stored procedures

A stored procedure is a segment of declarative SQL statements stored inside the database catalog. A stored procedure can be invoked by triggers, other stored procedures, and applications such as JavaPythonPHP.

Stored Procedures in MySQL

MySQL is known as the most popular open source RDBMS which is widely used by both community and enterprise. However, during the first decade of its existence, it did not support stored procedures, stored functionstriggers, and events. Since MySQL version 5.0, those features were added to the MySQL database engine to make it more flexible and powerful.

MySQL stored procedures advantages

  • Typically, stored procedures help increase the performance of the applications. Once created, stored procedures are compiled and stored in the database. However, MySQL implements the stored procedures slightly different. MySQL stored procedures are compiled on demand. After compiling a stored procedure, MySQL puts it into a cache and maintains its own stored procedure cache for every single connection. If an application uses a stored procedure multiple times in a single connection, the compiled version is used, otherwise, the stored procedure works like a query.
  • Stored procedures help reduce the traffic between application and database server because instead of sending multiple lengthy SQL statements, the application has to send only the name and parameters of the stored procedure.
  • Stored procedures are reusable and transparent to any applications. Stored procedures expose the database interface to all applications so that developers do not have to develop functions that are already supported in stored procedures.
  • Stored procedures are secure. The database administrator can grant appropriate permissions to applications that access stored procedures in the database without giving any permissions on the underlying database tables.

________________________________________________________________________

 3 . Explain about Collections and Topics

Collections in Java

A Collection is a group of individual objects represented as a single unit. Java provides Collection Framework which defines several classes and interfaces to represent a group of objects as a single unit.

The Collection interface (java.util.Collection) and Map interface (java.util.Map) are the two main “root” interfaces of Java collection classes.

Need for Collection Framework : 
Before Collection Framework (or before JDK 1.2) was introduced, the standard methods for grouping Java objects (or collections) were Arrays or Vectors or Hashtables. All of these collections had no common interface.

Accessing elements of these Data Structures was a hassle as each had a different method (and syntax) for accessing its members:

filter_none

edit

play_arrow

brightness_4

// Java program to show whey collection framework was neededimport java.io.*;

import java.util.*;

class Test

{

    public static void main (String[] args)

    {

        // Creating instances of array, vector and hashtable

        int arr[] = new int[] {1, 2, 3, 4};

        Vector<Integer> v = new Vector();

        Hashtable<Integer, String> h = new Hashtable();

        v.addElement(1);

        v.addElement(2);

        h.put(1,”geeks”);

        h.put(2,”4geeks”);

        // Array instance creation requires [], while Vector

        // and hastable require ()

        // Vector element insertion requires addElement(), but

        // hashtable element insertion requires put()

        // Accessing first element of array, vector and hashtable

        System.out.println(arr[0]);

        System.out.println(v.elementAt(0));

        System.out.println(h.get(1));

        // Array elements are accessed using [], vector elements

        // using elementAt() and hashtable elements using get()

    }

}

Output:

11geek

SYNTAX

  • Object− Objects have states and behaviors. Example: A dog has states – color, name, breed as well as behavior such as wagging their tail, barking, eating. An object is an instance of a class.
  • Class− A class can be defined as a template/blueprint that describes the behavior/state that the object of its type supports.
  • Methods− A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.
  • Instance Variables− Each object has its unique set of instance variables. An object’s state is created by the values assigned to these instance variables.

_________________________________________________________

 4 . What do you mean by Exception handling in Java ?

What is an Exception?

An exception is an unwanted or unexpected event, which occurs during the execution of a program i.e at run time, that disrupts the normal flow of the program’s instructions.

Error vs Exception

Error: An Error indicates serious problem that a reasonable application should not try to catch.
Exception: Exception indicates conditions that a reasonable application might try to catch

Exception Hierarchy

All exception and errors types are sub classes of class Throwable, which is base class of hierarchy.One branch is headed by Exception. This class is used for exceptional conditions that user programs should catch. NullPointerException is an example of such an exception.Another branch,Error are used by the Java run-time system(JVM) to indicate errors having to do with the run-time environment itself(JRE).

// Java program to demonstrate how exception is thrown.class ThrowsExecp{

    public static void main(String args[]){

        String str = null;

        System.out.println(str.length());

    }

}

Output :

Exception in thread “main” java.lang.NullPointerException

    at ThrowsExecp.main(File.java:8)

REFERENCES : 

https://www.journaldev.com/12496/oops-concepts-java-example

https://www.geeksforgeeks.org/sql-join-set-1-inner-left-right-and-full-joins/

https://www.geeksforgeeks.org/sql-ddl-dml-dcl-tcl-commands/

http://www.mysqltutorial.org/introduction-to-sql-stored-procedures.aspx

https://www.geeksforgeeks.org/collections-in-java-2/

https://www.tutorialspoint.com/java/java_basic_syntax.htm

https://www.geeksforgeeks.org/exceptions-in-java/