OPTISOL INTERVIEW QUESTIONS FOR FRESHERS WITH ANSWERS
This blog explains about OPTISOL INTERVIEW QUESTIONS FOR FRESHERS WITH ANSWERS and is given below :
_____________________________________________________
1. Write a java program to ” Reverse a string using recursion”
To understand these programs you should have the knowledge of following core java concepts:
1) substring() in java
2) charAt() method
// Java program to reverse a string using recursionclass StringReverse
{ /* Function to print reverse of the passed string */ void reverse(String str) { if ((str==null)||(str.length() <= 1)) System.out.println(str); else { System.out.print(str.charAt(str.length()-1)); reverse(str.substring(0,str.length()-1)); } } /* Driver program to test above function */ public static void main(String[] args) { String str = “Payilagam”; StringReverse obj = new StringReverse(); obj.reverse(str); } } |
Output:
” magaliyaP “
____________________________________________________________________
2. Explain briefly about Collection program(list,set,map)
List in Java provides ordered and indexed collection which may contain duplicates.
The Set interface provides an un ordered collection of unique objects, i.e. Set doesn’t allow duplicates, while Map provides a data structure based on key-value pair and hashing.
All three List, Set, and Map are interfaces in Java and there are many concrete implementations of them are available in Collection API.
ArrayList and LinkedList are two most popular used List implementation while LinkedHashSet, TreeSet, and HashSet are frequently used Set implementation.
_______________________________________________________________________________
3. Explain briefly about function overloading and function overriding
Overriding and Overloading are two very important concepts in Java.
They are confusing for Java novice programmers. This post illustrates their differences by using two simple examples.
-
Definitions
Overloading
It occurs when two or more methods in one class have the same method name but different parameters.
Overriding
It means having two methods with the same method name and parameters (i.e., method signature). One of the methods is in the parent class and the other is in the child class. Overriding allows a child class to provide a specific implementation of a method that is already provided its parent class.
- Overriding vs. Overloading
Here are some important facts about Overriding and Overloading:
1). The real object type in the run-time, not the reference variable’s type, determines which overridden method is used at runtime. In contrast, reference type determines which overloaded method will be used at compile time.
2). Polymorphism applies to overriding, not to overloading.
3). Overriding is a run-time concept while overloading is a compile-time concept.
-
An Example of Overriding
Here is an example of overriding. After reading the code, guess the output.
class Dog{ public void bark(){ System.out.println(“woof “);
} } class Hound extends Dog{ public void sniff(){ System.out.println(“sniff “); } public void bark(){ System.out.println(“bowl”); } } public class OverridingTest{ public static void main(String [] args){ Dog dog = new Hound(); dog.bark(); } } |
Output:
bowl
An Example of Overloading
class Dog{ public void bark(){ System.out.println(“woof “);
} //overloading method public void bark(int num){ for(int i=0; i<num; i++) System.out.println(“woof “); } } |
In this overloading example, the two bark method can be invoked by using different parameters. Compiler know they are different because they have different method signature .
_______________________________________________________________________________
4. Explain briefly about sql query using inner joint
Introduction to SQL Server INNER JOIN
The inner join is one of the most commonly used joins in SQL Server. The inner join clause allows you to query data from two or more related tables.
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
Consider the two tables below:
Student
STUDENT COURSE
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.
Example Queries(INNER JOIN)
- This query will show the names and age of students enrolled in different courses.
- SELECT StudentCourse.COURSE_ID, Student.NAME, Student.AGE FROM Student
- INNER JOIN StudentCourse
- ON Student.ROLL_NO = StudentCourse.ROLL_NO;
Output:
_______________________________________________________________________________
5.Find a duplicate characters in a string
// Java program to find the first// repeated character in a stringimport java.util.*;
class Main { // This function prints the first repeated // character in str[] static char firstRepeating(char str[]) { // Creates an empty hashset HashSet<Character> h = new HashSet<>(); // Traverse the input array from left to right for (int i=0; i<=str.length-1; i++) { char c = str[i]; // If element is already in hash set, update x // and then break if (h.contains(c)) return c; else // Else add element to hash set h.add(c); } return ‘\0’; } // Driver method to test above method public static void main (String[] args) { String str = “geeksforgeeks”; char[] arr = str.toCharArray(); System.out.println(firstRepeating(arr)); } } |

Output:
e
_______________________________________________________________________________
REFERENCES :
https://www.geeksforgeeks.org/reverse-a-string-using-recursion/
http://www.java67.com/2013/01/difference-between-set-list-and-map-in-java.html
https://www.programcreek.com/2009/02/overriding-and-overloading-in-java-with-examples/
https://www.geeksforgeeks.org/sql-join-set-1-inner-left-right-and-full-joins/
https://www.geeksforgeeks.org/find-the-first-repeated-character-in-a-string/