TR Questions Infosys3
TR Questions Infosys3
Java
1. Super keyword?
2. Object class in Java?
3. Errors and Exceptions?
4. Treemap?
5. Thread in Java?
6. Platform independence?
7. Call by Value vs. Call by Reference
8. D/B String and StringBuilder?
9. D/B ArrayList and LinkedList?
C++
1. Namespace std?
2. Diamond problem?
3. How we can Implement an interface in c++?
4. D/B Pointer and Reference variable ?
5. D/B Array and Vector?
6. D/B map and unordered_map?
OOPs –
1. Object-Oriented programming?
2. Abstraction ? Data Abstraction
3. Inheritance & types
4. Polymorphism ? (Static / Compile-Time Polymorphism)
(Dynamic / Runtime Polymorphism)
5. Encapsulation
6. Constructor & types ?
7. Static Blocks
8. Function overolading
9. Interface, use ?
10. D/B Overloading & Overriding
11. D/B Class & Object
12. D/B Abstraction and interface
Data Structure-
1. Data Structure
2. Stack & Queue
3. Stack & Array
4. Which sorting algorithm is best?
5. Hash map & hash set
6. Merge Sort.
7. Heap Sort
Database-
1. Database
2. Normalization
3. Key in DBMS Types of keys
4. D/B Primary key and unique key
5. Join in SQL
6. Referential integrity
7. Sub query
8. Acid Proporties
9. SQL Commands
10. SQL?
11. BCNF?
12. Find duplicate row or column in database
13. Primary key and the Foreign key?
14. Data manipulation languages DML ?
15. D/B Delete and truncate.
16. D/B Char and Varchar in DBMS
17. D/B Inner join and Outer join?
18. D/B DROP and DELETE command.
19. D/B MySQL & NoSQL.
TOP
Network protocol
TOP
D/B Call byvalue and call by reference
Call By Reference
Call By Value
1. Super keyword?
super can be used to refer immediate parent class instance
variable.can be used to invoke immediate parent class method.
can be used to invoke immediate parent class constructor.
2. Object Class In Java
The Object class is the parent class of all the classes in java
by default. In other words, it is the topmost class of java.
The Object class is beneficial if you want to refer any object
whose type you don't know. Notice that parent class reference
variable can refer the child class object, know as upcasting.
Error Exceptions
Errors are usually raised by Exceptions are caused by the
the environment in which the code of the application itself.
application is running. For
example, an error will occur
due to a lack of system
resources.
It is not possible to recover The use of try-catch blocks
from an error. can handle exceptions and
recover the application from
them.
Errors occur at run-time and Exceptions can be “checked”
are not known by the or “unchecked,” meaning they
compiler; hence, they are may or may not be caught by
classified as “unchecked.” the compiler.
TOP
4.Treemap?
The TreeMap in Java is used to implement Map interface
and NavigableMap along with the AbstractMap Class. The
map is sorted according to the natural ordering of its keys, or by
a Comparator provided at map creation time, depending on
which constructor is used.
5.Threads in java
A Thread is a very light-weighted process, or we can say the
smallest part of the process that allows a program to operate
more efficiently by running multiple tasks simultaneously.
Platform Indepemndence
The meaning of platform-independent is that the java
compiled code(byte code) can run on all operating
systems. A program is written in a language that is a
human-readable language. It may contain words, phrases, etc
which the machine does not understand.
TOP
6. D/B String buffer and StringBuilder
StringBuffer StringBuilder
ArrayList LinkedList
TOP
TOP
1.Namespace std
In C++, a namespace is a collection of related names or
identifiers (functions, class, variables) which helps to separate
these identifiers from similar identifiers in other namespaces or
the global namespace. The identifiers of the C++ standard
library are defined in a namespace called std .
TOP
4. D/B Pointer and Reference variable ?
● References are used to refer an existing variable in
another name whereas pointers are used to store address
of variable.
● References cannot have a null value assigned but pointer
can.
● A reference variable can be referenced by pass by value
whereas a pointer can be referenced by pass by reference.
● A reference must be initialized on declaration while it is not
necessary in case of pointer.
TOP
6. D/B Map And unordered_map
Map Unordered_map
map is define in #include <map> unordered_map is defined in
header file #include <unordered_map>
header file
It is implemented by red-black It is implemented using hash
tree. table.
It is slow. It is fast.
Time complexity for operations is Time complexity for operations is
O(log N) O(1)
TOP
1.What is Object-Oriented programming?
TOP
Inheritance - When one object acquires all the properties
and behaviours odf a parent object it is know as inheritance. It
provide code reusability. It is used to achieve runtime
polymorphoism.
Types of Inheritance -
Multi-level inheritance - In
this inheritance, a derived class is
created from another derived class.
TOP
Polymorphism - Polymorphism is a method of performing “
a single task in different ways”. Polymorphism enable a
programmer to use method or operator in different way. In java
we use method overloading and overriding to obtain
polymorphism.
Types of polymorphism -
TOP
D/B Class & Object
Class Object
A class is a logical entity. An object is a physical entity.
It is conceptual It is real
It binds data & method It is just like a variable of class
together into a single unit
It does not occupy space in Its occupy space in memory
memory
It is a data type that represent It is an instance of the class
the blueprint of an object
It use the keyword class when It uses the new keyword to
declared create an object
A class can exist without any Object cannot exist without a
object class
TOP
D/B Abstract Class & Interface
TOP
D/B overloading & Overriding
Overloading Overriding
The process of calling two The process of calling two
method having same name method one in the subclass
with different parameters is and other in the superclass
called overloading having same signature is
called overriding
It is used to increase the Provides a specific
readability of the program implementation of the method
already in the parent class
It is performed within the It involves multiple classes
same class
Parameters must be different Parameters must be same in
in case of overloading case of overriding
Is an example of compile-time It is an example of runtime
polymorphism polymorphism
Static methods can be Overriding does not involve
overloaded static methods.
TOP
Constructor & types
Types -
TOP
Data Abstraction - Data Abstraction is a process of hiding
unwanted or irrelevant details from the end user. It provides a
different view and help in achieving data independence which is
used to enhance the securities of data.
Static Block -
Function Overloading -
TOP
D/b Stack And Queue -
Stack Queue
TOP
D/b Stack And Array -
Stack Array
TOP
TOP
Merge Sort -
What is Database?
A database is an organized collection of data, so that it can be
easily accessed and managed. You can organize data into
tables, rows, columns, and index it to make it easier to find
relevant information.
TOP
Normalization
● Normalization divides the larger table into smaller and links them
using relationships.
Key In DBMS
SQL Join
The SQL Joins clause is used to combine records from two or
more tables in a database. A JOIN is a means for combining
fields from two tables by using values common to each
TOP
Referential Integrity
referential integrity is made up of the combination of a primary
key and a foreign key.
MySQL Subquery
TOP
ACID properties
TOP
ACID Properties -
(1) Atomicity (2) Consistency (3) Isolation (4) Durability
SQL Commands
SQL commands are instructions. It is used to communicate with
the database. It is also used to perform specific tasks,
functions, and queries of data. SQL can perform various tasks
like create a table, add data to tables, drop the table, modify the
table, set permission for users.
TOP
DCL commands are used to grant and take back authority from
any database user. Some Comands-
GRANT REVOKE
TOP
SELECT
DELETE TRUNCATE
The DELETE command is This command is used to
used to delete specified delete all the rows from a
rows(one or more). table.
It is a DML(Data Manipulation it is a DDL(Data Definition
Language) command. Language) command.
DELETE command is slower TRUNCATE command is
than TRUNCATE command. faster than the DELETE
command.
To use Delete you need To use Truncate on a table we
DELETE permission on the need at least ALTER
table. permission on the table.
The delete can be used with Truncate cannot be used with
indexed views. indexed views.
TOP
D/BChar And Varchar
TOP
What is SQL?
SQL is Structured Query Language, which is a computer
language for storing, manipulating and retrieving data stored in
a relational database.
TOP
D/B Drop And Delete Comand
DELETE DROP
TOP
D/B MySQL & NoSQL.
MySql No SQl
SQL databases are classified as NoSQL databases are known as
Relational databases, i.e., non-relational or distributed
RDBMS. database.
SQL databases have a fixed, NoSQL databases don’t have a
pre-defined schema, which pre-defined schema, which
makes the data storage more makes them schema-less and
rigid, static, and restrictive. more flexible.
SQL follows ACID (Atomicity, NoSQL is based on CAP
Consistency, Isolation and (Consistency, Availability, and
Durability) properties for its Partition Tolerance).
operations.
BCNF
TOP
Backtracking
Backtracking is an algorithmic technique whose goal is to use brute
force to find all solutions to a problem. It entails gradually compiling a
set of all possible solutions. Because a problem will have constraints,
solutions that do not meet them will be removed.
Backtracking Algorithm
Backtrack(s)
return false
if is a new solution
backtrack(expand s)
TOP
TOP
Reverse a linked list
class LinkedList {
int data;
Node next;
Node(int d)
{
data = d;
next = null;
}
}
TOP
Find if the cycle is present in LinkedList.
import java.util.*;
public class LinkedList {
static Node head; // head of list
static class Node {
int data;
Node next;
Node(int d)
{
data = d;
next = null;
}
}
static public void push(int new_data)
{
Node new_node = new Node(new_data);
new_node.next = head;
head = new_node;
}
static boolean detectLoop(Node h)
{
HashSet<Node> s = new HashSet<Node>();
while (h != null) {
if (s.contains(h))
return true;
s.add(h);
h = h.next;
}
return false;
}
public static void main(String[] args)
{
LinkedList llist = new LinkedList();
llist.push(20);
llist.push(4);
llist.push(15);
llist.push(10);
llist.head.next.next.next.next = llist.head;
if (detectLoop(head))
System.out.println("Loop found");
else
System.out.println("No Loop");
}
}
TOP
Sort array based on the frequency
METHOD (Use Hashing and Sorting) Using a hashing
mechanism, we can store the elements (also the first index)
and their counts in a hash. Finally, sort the hash elements
according to their counts.
class GFG {
static Integer[] arr = { 2, 5, 2, 8, 5, 6, 8, 8 };
public static void main(String[] args)
{
List<Integer> list = Arrays.asList(arr);
sortBasedOnFrequencyAndValue(list);
}
public static void
sortBasedOnFrequencyAndValue(List<Integer> list)
{
int n = arr.length;
final HashMap<Integer, Integer> mapCount
= new HashMap<Integer, Integer>();
final HashMap<Integer, Integer> mapIndex
= new HashMap<Integer, Integer>();
for (int i = 0; i < n; i++) {
if (mapCount.containsKey(arr[i])) {
mapCount.put(arr[i],
mapCount.get(arr[i]) + 1);
}
else {
mapCount.put(arr[i],1);
mapIndex.put(arr[i],i);
}
Collections.sort(list, new Comparator<Integer>() {
public int compare(Integer n1, Integer n2)
{
int freq1 = mapCount.get(n1);
int freq2 = mapCount.get(n2);
if (freq1 != freq2) {
return freq2 - freq1;
}
else {
return mapIndex.get(n1)
- mapIndex.get(
n2);
}
}
});
System.out.println(list);
}
}
Output - 8 8 8 2 2 5 5 6 -1 9999999
TOP
Sort an array by characters.
Method : By using the sort() method 2A By using the sort()
method- natural sorting
Procedure: The main logic is to toCharArray() method of the
String class over the input string to create a character array for
the input string. Now use Arrays.sort(char c[]) method to sort
character array. Use the String class constructor to create a
sorted string from a char array.
import java.util.Arrays;
public class GFG {
public static String sortString(String inputString)
{
char tempArray[] = inputString.toCharArray();
Arrays.sort(tempArray);
return new String(tempArray);
}
public static void main(String[] args)
{
String inputString = "geeksforgeeks";
String outputString = sortString(inputString);
System.out.println("Input String : " + inputString);
System.out.println("Output String : "
+ outputString);
}
}
TOP
find its first non-repeating character
Method #1: HashMap and Two-string method traversals.
class GFG {
static final int NO_OF_CHARS = 256;
static char count[] = new char[NO_OF_CHARS];
static void getCharCountArray(String str)
{
for (int i = 0; i < str.length(); i++)
count[str.charAt(i)]++;
}
static int firstNonRepeating(String str)
{
getCharCountArray(str);
int index = -1, i;
return index;
}
public static void main(String[] args)
{
String str = "geeksforgeeks";
int index = firstNonRepeating(str);
System.out.println(
index == -1
? "Either all characters are repeating or string "
+ "is empty"
: "First non-repeating character is "
+ str.charAt(index));
}
}
class GFG {
public static int kthSmallest(Integer[] arr, int K)
{
Arrays.sort(arr);
return arr[K - 1];
}
public static void main(String[] args)
{
Integer arr[] = new Integer[] { 12, 3, 5, 7, 19 };
int K = 2;
System.out.print("K'th smallest element is "
+ kthSmallest(arr, K));
}
}
Intro -
Q2. How long are you planning to work for Infosys, is it for a short
duration?
No , it's not like that , As a fresher I want to work on at least 2-3 client
project in Infosys so that it will be beneficial for my career growth.
Q3 . Any plans for higher studies?
TOP
Project -
If you are mainly your story public anyone can access it and
give there suggestions about how they were able to overcome
that same thing as well as a professional will be watching and
giving their advices too
Now if you that story contains any private details or you dont
want anyone to read that you can make it private
TOP