Skip to main content

Posts

Showing posts from November, 2017

Web Services : Why HTTPS is required and How SSL/TLS works.

Why is HTTPS required?Hyper Text Transfer Protocol Secure (HTTPS) is the secure version of HTTP, the protocol over which data is sent between your browser and the website that you are connected to. The 'S' at the end of HTTPS stands for 'Secure'. It means all communications between your browser and the website are encrypted. HTTPS is often used to protect highly confidential online transactions like online banking and online shopping order forms.
Web browsers such as Internet Explorer, Firefox and Chrome also display a padlock icon in the address bar to visually indicate that a HTTPS connection is in effect.
To verify whether the website is authenticated/certified or not (uncertified websites can do evil things). An authenticated website has a unique personal certificate purchased from one of the CA’s.
Who are CA’s (Certificate Authorities)?CA’s are globally trusted companies like GoDaddy, GeoTrust, VeriSign etc who provide digital certificates to the websites.
What are pu…

Data retrieving using the SQL SELECT command.

Basic SELECT StatementSELECT *|{[DISTINCT] column|expression [alias],...} FROM table; SELECT identifies the columns to be displayed.
FROM identifies the table containing those columns.
Selecting All Columns SELECT * FROM departments;
Selecting Specific Columns SELECT department_id, location_id FROM departments;

Writing SQL Statements(Conventions)SQL statements are not case-sensitive.SQL statements can be entered on one or more lines.Keywords cannot be abbreviated or split across lines.Clauses are usually placed on separate lines.Indents are used to enhance readability.In SQL Developer, SQL statements can optionally be terminated by a semicolon (;).Semicolons are required when you execute multiple SQL statements.In SQL*Plus, you are required to end each SQL statement
with a semicolon (;).

Database table basics

Table Basics:A relational database system contains one or more objects called tables. The data or information for the database are stored in these tables. Tables are uniquely identified by their names and are comprised of columns and rows. Columns contain the column name, data type, and any other attributes for the column. Rows contain the records or data for the columns. Here is a sample table called "weather".
city, state, high, and low are the columns. The rows contain the data for this table:

WeathercitystatehighlowPhoenixArizona10590TucsonArizona10192FlagstaffArizona8869San DiegoCalifornia7760AlbuquerqueNew
Mexico8072

What is database and SQL?

In simple words data can be facts related to any object in consideration.For example your name, age, height, weight, etc are some data related to you. A picture , image , file , pdf etc can also be considered data.
What is a Database? Database is a systematic collection of data. Databases support storage and manipulation of data. Databases make data management easy. Let's discuss few examples. An online telephone directory would definitely use database to store data pertaining to people, phone numbers, other contact details, etc.Your electricity service provider is obviously using a database to manage billing , client related issues, to handle fault data, etc. Let's also consider the facebook. It needs to store, manipulate and present data related to members, their friends, member activities, messages, advertisements and lot more. We can provide countless number of examples for usage of databases .
What is a Database Management System (DBMS)?Database Management System (DBMS)…

Pagination with hibernate criteria

Hibernate is most popular technology in Java development. Most of the real world application they used kind of hibernate technology with fine tuned mechanisms. If you are in java development I hope the following code snippet will be helpful you to make your application faster. What I’m going to explain in this post is how to load the chunk of data with efficient manner.
Hibernate Criteria helps to do this as we wish. Think about if you have millions of data in your data table and you are going to display the data in your application.

package com.jubiliation.example.pagination;

import java.util.Date;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class PaginationInHibernateWithCriteriaAPI {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
SessionFactory sessionFactory = new Configuration().configure().b…

What is multi-tenancy in Software Design???

Multi-tenancy is an architectural approach that enables a single instance of an application to be shared among multiple organizations/users,also called tenants.  According to Oracle Multitenant’s description on IT Central Station, multitenant architecture is “a new architecture that enables customers to easily consolidate multiple databases, without changing their applications.” "Multitenancy refers to a principle in software architecture where a single instance of the software runs on a server, serving multiple client organizations (tenants). Multitenancy is contrasted with a multi-instance architecture where separate software instances (or hardware systems) are set up for different client organizations..."
In SaaS, usually a multitenant application has one software layer and one database, but each customer logs in to what appears to be his exclusive app environment. He can only see and manage its own information.
Sometimes, single customer applications can be eas…

Way of multitenancy implementation from database side.

Discriminator Strategy The discriminator pattern works on a single database service and single schema for all tenants. Constituent tenants are discriminated by a specific strategy such as a tenant_id field embedded in tables containing tenant specific data. Beyond the below pro's/con's this strategy is a non-starter for use case which legally require 'air-space' between tenants.
Pros
Single database and schema instance to manageSingle schema to backupSingle schema to archive, upgrade etc.Simple reporting across tenants (e.g. SELECT .... GROUP BY tenant_id)Single database service account to manage per application.Single database instance to tune and maintain. Cons
Tenant data is interwoven meaning backup & restore is an all or nothing proposition.Care needs to be taken with every database interaction that the data returned is appropriately scoped.If your database goes down, all your customers go down, therefor necessitating a high availability strategy which is gene…

WebServices: PUT vs POST in REST

According to the HTTP/1.1 Spec:
The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line In other words, POST is used to create.
The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI." That is, PUT is used to create or update. So, which one should be used to create a resource? Or one needs to support both?
Both PUT and POST can be used for creating.
You have to ask "what are you performing the action to?" to distinguish what you should be using. …

WebServices : REST is stateless why???

The fundamental explanation is: No client session state on the server. By stateless it means that the server does not store any state about the client session on the server side. The client session is stored on the client. The server is stateless means that every server can service any client at any time, there is no session affinity or sticky sessions. The relevant session information is stored on the client and passed to the server as needed. That does not preclude other services that the web server talks to from maintaining state about business objects such as shopping carts, just not about the client's current application/session state. The client's application state should never be stored on the server, but passed around from the client to every place that needs it. That is where the ST in REST comes from, State Transfer. You transfer the state around instead of having the server store it. This is the only way to scale to millions of concurrent users. If for no othe…

WebServices : RESTful vs SOAP

SOAP and REST can't be compared directly, since the first is a protocol (or at least tries to be) and the second is an architectural style. This is probably one of the sources of confusion around it, since people tend to call REST any HTTP API that isn't SOAP. Pushing things a little and trying to establish a comparison, the main difference between SOAP and REST is the degree of coupling between client and server implementations. A SOAP client works like a custom desktop application, tightly coupled to the server. There's a rigid contract between client and server, and everything is expected to break if either side changes anything. You need constant updates following any change, but it's easier to ascertain if the contract is being followed. A REST client is more like a browser. It's a generic client that knows how to use a protocol and standardized methods, and an application has to fit inside that. You don't violate the protocol standards by creating extra …

Spring : Dependency of Beans

DEPENDENCY OF BEANS
If a bean need other bean or beans for its working ten other beans are called dependencies of the
bean. Dependency of the bean can be of following type:
1. Dependency on primitive values (String are considered as primitive).
2. Dependency on other beans.
3. Dependency on collections.
Dependencies of beans can be satisfied using either of the following approach.
A. Dependency Injection
B. Dependency Lookup
In case of Dependency Injection, dependencies of the bean are satisfied by the container on its own
i.e. a bean user simply ask the container to provide the bean if the bean has some dependencies.
Container is not asked explicitly to satisfy them rather they are satisfied by container by its own.
In case of Dependency Lookup, dependencies are satisfied by the container only when its explicitly
asked to do so.
Spring IOC Container supports dependency Injection because it reduces the steps for the bean user.
Two strategies are supported by the container for injectin…

Spring : Detailed Example for bean creation and management

Now Objects which are used in the application have some data which is either loaded from the
Database or provided by the user as input i.e.in both the cases the data becomes available at the time
of execution. To get the object initialize either from user input or from database factory method is
used.
In the application example 1; Two beans were configured by the name “num1” and “num2” with fixed values given by the programmer. Whenever these beans will be requested they will have same values.
In real application scenario different users want to provide the different values to their objects.
It can be facilitated by concerting the direct object creation approach to indirect object creating
approach i.e. we can add static factory methods to Complex.java and Rational.java to create and
initialize their object from the user input.
Now Application Example 1 is looks like the following:
1. Number.java
package com.jubilation.spring.user;
public interface Number {
public Number add(Number n…

Spring : Creating bean by different class non-static factory method

Different class non-static factory method
Let’s take an example.
package com.jubilation.spring.user;
public class A {
public A() {
System.out.println(“Object of the class A is created…”);
}
}
package com.jubilation.spring.user;
public class B {
public A getA() {
//some object of class A created here and returned….
}
}
Configuration will be like this
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id=”b” class=”com.jubilation.spring.user.B”>
<bean id=”a” factory-bean=”b” factory-method=”getA”>
</beans>

Spring : Creating bean by different class static factory method

Different class static factory method
Let’s take an example.
package com.jubilation.spring.user;
public class A {
public A() {
System.out.println(“Object of the class A is created…”);
}
}
package com.jubilation.spring.user;
public class B {
public static A getA() {
//some object of class A created here and returned….
}
}
Configuration will be like this
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id=”a” class="com.jubilation.spring.user.B" factory-method=”getA”>
</beans>

Spring : Creating bean by Same class static factory method

Same class static factory method
Let’s take an example.
package com.jubilation.spring.user;
public class A {
private A() {
System.out.println(“Object of the class A is created…”);
}
public static A getA()
{
// some object is created and return by this function.
}}
Configuration will be like this
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="a" class="com.jubilation.spring.user.A" factory-method=”getA”/>
</beans>

Spring : Creating bean by Constructor

Directly by using the constructors of the bean class.
Let’s take an example.
package com.jubilation.spring.user;
public class A {
public A() {
System.out.println(“Object of the class A is created…”);
}
}
Configuration will be like this
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="a" class="com.jubilation.spring.user.A"/>
</beans>

Spring : Terminology and Components of Spring IOC

Terminology and Components of Spring IOC
1. Bean- An object which is created and managed by IOC Container is a Bean.
2. BeanFactory- is an interface which describe the functionality of a basic IOC Container. Any
class which implements this interface represents as an IOC Container.
3. XMLBeanFactory- is a framework provided class which implements BeanFactory Interface; an
Object of XMLBeanFactory requires Bean Configuration File i.e. A XML Document.
4. Resource- is an interface it provides methods of managing the beans Configuration. Different
implementations of this interface are provided by the framework.
a. ClassPathResource- It is used when the configuration file/required file is in class path (A
default path for placing the classes that is “build” in case of desktop/console application
and WEB-INF in case of Web Application). This is mostly used in Web Application
because developer doesn’t know the exact path when the application is deployed on
server. Its default searching approach is class …

Spring : Description of Modules

DESCRIPTION OF MODULES:
CORE
This module provides the implementation of basic IOC Container.
CONTEXT
This module is built over core and provides the implementation of an Advanced IOC Container.
AOP (ASPECT ORIENTED PROGRAMMING)
This module is built over context and provides the implementation of Spring AOP.
TX
This module facilitates AOP based transaction management.
JDBC
This module provides the implementation of template design pattern for JDBC operations.
ORM
This module facilitates integration of sprig application to ORM frameworks such as Hibernate, iBatis etc.
WEB
This module provides the implementation of common operations of web application such as validation, file downloading, file uploading etc.
WEB MVC
This module provides the implementation of MVC design pattern for developing dynamic web
application.
ENTERPRISE INTEGRATION
This module facilitates integration of Enterprise services such as JMS, JNDI, Java Mai, etc. to Spring
Application.
TESTING
This module facilitates IOC based Unit & Inte…

Spring : Bean configuration & Management

BEAN CONFIGURATION & DEPENDENCY MANAGEMENT : To configure the beans and their dependency <bean> element is used. This element supports multiple attributes, most commonly used among them are as follows:
1. id: is used to assign a unique identifier to the bean.
2. class: used to specify the class name of the bean.
3. factory-method: is used to specify the method which is to be used by the IOC Container for creating the requested bean.
4. factory-bean: to specify the bean which is to is used by the IOC Container for creating the
requested bean.
5. scope: to specify the scope of the bean; A bean can have either of the following scope:
a. Singleton: It is the default scope for the beans, singleton beans are created Only once by the container when they are requested for the very first time. They are shared by the multiple users.
b. Prototype: Prototype beans are created each time they are requested from the container. They are used when different users need to represent different states (…

Spring : Core (IOC Container)

First we will understand what is IOC- Inversion of Control, The concept of IOC deals with Object Creation, Dependency Satisfaction & Life Cycle Management. The concept states that application programmers must only be concern with the use of Objects, they shouldn’t be concern with their creation and life cycle management. Application programmers should delegate these responsibilities to a Runtime Environment called IOC Container. Conventionally application programmers waste more than 50% of their efforts in object creation & their management as we can describe this situation by the following example.
Let's there be two classes named A & B. Class A has a dependency on Class B i.e. an Object of Class B is required by an Object of Class A to Perform its task.
The conventional approach does this thing as.
1. Application need an Object of Class A.
2. Object of Class A is created let ObjA.
3. Object of B class is created let ObjB.
4. Reference of ObjB is provided to ObjA.
5. ObjA is…

Spring : Introduction

Spring is a general purpose framework which doesn’t confine itself to any specific domain i.e. it can because in a console application, desktop application or a web application. It is based on a concept of Inversion of Control & Aspect Oriented Programming. It also supports distributed application
development.
Spring is a collection of Modules which can be used individually or collectively.
Read Here : Detailed Description of the Spring Modules