Interview Questionss
Interview Questionss
Most Important
Interview Questions
for
“Campus Placement”
Applicable for: CSE, IT, ECE, AEIE, CSBS, AIML.
Compiled by:
*Selected for: Cognizant- GenC Pro, GS Lab- JDS, Kiwi InfoTech- SE.
What is C language?
C is a mid-level and procedural programming language. The Procedural programming language is
also known as the structured programming language is a technique in which large programs are
broken down into smaller modules, and each module uses structured code. This technique minimizes
error and misinterpretation. More details.
o Simple: C is a simple language because it follows the structured approach, i.e., a program is
broken into parts
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
o Portable: C is highly portable means that once the program is written can be run on any
machine with little or no modifications.
o Mid Level: C is a mid-level programming language as it combines the low- level language
with the features of the high-level language.
o Structured: C is a structured language as the C program is broken into parts.
o Fast Speed: C language is very fast as it uses a powerful set of data types and operators.
o Memory Management: C provides an inbuilt memory function that saves the memory and
improves the efficiency of our program.
o Extensible: C is an extensible language as it can adopt new features in the future.
scanf(): The scanf() function is used to take input from the user.
What is the difference between the local variable and global variable in C?
Following are the differences between a local variable and global variable:
Declaration A variable which is declared inside function or A variable which is declared outside
block is known as a local variable. function or block is known as a global
variable.
Scope The scope of a variable is available within a The scope of a variable is available
function in which they are declared. throughout the program.
Access Variables can be accessed only by those Any statement in the entire program can
statements inside a function in which they are access variables.
declared.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
Life Life of a variable is created when the function Life of a variable exists until the program
block is entered and destroyed on its exit. is executing.
Storage Variables are stored in a stack unless The compiler decides the storage
specified. location of a variable.
o A variable which is declared as static is known as a static variable. The static variable retains
its value between multiple function calls.
o Static variables are used because the scope of the static variable is available in the entire
program. So, we can access a static variable anywhere in the program.
o The static variable is initially initialized to zero. If we update the value of a variable, then the
updated value is assigned.
o The static variable is used as a common value which is shared by all the methods.
o The static variable is initialized only once in the memory heap to reduce the memory usage.
o C functions are used to avoid the rewriting the same code again and again in our program.
o C functions can be called any number of times from any place of our program.
o When a program is divided into functions, then any part of our program can easily be tracked.
o C functions provide the reusability concept, i.e., it breaks the big task into smaller tasks so
that it makes the C program more understandable.
Description When a copy of the value is passed to the function, then When a copy of the value is passed to
the original value is not modified. then the original value is modified.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
Memory Actual arguments and formal arguments are created in Actual arguments and formal argument
location separate memory locations. in the same memory location.
Safety In this case, actual arguments remain safe as they In this case, actual arguments are not rel
cannot be modified. are modified.
Arguments The copies of the actual arguments are passed to the The addresses of actual arguments are pa
formal arguments. respective formal arguments.
What is recursion in C?
When a function calls itself, and this process is known as recursion. The function that calls itself is
known as a recursive function.
1. Winding phase
2. Unwinding phase
Winding phase: When the recursive function calls itself, and this phase ends when the condition is
reached.
Unwinding phase: Unwinding phase starts when the condition is reached, and the control returns
to the original call.
What is an array in C?
An Array is a group of similar types of elements. It has a contiguous memory location. It makes the
code optimized, easy to traverse and easy to sort. The size and type of arrays cannot be changed
after its declaration.
o One-dimensional array: One-dimensional array is an array that stores the elements one after
the another.
o Multidimensional array: Multidimensional array is an array that contains more than one
array.
What is a pointer in C?
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
A pointer is a variable that refers to the address of a value. It makes the code optimized and makes
the performance fast. Whenever a variable is declared inside a program, then the system allocates
some memory to a variable. The memory contains some address number. The variables that hold
this address number is known as the pointer variable.
o Accessing array elements: Pointers are used in traversing through an array of integers and
strings. The string is an array of characters which is terminated by a null character '\0'.
o Dynamic memory allocation: Pointers are used in allocation and deallocation of memory
during the execution of a program.
o Call by Reference: The pointers are used to pass a reference of a variable to other function.
o Data Structures like a tree, graph, linked list, etc.: The pointers are used to construct
different data structures like tree, graph, linked list, etc.
o If a pointer is pointing any memory location, but meanwhile another pointer deletes the
memory occupied by the first pointer while the first pointer still points to that memory
location, the first pointer will be known as a dangling pointer. This problem is known as a
dangling pointer problem.
o Dangling pointer arises when an object is deleted without modifying the value of the pointer.
The pointer points to the deallocated memory.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
o In case of static memory allocation, memory is allocated at compile time, and memory can't
be increased while executing the program. It is used in the array.
o The lifetime of a variable in static memory is the lifetime of a program.
o The static memory is allocated using static keyword.
o The static memory is implemented using stacks or heap.
o The pointer is required to access the variable present in the static memory.
o The static memory is faster than dynamic memory.
o In static memory, more memory space is required to store the variable.
o In case of dynamic memory allocation, memory is allocated at runtime and memory can be
increased while executing the program. It is used in the linked list.
o The malloc() or calloc() function is required to allocate the memory at the runtime.
o An allocation or deallocation of memory is done at the execution time of a program.
o No dynamic pointers are required to access the memory.
o The dynamic memory is implemented using data segments.
o Less memory space is required to store the variable.
1. malloc()
o The malloc() function is used to allocate the memory during the execution of the
program.
o It does not initialize the memory but carries the garbage value.
o It returns a null pointer if it could not be able to allocate the requested space.
Syntax
2. calloc()
o The calloc() is same as malloc() function, but the difference only is that it initializes the
memory with zero value.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
Syntax
2. realloc()
o The realloc() function is used to reallocate the memory to the new size.
o If sufficient space is not available in the memory, then the new block is allocated to
accommodate the existing data.
Syntax
1. ptr = realloc(ptr, newsize); // updating the memory size using realloc() function.
2. free():The free() function releases the memory allocated by either calloc() or malloc() function.
Syntax
The above syntax releases the memory from a pointer variable ptr.
calloc() malloc()
Description The malloc() function allocates a single block of The calloc() function allocates multipl
requested memory. requested memory.
Initialization It initializes the content of the memory to zero. It does not initialize the content of m
carries the garbage value.
Return value It returns a pointer pointing to the allocated It returns a pointer pointing to the allocat
memory.
o The structure is a user-defined data type that allows storing multiple types of data in a single
unit. It occupies the sum of the memory of all members.
o The structure members can be accessed only through structure variables.
o Structure variables accessing the same structure but the memory allocated for each variable
will be different.
What is a union?
o The union is a user-defined data type that allows storing multiple types of data in a single
unit. However, it doesn't occupy the sum of the memory of all members. It holds the memory
of the largest member only.
o In union, we can access only one variable at a time as it allocates one common space for all
the members of a union.
But, if we use #define, we can compile and run a C program without using the main() function. For
example:
1. #include<stdio.h>
2. #define start main
3. void start() {
4. printf("Hello");
5. }
The argument passed to the main() function while executing the program is known as command line
argument. For example:
The getche() function reads a single character from the keyword, but data is displayed on the output
screen. Press Alt+f5 to see the entered character.
What is typecasting?
The typecasting is a process of converting one data type into another is known as typecasting. If we
want to store the floating type value to an int type, then we will convert the data type into another
data type explicitly.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
Linear Data Structure: A data structure is called linear if all of its elements are arranged in the
sequential order. In linear data structures, the elements are stored in a non-hierarchical way where
each item has the successors and predecessors except the first and last element.Difference between
JDK, JRE, and JVM
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
Non-Linear Data Structure: The Non-linear data structure does not form a sequence i.e. each item
or element is connected with two or more other items in a non-linear arrangement. The data
elements are not arranged in the sequential structure.
o Compiler Design,
o Operating System,
o Database Management System,
o Statistical analysis package,
o Numerical Analysis,
o Graphics,
o Artificial Intelligence,
o Simulation
The main difference between file structure and storage structure is based on memory area that is
being accessed.
Storage structure: It is the representation of the data structure in the computer memory.
File structure: It is the representation of the storage structure in the auxiliary memory.
5) List the data structures which are used in RDBMS, Network Data Modal,
and Hierarchical Data Model.
7) What is a Stack?
Stack is an ordered list in which, insertion and deletion can be performed only at one end that is
called the top. It is a recursive data structure having pointer to its top element. The stack is
sometimes called as Last-In-First-Out (LIFO) list i.e. the element which is inserted first in the stack
will be deleted last from the stack.
8) List the area of applications where stack data structure can be used?
o Expression evaluation
o Backtracking
o Memory Management
o Function calling and return
o Push Operations
o Pop Operations
o Peek Operations
PUSH: PUSH specifies that data is being "inserted" into the stack.
POP: POP specifies data retrieval. It means that data is being deleted from the stack.
12) Write the steps involved in the insertion and deletion of an element in
the stack.
Push:
o Increment the variable top so that it can refer to the next memory allocation
o Copy the item to the at the array index value equal to the top
o Repeat step 1 and 2 until stack overflows
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
Pop:
16)What is an array?
Arrays are defined as the collection of similar types of data items stored at contiguous memory
locations. It is the simplest data structure in which each data element can be randomly accessed by
using its index number.
The multidimensional array can be defined as the array of arrays in which, the data is stored in tabular
form consists of rows and columns. 2D arrays are created to implement a relational database
lookalike data structure. It provides ease of holding the bulk of data at once which can be passed to
any number of functions wherever required.
19) How are the elements of a 2D array are stored in the memory?
There are two techniques by using which, the elements of a 2D array can be stored in the memory.
o Row-Major Order: In row-major ordering, all the rows of the 2D array are stored into the
memory contiguously. First, the 1st row of the array is stored into the memory completely,
then the 2nd row of the array is stored into the memory completely and so on till the last
row.
o Column-Major Order: In column-major ordering, all the columns of the 2D array are stored
into the memory contiguously. first, the 1st column of the array is stored into the memory
completely, then the 2nd row of the array is stored into the memory completely and so on till
the last column of the array.
Address(a[i][j]) = B. A. + (i * n + j) * size
Column-Major Order: If array is declared as a[m][n] where m is the number of rows while n is the
number of columns, then address of an element a[i][j] of the array stored in column major order is
calculated as
o The size of a linked list can be incremented at runtime which is impossible in the case of the
array.
o The List is not required to be contiguously present in the main memory, if the contiguous
space is not available, the nodes can be stored anywhere in the memory connected through
the links.
o The List is dynamically stored in the main memory and grows as per the program demand
while the array is statically stored in the main memory, size of which must be declared at
compile time.
o The number of elements in the linked list are limited to the available memory space while the
number of elements in the array is limited to the size of an array.
25) If you are using C language to implement the heterogeneous linked list,
what pointer type should be used?
The heterogeneous linked list contains different data types, so it is not possible to use ordinary
pointers for this. For this purpose, you have to use a generic pointer type like void pointer because
the void pointer is capable of storing a pointer to any type.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
o node data
o pointer to the next node in sequence (next pointer)
o pointer to the previous node (previous pointer).
o Queues are widely used as waiting lists for a single shared resource like a printer, disk, CPU.
o Queues are used in the asynchronous transfer of data (where data is not being transferred at
the same rate between two processes) for eg. pipes, file IO, sockets.
o Queues are used as buffers in most of the applications like MP3 media player, CD player, etc.
o Queues are used to maintain the playlist in media players to add and remove the songs from
the play-list.
o Queues are used in operating systems for handling interrupts.
o Memory Wastage: The space of the array, which is used to store queue elements, can never
be reused to store the elements of that queue because the elements can only be inserted at
front end and the value of front might be so high so that, all the space before that, can never
be filled.
o Array Size: There might be situations in which, we may need to extend the queue to insert
more elements if we use an array to implement queue, It will almost be impossible to extend
the array size, therefore deciding the correct array size is always a problem in array
implementation of queue.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
31) What are the scenarios in which an element can be inserted into the
circular queue?
o If (rear + 1)%maxsize = front, the queue is full. In that case, overflow occurs and therefore,
insertion can not be performed in the queue.
o If rear != max - 1, the rear will be incremented to the mod(maxsize) and the new value will be
inserted at the rear end of the queue.
o If front != 0 and rear = max - 1, it means that queue is not full therefore, set the value of rear
to 0 and insert the new element there.
33) What is the minimum number of queues that can be used to implement
a priority queue?
Two queues are needed. One queue is used to store the data elements, and another is used for
storing priorities.
o General Tree
o Forests
o Binary Tree
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
39) Which data structure suits the most in the tree construction?
Queue data structure
40) Which data structure suits the most in the tree construction?
Queue data structure
43) How can AVL Tree be useful in all the operations as compared to
Binary search tree?
AVL tree controls the height of the binary search tree by not letting it be skewed. The time taken for
all operations in a binary search tree of height h is O(h). However, it can be extended to O(n) if the
BST becomes skewed (i.e. worst case). By limiting this height to log n, AVL tree imposes an upper
bound on each operation to be O(log n) where n is the number of nodes.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
A B tree of order m contains all the properties of an M way tree. In addition, it contains the following
properties.
SN B Tree B+ Tree
1 Search keys cannot repeatedly be stored. Redundant search keys can be present.
2 Data can be stored in leaf nodes as well as Data can only be stored on the leaf nodes.
internal nodes
3 Searching for some data is a slower process Searching is comparatively faster as data
since data can be found on internal nodes as can only be found on the leaf nodes.
well as on the leaf nodes.
5 Leaf nodes cannot be linked together. Leaf nodes are linked together to make
the search operations more efficient.
A graph G can be defined as an ordered set G(V, E) where V(G) represents the set of vertices and
E(G) represents the set of edges which are used to connect these vertices. A graph can be seen as a
cyclic tree, where the vertices (Nodes) maintain any complex relationship among them instead of
having parent-child relations.
o Path: A Path is the sequence of adjacent vertices connected by the edges with no restrictions.
o Cycle: A Cycle can be defined as the closed path where the initial vertex is identical to the
end vertex. Any vertex in the path can not be visited twice
o Circuit: A Circuit can be defined as the closed path where the intial vertex is identical to the
end vertex. Any vertex may be repeated.
49) Mention the data structures which are used in graph implementation.
For the graph implementation, following data structures are used.
50) Which data structures are used in BFS and DFS algorithm?
Graphs are used in circuit networks where points of connection are drawn as vertices and component
wires become the edges of the graph.
o Graphs are used in transport networks where stations are drawn as vertices and routes
become the edges of the graph.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
o Graphs are used in maps that draw cities/states/regions as vertices and adjacency relations
as edges.
o Graphs are used in program flow analysis where procedures or modules are treated as vertices
and calls to these procedures are drawn as edges of the graph.
52) What are the advantages of Binary search over linear search?
There are relatively less number of comparisons in binary search than that in linear search. In average
case, linear search takes O(n) time to search a list of n elements while Binary search takes O(log n)
time to search a list of n elements.
o Sparse matrix,
o Index generation.
1) What is Java?
Java is the high-level, object-oriented, robust, secure programming language, platform-
independent, high performance, Multithreaded, and portable programming language. It was
developed by James Gosling in June 1991. It can also be known as the platform as it provides its
own JRE and API.
29.9M
605
HTML Tutorial
Mainly used for C++ is mainly used for system Java is mainly used for application
programming. programming. It is widely used in window,
web-based, enterprise and mobile
applications.
Design Goal C++ was designed for systems and Java was designed and created as an
applications programming. It was interpreter for printing systems but later
an extension of C programming extended as a support network computing.
language. It was designed with a goal of being easy to
use and accessible to a broader audience.
Goto C++ supports the goto statement. Java doesn't support the goto statement.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
Pointers C++ supports pointers. You can Java supports pointer internally. However,
write pointer program in C++. you can't write the pointer program in java.
It means java has restricted pointer support
in Java.
Compiler and C++ uses compiler only. C++ is Java uses compiler and interpreter both.
Interpreter compiled and run using the Java source code is converted into bytecode
compiler which converts source at compilation time. The interpreter
code into machine code so, C++ is executes this bytecode at runtime and
platform dependent. produces output. Java is interpreted that is
why it is platform independent.
Call by Value and C++ supports both call by value Java supports call by value only. There is no
Call by reference and call by reference. call by reference in java.
Structure and C++ supports structures and Java doesn't support structures and unions.
Union unions.
Thread Support C++ doesn't have built-in support Java has built-in thread support.
for threads. It relies on third-party
libraries for thread support.
Virtual Keyword C++ supports virtual keyword so Java has no virtual keyword. We can override
that we can decide whether or not all non-static methods by default. In other
override a function. words, non-static methods are virtual by
default.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
unsigned right C++ doesn't support >>> Java supports unsigned right shift >>>
shift >>> operator. operator that fills zero at the top for the
negative numbers. For positive numbers, it
works same like >> operator.
Inheritance Tree C++ creates a new inheritance tree Java uses a single inheritance tree always
always. because all classes are the child of Object
class in java. The object class is the root of
the inheritance tree in java.
o Simple: Java is easy to learn. The syntax of Java is based on C++ which makes easier to write the
program in it.
o Object-Oriented: Java follows the object-oriented paradigm which allows us to maintain our code as
the combination of different type of objects that incorporates both data and behavior.
o Portable: Java supports read-once-write-anywhere approach. We can execute the Java program on
every machine. Java program (.java) is converted to bytecode (.class) which can be easily run on every
machine.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
with its platform on which its code is executed. Java doesn't depend upon the operating system to be
executed.
o Secured: Java is secured because it doesn't use explicit pointers. Java also provides the concept of
ByteCode and Exception handling which makes it more secured.
o Robust: Java is a strong programming language as it uses strong memory management. The concepts
like Automatic garbage collection, Exception handling, etc. make it more robust.
o Architecture Neutral: Java is architectural neutral as it is not dependent on the architecture. In C, the
size of data types may vary according to the architecture (32 bit or 64 bit) which doesn't exist in Java.
o Interpreted: Java uses the Just-in-time (JIT) interpreter along with the compiler for the program
execution.
o High Performance: Java is faster than other traditional interpreted programming languages because
Java bytecode is "close" to native code. It is still a little bit slower than a compiled language (e.g., C++).
o Multithreaded: We can write Java programs that deal with many tasks at once by defining multiple
threads. The main advantage of multi-threading is that it doesn't occupy memory for each thread. It
shares a common memory area. Threads are important for multi-media, Web applications, etc.
o Distributed: Java is distributed because it facilitates users to create distributed applications in Java.
RMI and EJB are used for creating distributed applications. This feature of Java makes us able to access
files by calling the methods from any machine on the internet.
o Dynamic: Java is a dynamic language. It supports dynamic loading of classes. It means classes are
loaded on demand. It also supports functions from its native languages, i.e., C and C++.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
JVM is an acronym for Java Virtual Machine; it is an abstract machine which provides the runtime
environment in which Java bytecode can be executed. It is a specification which specifies the working
of Java Virtual Machine. Its implementation has been provided by Oracle and other companies. Its
implementation is known as JRE.
JVMs are available for many hardware and software platforms (so JVM is platform dependent). It is
a runtime instance which is created when we run the Java class. There are three notions of the JVM:
specification, implementation, and instance.
JRE
JRE stands for Java Runtime Environment. It is the implementation of JVM. The Java Runtime
Environment is a set of software tools which are used for developing Java applications. It is used to
provide the runtime environment. It is the implementation of JVM. It physically exists. It contains a
set of libraries + other files that JVM uses at runtime.
JDK
JDK is an acronym for Java Development Kit. It is a software development environment which is used
to develop Java applications and applets. It physically exists. It contains JRE + development tools.
JDK is an implementation of any one of the below given Java Platforms released by Oracle
Corporation:
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
Many types:
1. Class(Method) Area: Class Area stores per-class structures such as the runtime constant pool, field,
method data, and the code for methods.
2. Heap: It is the runtime data area in which the memory is allocated to the objects
3. Stack: Java Stack stores frames. It holds local variables and partial results, and plays a part in method
invocation and return. Each thread has a private JVM stack, created at the same time as the thread. A
new frame is created each time a method is invoked. A frame is destroyed when its method invocation
completes.
4. Program Counter Register: PC (program counter) register contains the address of the Java virtual
machine instruction currently being executed.
5. Native Method Stack: It contains all the native methods used in the application.
9) What are the main differences between the Java platform and other
platforms?
There are the following differences between the Java platform and other platforms.
o Java is the software-based platform whereas other platforms may be the hardware platforms or
software-based platforms.
o Java is executed on the top of other hardware platforms whereas other platforms can only have the
hardware components.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
10) What gives Java its 'write once and run anywhere' nature?
The bytecode. Java compiler converts the Java programs into the class file (Byte Code) which is the
intermediate language between source code and machine code. This bytecode is not platform
specific and can be executed on any computer.
1. Bootstrap ClassLoader: This is the first classloader which is the superclass of Extension classloader. It
loads the rt.jar file which contains all class files of Java Standard Edition like java.lang package classes,
java.net package classes, java.util package classes, java.io package classes, java.sql package classes,
etc.
2. Extension ClassLoader: This is the child classloader of Bootstrap and parent classloader of System
classloader. It loads the jar files located inside $JAVA_HOME/jre/lib/ext directory.
3. System/Application ClassLoader: This is the child classloader of Extension classloader. It loads the
class files from the classpath. By default, the classpath is set to the current directory. You can change
the classpath using "-cp" or "-classpath" switch. It is also known as Application classloader.
14) If I don't provide any arguments on the command line, then what will
the value stored in the String array passed into the main() method, empty
or NULL?
It is empty, but not null.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
15) What if I write static public void instead of public static void?
The program compiles and runs correctly because the order of specifiers doesn't matter in Java.
o Public The classes, methods, or variables which are defined as public, can be accessed by any class or
method.
o Protected Protected can be accessed by the class of the same package, or by the sub-class of this
class, or within the same class.
o Default Default are accessible within the package only. By default, all the classes, methods, and
variables are of default scope.
o Private The private class, methods, or variables defined as private can be accessed within the class
only.
For example, In the class simulating the collection of the students in a college, the name of the
college is the common attribute to all the students. Therefore, the college name will be defined
as static.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
o Object-oriented languages follow all the concepts of OOPs whereas, the object-based language
doesn't follow all the concepts of OOPs like inheritance and polymorphism.
o Object-oriented languages do not have the inbuilt objects whereas Object-based languages have the
inbuilt objects, for example, JavaScript has window object.
o Examples of object-oriented programming are Java, C#, Smalltalk, etc. whereas the examples of
object-based languages are JavaScript, VBScript, etc.
26) What will be the initial value of an object reference which is defined as
an instance variable?
All object references are initialized to null in Java.
o Default Constructor: default constructor is the one which does not accept any value. The default
constructor is mainly used to initialize the instance variable with the default values. It can also be used
for performing some useful task on object creation. A default constructor is invoked implicitly by the
compiler if there is no constructor defined in the class.
o Parameterized Constructor: The parameterized constructor is the one which can initialize the
instance variables with the given values. In other words, we can say that the constructors which can
accept the arguments are called parameterized constructors.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
There are many ways to copy the values of one object into another in java. They are:
o By constructor
o By assigning the values of one object into another
o By clone() method of Object class
In this example, we are going to copy the values of one object into another using java constructor.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
35) What are the differences between the constructors and methods?
There are many differences between constructors and methods. They are given below.
A constructor is used to initialize the state of an object. A method is used to expose the behavior
of an object.
A constructor must not have a return type. A method must have a return type.
The Java compiler provides a default constructor if you don't The method is not provided by the
have any constructor in a class. compiler in any case.
The constructor name must be same as the class name. The method name may or may not be
same as class name.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
41) What are the restrictions that are applied to the Java static methods?
Two main restrictions are applied to the static methods.
o The static method can not use non-static data member or call the non-static method directly.
o this and super cannot be used in static context as they are non-static.
46) What if the static modifier is removed from the signature of the main
method?
Program compiles. However, at runtime, It throws an error "NoSuchMethodError."
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
47) What is the difference between static (class) method and instance
method?
1)A method that is declared as static is known as the static A method that is not declared as static
method. is known as the instance method.
2)We don't need to create the objects to call the static methods. The object is required to call the
instance methods.
3)Non-static (instance) members cannot be accessed in the Static and non-static variables both
static context (static method, static block, and static nested class) can be accessed in instance methods.
directly.
4)For example: public static int cube(int n){ return n*n*n;} For example: public void msg(){...}.
50) Can we declare the static variables and methods in an abstract class?
Yes, we can declare static variables and methods in an abstract method. As we know that there is no
requirement to make the object to access the static context, therefore, we can access the static
context declared inside the abstract class by using the name of the abstract class. Consider the
following example.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
variables through objects, therefore, it is not the best practice to use this to refer static members.
Consider the following example.
56) What are the advantages of passing this into a method instead of the
current class object itself?
As we know, that this refers to the current class object, therefore, it must be similar to the current
class object. However, there can be two main advantages of passing this into a method instead of
the current class object.
o this is a final variable. Therefore, this cannot be assigned to any new value whereas the current class
object might not be final and can be changed.
o this can be used in the synchronized block.
o Single-level inheritance
o Multi-level inheritance
o Multiple Inheritance
o Hierarchical Inheritance
o Hybrid Inheritance
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
o Inheritance provides code reusability. The derived class does not need to redefine the method of base
class unless it needs to provide the specific implementation of the method.
o Runtime polymorphism cannot be achieved without using inheritance.
o We can simulate the inheritance of classes with the real-time objects which makes OOPs more realistic.
o Inheritance provides data hiding. The base class can hide some data from the derived class by making
it private.
o Method overriding cannot be achieved without inheritance. By method overriding, we can give a
specific implementation of some basic method contained by the base class.
Since the compile-time errors are better than runtime errors, Java renders compile-time error if you
inherit 2 classes. So whether you have the same method or different, there will be a compile time
error.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
o super can be used to refer to the immediate parent class instance variable.
o super can be used to invoke the immediate parent class method.
o super() can be used to invoke immediate parent class constructor.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
68) What are the differences between this and super keyword?
There are the following differences between this and super keyword.
o The super keyword always points to the parent class contexts whereas this keyword always points to
the current class context.
o The super keyword is primarily used for initializing the base class variables within the derived class
constructor whereas this keyword primarily used to differentiate between local and instance variables
when passed in the class constructor.
o The super and this must be the first statement inside constructor otherwise the compiler will throw an
error.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
Method overloading increases the readability of the program. Method overloading is performed to
figure out the program quickly.
73) Why is method overloading not possible by changing the return type in
java?
In Java, method overloading is not possible by changing the return type of the program due to avoid
the ambiguity.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
As displayed in the above diagram, the byte can be promoted to short, int, long, float or double. The
short datatype can be promoted to int, long, float or double. The char datatype can be promoted to
int, long, float or double and so on. Consider the following example.
o The method must have the same name as in the parent class.
o The method must have the same signature as in the parent class.
o Two classes must have an IS-A relationship between them.
More Details.
No, you can't override the static method because they are the part of the class, not the object.
1) Method overloading increases the Method overriding provides the specific implementation of
readability of the program. the method that is already provided by its superclass.
2) Method overloading occurs within Method overriding occurs in two classes that have IS-A
the class. relationship between them.
3) In this case, the parameters must In this case, the parameters must be the same.
be different.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
84) Can we change the scope of the overridden method in the subclass?
Yes, we can change the scope of the overridden method in the subclass. However, we must notice
that we cannot decrease the accessibility of the method. The following point must be taken care of
while changing the accessibility of the method.
85) Can we modify the throws clause of the superclass method while
overriding it in the subclass?
Yes, we can modify the throws clause of the superclass method while overriding it in the subclass.
However, there are some rules which are to be followed while overriding in case of exception
handling.
o If the superclass method does not declare an exception, subclass overridden method cannot declare
the checked exception, but it can declare the unchecked exception.
o If the superclass method declares an exception, subclass overridden method can declare same,
subclass exception or no exception but cannot declare parent exception.
Now, since java5, it is possible to override any method by changing the return type if the
return type of the subclass overriding method is subclass type. It is known as covariant
return type. The covariant return type specifies that the return type may vary in the same
direction as the subclass.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
No, we cannot declare an interface as final because the interface must be implemented by some
class to provide its definition. Therefore, there is no sense to make an interface final. However, if you
try to do so, the compiler will show an error.
100) What is the difference between the final method and abstract method?
The main difference between the final method and abstract method is that the abstract method
cannot be final as we need to override them in the subclass to give its definition.
1) What is DBMS?
DBMS is a collection of programs that facilitates users to create and maintain a database. In other
words, DBMS provides us an interface or tool for performing different operations such as the
creation of a database, inserting data into it, deleting data from it, updating the data, etc. DBMS is
a software in which data is stored in a more secure way as compared to the file-based system. Using
DBMS, we can overcome many problems such as- data redundancy, data inconsistency, easy access,
more organized and understandable, and so on. There is the name of some popular Database
Management System- MySQL, Oracle, SQL Server, Amazon simple DB (Cloud-based), etc.
2) What is a database?
A Database is a logical, consistent and organized collection of data that it can easily be accessed,
managed and updated. Databases, also known as electronic databases are structured to provide the
facility of creation, insertion, updating of the data efficiently and are stored in the form of a file or
set of files, on the magnetic disk, tapes and another sort of secondary devices. Database mostly
consists of the objects (tables), and tables include of the records and fields. Fields are the basic units
of data storage, which contain the information about a particular aspect or attribute of the entity
described by the database. DBMS is used for extraction of data from the database in the form of the
queries.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
The collection of database and DBMS software together is known as a database system. Through
the database system, we can perform many activities such as-
The data can be stored in the database with ease, and there are no issues of data redundancy and
data inconsistency.
The data will be extracted from the database using DBMS software whenever required. So, the
combination of database and DBMS software enables one to store, retrieve and access data with
considerate accuracy and security.
o Redundancy control
o Restriction for unauthorized access
o Provides multiple user interfaces
o Provides backup and recovery
o Enforces integrity constraints
o Ensure data consistency
o Easy accessibility
o Easy data extraction and data processing due to the use of queries
There are two ways which can help the DBMS in recovering and maintaining the ACID properties,
and they are- maintaining the log of each transaction and maintaining shadow pages. So, when it
comes to log based recovery system, checkpoints come into existence. Checkpoints are those points
to which the database engine can recover after a crash as a specified minimal point from where the
transaction log record can be used to recover all the committed data up to the point of the crash.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
used for the recovery of the database after the system crash. Checkpoints are used in the log-based
recovery system. When due to a system crash we need to restart the system then at that point we
use checkpoints. So that, we don't have to perform the transactions from the very starting.
9) What is RDBMS?
RDBMS stands for Relational Database Management Systems. It is used to maintain the data records
and indices in tables. RDBMS is the form of DBMS which uses the structure to identify and access
data concerning the other piece of data in the database. RDBMS is the system that enables you to
perform different operations such as- update, insert, delete, manipulate and administer a relational
database with minimal difficulties. Most of the time RDBMS use SQL language because it is easily
understandable and is used for often.
o Data Definition Language (DDL) e.g., CREATE, ALTER, DROP, TRUNCATE, RENAME, etc. All these
commands are used for updating the data that?s why they are known as Data Definition Language.
o Data Manipulation Language (DML) e.g., SELECT, UPDATE, INSERT, DELETE, etc. These commands
are used for the manipulation of already updated data that's why they are the part of Data
Manipulation Language.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
o DATA Control Language (DCL) e.g., GRANT and REVOKE. These commands are used for giving and
removing the user access on the database. So, they are the part of Data Control Language.
o Transaction Control Language (TCL) e.g., COMMIT, ROLLBACK, and SAVEPOINT. These are the
commands used for managing transactions in the database. TCL is used for managing the changes
made by DML.
Database language implies the queries that are used for the update, modify and manipulate the
data.
A relation is specified as a set of tuples. A relation is the set of related attributes with identifying key
attributes
Let r be the relation which contains set tuples (t1, t2, t3, ..., tn). Each tuple is an ordered list of n-
values t=(v1,v2, ...., vn).
The degree of relation is a number of attribute of its relation schema. A degree of relation is also
known as Cardinality it is defined as the number of occurrence of one entity which is connected to
the number of occurrence of other entity. There are three degree of relation they are one-to-
one(1:1), one-to-many(1:M), many-to-one(M:M).
One-To-One: Here one record of any object can be related to one record of another object.
One-To-Many (many-to-one): Here one record of any object can be related to many records of
other object and vice versa.
Many-to-many: Here more than one records of an object can be related to n number of records of
another object.
o Inconsistent
o Not secure
o Data redundancy
o Difficult in accessing data
o Data isolation
o Data integrity
o Concurrent access is not possible
o Limited data sharing
o Atomicity problem
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
For example: We know that most of the users prefer those systems which have a simple GUI that
means no complex processing. So, to keep the user tuned and for making the access to the data
easy, it is necessary to do data abstraction. In addition to it, data abstraction divides the system in
different layers to make the work specified and well defined.
Physical level: It is the lowest level of abstraction. It describes how data are stored.
Logical level: It is the next higher level of abstraction. It describes what data are stored in the
database and what the relationship among those data is.
View level: It is the highest level of data abstraction. It describes only part of the entire database.
For example- User interacts with the system using the GUI and fill the required details, but the user
doesn't have any idea how the data is being used. So, the abstraction level is entirely high in VIEW
LEVEL.
Then, the next level is for PROGRAMMERS as in this level the fields and records are visible and the
programmers have the knowledge of this layer. So, the level of abstraction here is a little low in VIEW
LEVEL.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
Procedural DML or Low level DML: It requires a user to specify what data are needed and how to
get those data.
Non-Procedural DML or High level DML:It requires a user to specify what data are needed without
specifying how to get those data.
o select
o project
o set difference
o union
o rename,etc.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
In E-R diagram, entities are represented by rectangles, relationships are represented by diamonds,
attributes are the characteristics of entities and represented by ellipses, and data flow is represented
through a straight line.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
For example: In the employee database of a company, the employee, department, and the
designation can be considered as the entities. These entities have some characteristics which will be
the attributes of the corresponding entity.
For example, a student has student_id, department, and course as its characteristics.
For example: If a student is an entity in the table then age will be the attribute of that student.
Entity Integrity : It specifies that "Primary key cannot have a NULL value."
Referential Integrity: It specifies that "Foreign Key can be either a NULL value or should be the
Primary Key value of other relation
Intension: Intension is also known as Data Schema and defined as the description of the database,
which is specified during database design and is expected to remain unchanged. The Intension is a
constant value that gives the name, structure of tables and the constraints laid on it.
o Research Storage
o System Relational Data System
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
It makes you able to modify the schema definition in one level should not affect the schema
definition in the next higher level.
Physical Data Independence: Physical data is the data stored in the database. It is in the bit-format.
Modification in physical level should not affect the logical level.
For example: If we want to manipulate the data inside any table that should not change the format
of the table.
Logical Data Independence: Logical data in the data about the database. It basically defines the
structure. Such as tables stored in the database. Modification in logical level should not affect the
view level.
For example: If we need to modify the format of any table, that modification should not affect the
data inside it.
Physical level: It is the lowest level of abstraction. It describes how data are stored.
Logical level: It is the next higher level of abstraction. It describes what data are stored in the
database and what relationship among those data.
View level: It is the highest level of data abstraction. It describes only part of the entire database.
For example- User interact with the system using the GUI and fill the required details, but the user
doesn't have any idea how the data is being used. So, the abstraction level is absolutely high in VIEW
LEVEL.
Then, the next level is for PROGRAMMERS as in this level the fields and records are visible and the
programmer has the knowledge of this layer. So, the level of abstraction here is a little low in VIEW
LEVEL.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
o The table is in 1NF, i.e., firstly it is necessary that the table should follow the rules of 1NF.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
o Every non-prime attribute is fully functionally dependent on the primary key, i.e., every non-key
attribute should be dependent on the primary key in such a way that if any key element is deleted,
then even the non_key element will still be saved in the database.
o It is in 3NF.
o For every functional dependency X->Y, X should be the super key of the table. It merely means that X
cannot be a non-prime attribute if Y is a prime attribute.
ATOMICITY: Atomicity is more generally known as ?all or nothing rule.' Which implies all are
considered as one unit, and they either run to completion or not executed at all.
CONSISTENCY: This property refers to the uniformity of the data. Consistency implies that the
database is consistent before and after the transaction.
ISOLATION: This property states that the number of the transaction can be executed concurrently
without leading to the inconsistency of the database state.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
DURABILITY: This property ensures that once the transaction is committed it will be stored in the
non-volatile memory and system crash can also not affect it anymore.
o DELETE command delete only those rows which are specified with the WHERE clause.
o DELETE command can be rolled back.
o DELETE command maintain a log, that's why it is slow.
o DELETE use row lock while performing DELETE function.
TRUNCATE command: TRUNCATE command is used to remove all rows (complete data) from a
table. It is similar to the DELETE command with no WHERE clause.
o The TRUNCATE command removes all the rows from the table.
o The TRUNCATE command cannot be rolled back.
o The TRUNCATE command doesn't maintain a log. That's why it is fast.
o TRUNCATE use table log while performing the TRUNCATE function.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
51) What is the difference between a shared lock and exclusive lock?
Shared lock: Shared lock is required for reading a data item. In the shared lock, many transactions
may hold a lock on the same data item. When more than one transaction is allowed to read the data
items then that is known as the shared lock.
Exclusive lock: When any transaction is about to perform the write operation, then the lock on the
data item is an exclusive lock. Because, if we allow more than one transaction then that will lead to
the inconsistency in the database.
Primary key: The Primary key is an attribute in a table that can uniquely identify each record in a
table. It is compulsory for every table.
Candidate key: The Candidate key is an attribute or set of an attribute which can uniquely identify
a tuple. The Primary key can be selected from these attributes.
Super key: The Super key is a set of attributes which can uniquely identify a tuple. Super key is a
superset of the candidate key.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
Foreign key: The Foreign key is a primary key from one table, which has a relationship with another
table. It acts as a cross-reference between tables.
o Assumption
o Simplification
o Limitation
o Constraints
o Preferences
4) Define Framework.
A framework is the Code Skeleton that can be fleshed out with particular classes or functionality and
designed to address the specific problem at hand.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
o Real projects rarely follow the sequential flow. Iteration always occurs and creates a problem.
o Challenging for the customer to state all requirements.
o The working version of the program is not available. So the customer must have patience.
o The incremental model can be accepted when there is less number of people include in the
project.
o Technical risks can be handle with each increment.
o For a minimal period, at least the core product can be delivered to the user.
1. It is based on user communication. If the interface is not proper, then the software product
which gets created will not be the up to the mark.
2. It demands a vast risk assessment. If the risk assessment is completed correctly, then only the
successful product can be obtained.
o Incremental model
o Spiral model
o WIN-WIN spiral model
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
o Concurrent Development
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
o Establish data boundary between System being implemented and Environment in which
system operates.
o Describes all external producers, external consumers, and entities that communicate through
the customer interface.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
Coupling is the significant measure of the degree to which classes are linked to one another.
Coupling should be kept as low as possible.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
o Unit testing: The individual elements are tested in this type of testing.
o Module testing: Related group of independent items is tested.
o Sub-system testing: This is a type of integration testing. Different modules are integrated
into a sub-system, and the entire subsystem is tested.
o System testing: The entire system is tested in this system.
o Acceptance testing: This type of testing contains testing of the system with user data if the
system behaves as per client need, then it is accepted.
o Alpha test: The alpha testing is attesting in which the customer tests the version of complete
software under the supervision of the developer. This testing is implement at the developer's
site.
o Beta test: The beta testing is a testing in which the customer tests the version of the software
without the developer being present. This testing is performed at the customer's site.
o Code-based testing tools: These tools take source code as input and generate test cases.
o Specialized testing tools: Using this language, the detailed test specification can be written
for each test case.
o Requirement-based testing tools: These tools help in designing as per user requirements.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
Maintenance is described as the process in which changes are implemented by either modifying the
existing system?s architecture or by adding new components to the system.
Corrective Maintenance: It means the maintenance for correcting the software faults.
Perfective maintenance: It means modifying or enhancing the system to meet the new
requirements.
CONTACT @ CS.KAIRI_SRV
COMPUTER SCIENCE & ENGINEERING- ASANSOL ENGINEERING COLLEGE
CONTACT @ CS.KAIRI_SRV