Interview Preparation
OOP Concepts - Object Orientated Programming
OOP is Providing Code Reuse ability with reduce duplication of code and you have to change every where which leads to performance
code can be changed any time so when you want to change it in any application, OOP make it easy
Four main Concepts.
- Polymorphism
- Overloading / Static Binding /Compile Time / Early Binding : Same Methods with Different Properties, methods contain same name but having different Parameters which is compile on run time and shows error while compile time. It is also known as Static Binding or Early Binding.
- Example :
public void result(){} public void result(int numbers){} public void result(String names){}
- Example :
- Overriding / Dynamic Binding /Run Time / Late Binding : child class can implement a parent class method based on its requirement. Overriding means to override the functionality of an existing method.
- Example :
class Animal { public void move() { System.out.println("Animals can move"); } } class Dog extends Animal { public void move() { System.out.println("Dogs can walk and run"); } } public class TestDog { public static void main(String args[]) { Animal a = new Animal(); // Animal reference and object Animal b = new Dog(); // Animal reference but Dog object a.move(); // runs the method in Animal class b.move(); // runs the method in Dog class } }
- Example :
- Overloading / Static Binding /Compile Time / Early Binding : Same Methods with Different Properties, methods contain same name but having different Parameters which is compile on run time and shows error while compile time. It is also known as Static Binding or Early Binding.
- Encapsulation
- Abstraction
- Inheritance
.
OOP Basics - Object Orientated Programming.
Class- A class is a Body for any functional entity which defines its properties and its functions. Like Human Being, having body parts, and performing various actions.
.
Data Types- Primitive Data Type: such as boolean, char, int, short, byte, long, float, and double
- Non-Primitive Data Type or Object Data type: such as String, Array, etc.
.
Basic Programming.
MVC - Model View ControllerThe Model-View-Controller (MVC) is an architectural pattern that separates an application into three main logical components: the model, the view, and the Controller
Using the MVC pattern for websites, requests are routed to a Controller that is responsible for working with the Model to perform actions and/or retrieve data. The Controller chooses the View to display and provides it with the Model. The View renders the final page, based on the data in the Model.
.
Rest full ServicesIn REST Architecture everything is a resource. RESTful web services are light weight, highly scalable and maintainable and are very commonly used to create APIs for web-based applications.
.
HibernateHibernate is a Java framework that simplifies the development of Java application to interact with the database. It is an open source, lightweight, ORM (Object Relational Mapping) tool. Hibernate implements the specifications of JPA (Java Persistence API) for data persistence
.
MavenRepository management framework, it can implement all dependencies through its POM file where we put library name in Dependency Tag
.
SpringSpring is Framework where we can create web applications, Spring is a huge framework where we can develop big applications
we can manage exception handling manually,
we can implement spring Security to secure the app
Its annotation base framework
.
Collections & GenericsList list = new ArrayList(); // before generics list.add(10); list.add("100"); List<Integer> list1 = new ArrayList<Integer>(); // adding generics list1.add(10); list1.add("100"); // compile-time error.
.
Data Structure.
Web Services.
JTDS/JDBC.
Connectivity With DataBase.
GIT Overview.
Agile Overview.
Database Concepts.
Hashing vs Encryption.
Generalization & specializationGeneralization is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass
Specialization converting a super class type into a sub class type is called ‘Specialization‘. Here, we are coming down from more general form to a specific form and hence the scope is narrowed. Hence, this is called narrowing or down-casting.
.
Access / non access ModifiersAccess Modifiers in Java helps to restrict the scope of a class, constructor, variable, method, or data member. There are four types of access modifiers available in java:
- Access: default, public , private , protected .
Non Access Modifiers They are used with classes, methods, variables, constructors etc to provide information about their behavior to JVM
- Non-access: static, final, abstract, synchronized, volatile, transient and native .
.
Multi Threading.
Synchronized and Asynchronize.
For each loop.
Static & Dynamic BindingsDynamic bindings are also known as Overload
Static bindings are also known as Override
.
Generics vs Object ClassThe Generics Object is the superclass of all other classes and Object reference can refer to any type object.
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
.
Aggregation / Composition / AssociationAggregation: In Aggregation, the direction specifies which object contains the other object. There are mutual dependencies among objects.
For example, departments and employees, a department has many employees but a single employee is not associated with multiple departments
Composition: In this type of Aggregation the child object does not have their own life cycle. The child object’s life depends on the parent’s life cycle.
Association: Association in Java is a connection or relation between two separate classes that are set up through their objects.
.
Design Patterns.
Modulus Sign.
List / Array list / Array / Collections.
Data Base Self Join.
Programming Small ProblemsAbout Struts 2 :
it is an MVC Framework.
Give us PreBuilt classes for MVC that we can use / extend.
Structs Main Components :
interceptors = request parameters
Action Class = Business services classes
Structs XML : work like controller, it controls the execution flow of request. it need to map Actions Classes and JSP.
JSP = Tag libraries
Structs TAGs :
<struts> <Package name = "default" namespace = "/anyNameForURL" extends = "struts-default"> <action name= "URL name" class = "Class complete path with package name" method = "someOtherMethod"> <result name = "SucessjSP">/JSPPageCallHere.JSP</result> <result name = "ErrorJSP">/AnotherJSPPageCallHere.JSP</result> </action> </package> </struts> <method> : calls when one class have many methods. Example : http://<server>:<port>/<webapp>/<namespace>/<action.action>
Struts Wild Cards:
use to search action classes when service is hit:
Example: <action name= "URL*" class = "Class complete path with package name"> <result name = "SucessjSP">/JSPPageCallHere.JSP</result> it Hit the action class which is start with URL.
pattern :
to architect the application
framework :
provides you classes and libraries to build an application
spring framework :
spring framework is a enterprise java framework which let you write enterprise java application.
spring boot :
Spring boot is a spring + bootstrap and a quickly startup a spring application which includes its own web server , we can build a complex and end to end applications in spring.
its a huge frame work have a lot of stuff.
spring boot make it easy to create stand alone, production-grade spring based applications that you can “just run”.
end to end :
includes controller,data layer,service layer
Zuul Library :
Zuul is a JVM based router and server side load balance.
rmi :(Remote Method invocation)
works through stub and skeleton.
rmi is an API which allows an object to invoke a method on an object that exists in another address space
mybatis :
MyBatis is a Java persistence framework that couples objects with stored procedures or SQL statements using an XML descriptor or annotations.
JPA : (Java Persistence API)
Java Persistence API is a collection of classes and methods to persistently store the vast amounts of data into a database.
EJB : (Enterprise JavaBeans) / Java Beans
A JavaBean is a Java class
Enterprise Java Beans (EJB) is one of several Java APIs for modular construction of enterprise software. EJB is a server-side software component that encapsulates business logic of an application.
It is a reusable software component. A bean encapsulates many objects into one object so that we can access this object from multiple places.
Serialization/Deserialization
Ajax Types:
have two types.
GET and POST
Is GET Method recieves huge data through request parameter
No, Only POST Method recieves huge data through request parameter
Differentiate between return a Value and a Reference
Differentiate between String and String Buffer ?
String-Buffer is a peer class of String that provides much of the functionality of strings. String represents fixed-length, immutable character sequences while String-Buffer represents grow able and writable character sequences.
Access Modifiers :
Modifier |
Class |
Package |
Subclass |
World |
public |
Y |
Y |
Y |
Y |
protected |
Y |
Y |
Y |
N |
no modifier |
Y |
Y |
N |
N |
private |
Y |
N |
N |
N |
Structured Query Language(SQL) as we all know is the database language by the use of which we can perform certain operations on the existing database and also we can use this language to create a database. SQL uses certain commands like Create, Drop, Insert etc. to carry out the required tasks.
These SQL commands are mainly categorized into four categories as discussed below:
- 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.
- DML(Data Manipulation Language) : 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.
- DCL(Data Control Language) : 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.
Stateless vs Statefull Services
Statefull Web Services
a stateful web service looks like? Let’s say you log into a resource, and in doing so, you pass your password and username. If the web server stores this data in a backend manner and uses it to identify you as a constantly connected client,
Stateless Web Services
you use a variety of stateless services and applications. When you read the news, you are using HTTP to connect in a stateless manner, utilizing messages that can be parsed and worked with in isolation of each other and your state.
If you have Twitter on your phone, you are constantly utilizing a stateless service. When the service requests a list of recent direct messages using the Twitter REST API, it issues the following request:
Soap VS Rest
Soap is statefull
Rest is stateless
Difference between ArrayList and Vector
ArrayList and Vector both implements List interface and maintains insertion order.
However, there are many differences between ArrayList and Vector classes that are given below.
ArrayList | Vector |
---|---|
1) ArrayList is not synchronized. | Vector is synchronized. |
2) ArrayList increments 50% of current array size if the number of elements exceeds from its capacity. | Vector increments 100% means doubles the array size if the total number of elements exceeds than its capacity. |
3) ArrayList is not a legacy class. It is introduced in JDK 1.2. | Vector is a legacy class. |
4) ArrayList is fast because it is non-synchronized. | Vector is slow because it is synchronized, i.e., in a multithreading environment, it holds the other threads in runnable or non-runnable state until current thread releases the lock of the object. |
5) ArrayList uses the Iterator interface to traverse the elements. | A Vector can use the Iterator interface or Enumeration interface to traverse the elements. |
.
How to SUM Numeric value from String/** * * @author Usman Mughal */ public class calculateIntFromString { public static void main(String[] args){ try { String calculateInt = "A1B2C3"; int num1 = Integer.parseInt(calculateInt.substring(1,2)); int num2 = Integer.parseInt(calculateInt.substring(3,4)); int num3 = Integer.parseInt(calculateInt.substring(5,6)); int sum = num1 + num2 + num3; System.out.println("num1 = " + sum); } catch (NumberFormatException e) { e.getMessage(); } } }
.
How to SUM Numeric value from Dynamic String/** * * @author Usman Mughal */ public class calculateIntFromString { public static void main(String[] args){
String calculateInt = "A124B2C355CF85GT5";
int total = 0;
char[] data = calculateInt.toCharArray();
for(int i = 0; i < data.length; i++){
if(Character.isDigit(calculateInt.charAt(i)))
{
String number = "";
number = number + calculateInt.charAt(i);
total = total + Integer.parseInt(number);
}
}
System.out.println("Total number = " + total);
} }
Defference between Constructor and Destructor :-
Constructor called when object is created and Destructor called when object is ereased.
Angular Architect/Pillars :-
Angular have three pillars
1- component – communicate with front end – create HTML
2- service – business logic
3- routing – navigation with in pages/components
Spring @Webservice (annotation)
If we don’t define any service (REST,SOAP),through annotations in spring we use @webservice which is builtin library of java found in jax-ws
what is dbo in sql ?
dbo , or database owner, is a user account that has implied permissions to perform all activities in the database. Members of the sysadmin fixed server role are automatically mapped to dbo .
dbo is also the name of a schema, as discussed in Ownership and User-Schema Separation in SQL Server.
HTTP headers:
- HTTP headers let the client and the server pass additional information with an HTTP request or response
- Request headers contain more information about the resource to be fetched, or about the client requesting the resource.
- Response headers hold additional information about the response, like its location or about the server providing it.
- Representation headers contain information about the body of the resource, like its encoding/compression applied.
- Payload headers contain representation-independent information about payload data, including content length and the encoding used for transport.
MOCK
Mock objects (mocks) are objects which behave similar as the real object. But these mocks are not programmed; they are configured to behave in a certain predefined way. Mock is an English word which means to imitate.
Dependency injection :
Dependency injection (DI) is the concept in which objects get other required objects from outside.
A class has a dependency on another class, if it uses an instance of this class. We call this a class dependency. For example, a class which accesses a logger service has a dependency on this service class.\
Java Server Faces (JSF)
JSF is a Java-based web application framework intended to simplify development integration of web-based user interfaces.
It is a server-side Java framework for web development.
Java Server Pages (JSP)
JSP is a server-side programming technology, that helps software developers create dynamically generated web pages
Java Server Pages are built on top of the Java Servlets API, so like Servlets, JSP also has access to all the powerful Enterprise Java APIs, including JDBC, JNDI, EJB, JAXP, etc.
What is Big O notation in Java?
Big O Notation is the language we use for talking about how long an algorithm takes to run. It is how we compare the efficiency of different approaches to a problem. With Big O Notation we express the runtime in terms of — how quickly it grows relative to the input, as the input gets larger
Big O describes the set of all algorithms that run no worse than a certain speed (it’s an upper bound) Conversely, Big Ω describes the set of all algorithms that run no better than a certain speed (it’s a lower bound) Finally, Big Θ describes the set of all algorithms that run at a certain speed (it’s like equality)
Concept of Three Tier Architecture
The advantage of three tier Architecture is code reusability. In starting live practice for three tier Architecture, there are three layers,
1 – BAL (Business Access Layer)
This layer defines a function or class to use to transfer data into Data Access Layer and Presentation Access Layer
2 – DAL(Data Access Layer)
This layer provides contents of logic to implement a program, for example, a program to add, insert, or update; then all logic of this code is DAL Layer.
3 – UI (PAL) User Interface Presentation Access Layer
The design purpose to use this Layeris simple — to view all design layout from your program’s webpage code.