Monday, June 19, 2017

Why wait(), notify() and notifyAll)() had to be on Object class than Thread

Reason: Reduce code-complexity and to avoid lot of additional lines of code.

Here is why:
Here is the producer-consumer problem that uses wait notify and notifyAll on Object Class:


Queue:
public class Queue {

private List numberQueue;
private final int MAX_SIZE = 5;
private int top = 0;
public void produce(Integer number) throws InterruptedException{
synchronized(numberQueue){
if(numberQueue.size() == MAX_SIZE)
numberQueue.wait();

numberQueue.add(number);
top =  top+1;
numberQueue.notifyAll();

}

}

public void consume() throws InterruptedException{
synchronized(numberQueue) {
if(numberQueue.size() == 0)
numberQueue.wait();

numberQueue.remove(top);
top = top-1;
numberQueue.notifyAll();

}
}


}



Producer:
public class Producer extends Thread{

Queue queue;

Producer(Queue queue){
this.queue = queue;
}

public void run(){

while(true){
Integer i = new java.util.Random().nextInt(50)+1;
try {
queue.produce(i);
} catch (InterruptedException e) {

e.printStackTrace();
}
}

}
}


Consumer:

public class Consumer extends Thread{

Queue queue;

Consumer(Queue queue){
this.queue = queue;

}

public void run(){

while(true){
try {
queue.consume();
} catch (InterruptedException e) {

e.printStackTrace();
}
}
}


}


ProdConsDemo:
public class ProdConsDemo {

public static void main(String[] args) {
Queue queue = new Queue();
Producer producer = new Producer(queue);
Consumer consumer = new Consumer(queue);

producer.start();
consumer.start();

}

}


I am not going to explain whats the program is all about since its pretty popular but what I am going to do is...Re-write the program considering wait, notify and notifyAll on Thread class.

Producer, Consumer and ProdConsDemo wont have to change since they dont have the wait/notifyAll methods. But below is the Queue class that gets changed with the highlighted lines of code.

Queue:

import java.util.List;
public class Queue {

private List numberQueue;
private final int MAX_SIZE = 5;
private int top = 0;
public void produce(Integer number) throws InterruptedException{
synchronized(numberQueue){

if(Thread.currentThread().getName() == "Producer" && numberQueue.size() == MAX_SIZE)
Thread.currentThread().wait();


numberQueue.add(number);
top =  top+1;
numberQueue.notifyAll();

}

}

public void consume() throws InterruptedException{
synchronized(numberQueue) {

if(Thread.currentThread().getName() == "Consumer" && numberQueue.size() == 0)
Thread.currentThread().wait();


numberQueue.remove(top);
top = top-1;
numberQueue.notifyAll();

}
}


}

The statement - Thread.currentThread().getName() is repetitive.


How to define the Shareable-Class:
Normally, the code inside the shared object is independent of the threads sharing it. And also, any critical section of the Shareable-class normally has a same/generalized business-logic across multiple threads. The logic won't vary from thread to thread.

Hence, in any critical section(a synchronized block or method), JVM needs the following 2 things to put the threads in wait or active state based on the locks.
1) Which is the currently running thread.
2) Which is the object on which the currently running thread acquired the monitor.

It is evident from the critical section that both the information can clearly be inferred by JVM. Then JVM will act as soon as it encounters the wait() irrespective of which class(Object or Thread) callling wait() or notify/notifyAll() methods.

Thursday, June 8, 2017

Programming Language features(Under the hood) - Reuse, Scope, Code maintenance and Maintenance

I would like to discuss on how the ideas - Reuse, Scope, Code optimization and maintenance - drive one aspect of programming language design and ultimately its compiler or interpreter implementation.

To begin with, all or many existing programming languages up to some extent follow one or more of the fundamental paradigms such as - Functional, Declarative, Imperative/Procedural and Object Oriented.

A language is considered single paradigm type if it implements one of the paradigms and multi-paradigm language is the one which incorporates constructs from multiple paradigms.

    Hence, we can derive the fact that all existing programming languages have many characteristics in common. Below are some of the most important to list:
1) Variable and Constants
2) Control Structures
3) Inheritance
4) Encapsulation
5) Abstraction
6) Functions or Subroutines or Procedures
7) Arithmetic and logic operations
8) Type

etc.,

Lets analyze the above mentioned constructs/features and see where we get lead to...


1) Variables, Constants and their assignment: These are required by any programming language since they fairly constitute the fundamentals of computation.
2) Control Structures: 
   -> Decision making features - if else, switch case - describe the direction of flow of program. This can again be categorized to be in the lines of computation.
   -> Iterative structures - for, while, for each and do while -  though describe the typical behavior of performing computation (Executing set of instructions) but highlight the point of Repetition. This is actually refers to a kind of modularity which is nothing but code reuse.
3) Inheritance: This is one of the best examples of code-reuse. Be it Class based inheritance from Java & C# or Prototype based inheritance in Javascript, both eventually indicate the fair usage of Code-Reuse concept. A subclass inheriting the superclass's properties plainly mean reusing existing methods and data. The whole purpose is to code-reduction and promote reuse.

4) Encapsulation: There are two thoughts to encapsulation
a) Bundling data and code to get a new data type: This though indicates that in creating a new datatype but under the hood it conceptualizes Reuse of existing code in the form of creating object which refers to data and methods(nothing but lines of code acting on the data bundled to it). 
b) Access restriction on code: Imposing access restrictions such as public/private/protected mean nothing but deciding which blocks of code to be available to other developers to reuse to prevent misuse.

5)Abstraction: Concept of hiding the implementation details is called Abstraction. In case of Functional / Procedural languages, the functional/procedure is modeled as element of abstraction. Whereas in OOP, a class represents the unit of abstraction. So basically fundamental building block of a programming paradigm represents the level of abstraction. Lot has been said. Lot has been told about abstraction but finally what it means in terms of programming...Well this is also ultimately represents Code Reuse.

A function is defined as a block of code that can be called any number of times during computation of a problem. This facilitates developer to reuse same lines of code(if he wants to use) by calling the function/procedure/subroutine instead of re-writing the whole again.

Similar reasoning applies to Class in Java or C#. Where the lines of code along with data on which the methods apply are bundled into an element called Class and that can be reused if need be.

Based on the above scenarios, we can conclude that characteristic of abstraction is nothing but how efficiently it allows for code-reuse.


6)Functions or Subroutines or Procedures: They are introduced from the mathematical principles of set theory and functions.
Functions at last also are means of achieving re-usability of code.

7) Arithmetic and logic operations: Operations are nothing but the computations to be performed based on the instructions later resulting the desired output. Hence more or less they belong to category of Computation rather than language characteristic.

8) Data Type: Categorizing the data such as Text, Integers, float Binary etc - to manage memory efficiently and perform faster calculations is more of computational characteristic than something to do with code writing technique.

barring the computation features such as Variables, Constants, Control Structures, Arithmetic &  logic operations, Data Types etc...rest of the characteristics - - one way or the other way have the following principles under the hood.
1)Reuse
2)Scope
3)Code maintenance
4)Maintenance

Wednesday, February 8, 2017

Introduction to Java's Inheritance and Interfaces - Part 3

So far dynamic polymorphism is permitted within a Class hierarchy(thanks to Inheritance) but not across multiple hierarchies. What it means is...

Consider the following hierarchies of classes:
Parent: Car, Child1: BMWCar extends Car, Child2: BenzCar extends Car
Parent: Aeroplane, Child1: Boeing extends Aeroplane, Child2: AirBus extends Aeroplane




Now I want to create a program which uses the above class hierarchies where the requirement is to dynamically call cruise() based on a user input.
Requirement: If user enters 
     Benz   --> cruise() from BenzCar class should be executed
  BMW    --> cruise() from BMWCar class should be executed
  Boeing --> cruise() from Boeing class should be executed
  AirBus --> cruise() from AirBus class should be executed
  
Solution: 
This situation is quite common in OOPs programming. Here is the code below:

public class DemoInterface{

public static void main(String[] args){
Car car;
Airplane plane;
if(args[0].equals("Benz")){
car = new BenzCar();
}else if(args[0].equals("BMW")){
car = new BMWCar();
}else if(args[0].equals("Boeing")){
plane = new Boeing();
}else if(args[0].equals("AirBus")){
plane = new AirBus();
}else{
System.out.println("Invalid entry. Pls try again.");
}


//Calling the method
if(car != null)
car.cruise();
if(plane !=null)
plane.cruise();

}

}

Solution is okay...but observe the repetition:
car.cruise(); 
plane.cruise();

The method is called twice. Though it is necessary but can be avoided and has to be. Since this program contains just 2 different class hierarchies and we created two super-class obj-refs able to refer all other sub-class objects. But, What if it has many more.It might lead to more number of references. To optimize this situation, Java has provided Interface.

Interface(Def from Oracle):In the Java programming language, an interface is a reference type, similar to a class, that can contain only constants, method signatures, default methods, static methods, and nested types. Method bodies exist only for default methods and static methods. Interfaces cannot be instantiated—they can only be implemented by classes or extended by other interfaces.

I would say... Interfaces similar to SuperClass obj-ref referencing SubClass'Object for the benefits of code-optimization can do the same but accross multiple Class-Hierarchies. Its a level beyond the polymorphism achieved with Inheritance.

Notation: As in Class level inheritance, where super-class variable can refer any of its child class objects, An interface's variable too can refer any of its implementing classes. Lets use Interface in the above situation.

Figure followed by updated solution below shows how the hierarchy looks like if interface is used.



We can see, the super classes - Car & Airplane - implement CarOPlane interface containing the methods - cruise() and selfDrive(). Then, the child classes override those methods again.

Note: What methods that are qualified to be in Interface?
All those identical methods(methods with same signatures) which belong to multiple class-hierarchies can be part of Interface's definition.


Interface: 
public interface CarOPlane{
public void selfDrive();
public void cruise();
}

Updated solution:

public class DemoInterface{

public static void main(String[] args){
CarOPlane cop;                        //Creating an interface obj-ref
if(args[0].equals("Benz")){          
cop = new BenzCar();  //Assigning implementing class's object
}else if(args[0].equals("BMW")){
cop = new BMWCar();               //Assigning implementing class's object
}else if(args[0].equals("Boeing")){
cop = new Boeing();      //Assigning implementing class's object
}else if(args[0].equals("AirBus")){
cop = new AirBus();               //Assigning implementing class's object
}else{
System.out.println("Invalid entry. Pls try again.");
}


//Calling the method
if(cop != null)
cop.cruise();     //Calling the cruise() method. This is where the code is optimized

}

}


Summary of Interface benefits:
1) Code optimization: Repetition is reduced as a result code maintenance reduced too. Means..if some part of the repeated code need to be changed, it has to change at every repeated line of code.
2) Interface reference can refer objects span across multiple class hierarchies(A limitation in inheritance based). A level beyond polymorphism achieved with Inheritance.


Deadly Diamond of Death: Many Java professionals have an opinion that multiple-inheritance creates the problem of Deadly Diamond of Death(DDD) and Interface is the solution. But I wont agree. Here is my take...

In case of child-class inheriting a parent-class, the child basically inherits the code and does not require it to write the new code unless it really needs its own implementation. Hence, if a child tries to inherit from multiple parents containing identical methods(bodies may differ but do exit), the problem arises as to which parent's method need to inherit(DDD). Java does not allow this. 

But, same is not the case with Interfaces. They don't have implementation. Therefore, if a class implements several interfaces that have identical method-signatures only(but no bodies), it only imports method signatures and implements them. No confusion as to which code to implement since there is no code exist in interface's methods.

Tuesday, February 7, 2017

Introduction to Java's Inheritance and Interfaces - Part 2

Contd...

Lets now use the above classes in main program:
Objective: Based on an input from a user, the program has to use code from either Car or BenzCar or BMWCar.
Requirment: If the entry from use is Car then use the code from Car class similary for Benz and BMW.

Solution:
public class InheritanceDemo{
public static void main(String[] args){
if(args[0].equals("Car")){
Car car = new Car();
car.drive();          //Prints This is default drive implementation
car.accelerate();     //Prints This is default accelerate implementation
car.applyBrakes();    //Prints This is default applyBrakes implementation
}
else if(args[0].equals("Benz"){
BenzCar benz = new BenzCar();
benz.drive();         //Prints This is default drive implementation
benz.accelerate();    //Prints Accelerate slowly and steadily.
benz.applyBrakes();  //Prints This is default applyBrakes implementation
}
else if(args[0).equals("BMW"){
BMWCar bmw = new BMWCar();
bmw.drive();          //Prints Drive or move at highest speed all the time
bmw.accelerate();     //Prints Accelerate at brisk speed but steadily.
bwm.applyBrakes();    //Prints This is default applyBrakes implementation
}
else
System.out.println("Invalid Entry");
}

}

Notation: Super-class referencing Sub class object: So far, the code looks simple but there is an issue with the code. It contains lot of repetition.

car.drive();
benz.drive();
bmw.drive();

Like-wise the other methods - accelerate() and applyBrakes().
This repetition has made the program lengthy with more number of lines of code than required. As a result the code's compilation time increases. But there is a facility provided by Java's inheritance to optimize this kind of situations.

Use of the notation: Super class referencing Sub class object

Yes. The Super-class's or Parent-class's object reference can refer to its sub-class's or child class's object.

Car car = new BenzCar();
Car car = new BMWCar();



Lets use this notation in the above program.

public class InheritanceDemo{

public static void main(String[] args){

Car car;                 //Creating a Super class's object reference.

if(args[0].equals("Car")){
car = new Car();     //Assign a Class's object to its reference.
}
else if(args[0].equals("Benz"){

car = new BenzCar(); //Assign Subclass's object to its SuperClass's reference.


}
else if(args[0).equals("BMW"){
car = new BMWCar();  //Assign Subclass's object to its SuperClass's reference.
}

else
System.out.println("Invalid Entry");

car.drive();          //Prints based on input
car.accelerate();     //Prints based on input
car.applyBrakes();    //Prints based on input


}

}

Now see, how the code has shaped up with fewer number of lines with the new notation.
A Super-Class's object can behave(or morph or act) like its sub-class's object based on the object that it refers. This is called Runtime polymorphism or Dynamic polymorphism. An important concept closely associated with efficient coding.


Monday, January 30, 2017

Introduction to Java's Inheritance and Interfaces - Part 1

Before beginning to learn Java as a programming language, it is equally important to learn the evolution of the Object Oriented Programming from the days of Machine language. Here, I am just providing a tiny history of how it evolved all along. Note that it is very very tiny. There are books written all over about these Programming Paradigms.

During the days of Machine Languages, the coding is very difficult as it forces developers/coders to type instructions in binary digits like below:

10110000 01100001
01100010 11100101
00100010 10101001

Hardly, readable isn't it?. That is when the Human-Readable-Mnemonics are invented to easily remember the binary instructions.

MOV AL, 61h
CPY CH, 21H
ADD CY, CB
SUB AB, NY

Mnemonics have somewhat reduced the difficulties involved in binary languages but not completely solved the problems. Lets study a case. Say we want the processor(CPU) to do the following:
1. Read 2 numbers
2. Add the numbers
3. Store the result in another variable

This can be coded straight away as follows:
READ A       //Read data from variable A
READ B       //Read data from variable B
ADD A,B      //Add contents of B to A
MOV A, AH    //Save the contents of A to memory location AH

This is sufficient for now. But, what if we want to perform the same operation multiple times in future? The code is going to be a long list of repeated instructions.

READ A
READ B
ADD A,B 
MOV A, AH

UPD A
UPD B
READ A
READ B
ADD A,B 
MOV A, AH

UPD A
UPD B
READ A
READ B
ADD A,B 
MOV A, AH

UPD A
UPD B
READ A
READ B
ADD A,B 
MOV A, AHA

And so on. This repetition of code is strictly unwanted and highly inefficient. So, in order to resolve this, what can be done is ..Group the repeated block of statements as Function. Then assign a name to it and call the function whenever that block of code is required(is to be repeated). This type of Code-Reuse is called Functional Abstraction also called Process Abstraction. A concept that changed the style of programming since then.

Now the above code can be re-written as:

function add(A,B){
UPD A
UPD B
READ A
READ B
ADD A,B 
MOV A, AH
}

add(10,20)
add(20,30)
add(30,40) ..And so on. 

Note: The repetition of above function call - add(10,20) - can be put in a loop. Loops and Conditional Statements etc are other programming language constructs.

Functional Abstraction: The concept of hiding implementation details from the user of the function. Means, a developer who wants to use add(A,B) function need not know about the actual code inside the function block. All he/she needs is how to use the function. What parameters are to be sent(Eg: A, B) and what it returns.

This paved the way for Functional Programming.

Well! Not stopping at this, then came along another type of abstraction called Data Abstraction - The central & dominant theme of Object oriented languages.

Data Abstraction: In its plain sense, hiding the data and only exposing the methods which operate on that data. So anyone who wants to perform any operation on the data, need to use those methods associated with it.
The binding of both data and its associated methods together in a single block is called Class and its instantiation is called Object - The building blocks of Object Oriented Programming.
Note: The newly created data structure - Class - is also termed as Abstract Data Type(ADT).

The abstraction in object oriented languages is implemented using 3 more concepts:
1. Inheritance
2. Polymorphism
3. Encapsulation
Strictly remember that Abstraction is not a feature of OOPs. This is as stated earlier the central theme.

Abstraction be it Process or Data is basically Code-Reuse if you observe carefully. How effectively the code can be re-used and maintained determines the efficiency of language. Hence, the 3 concepts revolve around achieving Data abstraction.

Inheritance(Def from Oracle): The idea of inheritance is simple but powerful: When you want to create a new class and there is already a class that includes some of the code that you want, you can derive your new class from the existing class. In doing this, you can reuse the fields and methods of the existing class without having to write (and debug!) them yourself.

Here is the example of code re-use in Inheritance:

Base Code:
public class Car{
String name;
String model;
String number;

public void getDetails(){

}

public void drive(){
system.out.println("This is default drive implementation");
}

public void accelerate(){
System.out.println("This is default accelerate implementation");
}

public void applyBraks(){
System.out.println("This is default applyBrakes implementation");
}
}


Re-use Sample 1:
public class BenzCar extends Car {

float price;
float company;


/*String name;
String model;
String number;*/    //Inherited from Parent Car. Code is re-used.

//Did not want the default code. Hence, code is written. Did not re-use.
public void accelerate(){
System.out.println("Accelerate slowly and steadily.");
}   


/*drive() & applyBraks()*/  //Inherited from Parent Car. Code is re-used

}


Re-use Sample 2:
public class BMWCar extends Car {

float price;
float company;
float brandName;


/*String name;
String model;
String number;*/    //Inherited from Parent Car. Code is re-used.

//Did not want the default code. Hence, code is written. Did not re-use.
public void accelerate(){
System.out.println("Accelerate at brisk speed but steadily.");
}

//Did not want the default code. Hence, code is written. Did not re-use.
public void drive(){
system.out.println("Drive or move at highest speed all the time");
}

/*applyBraks()*/  //Inherited from Parent Car. Code is re-used

}

Saturday, September 17, 2016

Socket and Perception of Connection between Client and Server

Sockets: An object created by any networked application which contains 'data and address*' details to be sent to another program running on another machine elsewhere via wireless or wired infrastructure.
Eg: In case of Java, Socket is part of  Java's Networking API(java.net.* package) which knows how to talk to machine's Network Stack(TCP/IP) to send and receive data.

Network Stack: Its a software+hardware infrastructure specific to a computer. The software component is usually implemented by machine's OS.

data and address*:
Data -> Data from source program.
Address -> Host and Port details of the destination program.



Q) When can we say a connection is established between a server and a client?
Ans)       Many imagine or believe that a connection is physical wire or wireless connection. Or some might think it's specific to machine's protocol layer. But this is a pure misconception. Connection is purely abstract and conceptual. Below is how it's supposed to be perceived.

       Similar to how a socket object is created at source program, if a new socket object is created(to receive the data) at the destination program on the destination machine upon a receiving a request from source, then we can say a connection is established. So, in an abstract way connection means creation of client and server specific socket objects. The data transmission between source and destination programs over 'that connection' happens usually but not restricted to first via TCP(But also UDP, SCTP etc - Transport Layer protocols) then to IPv4(but also IPv6, ICMP etc - Internet layer protocols) then to ARN(but also NDP, OSN etc - Link Layer) and so on down through TCP/IP stack protocol layer. Above all the layers is the Application Layer. Hence, 'that connection' is named based on the application layer protocol...
Eg:
1) HTTP Connection if the client and server uses HTTP (Web applications use this)
2) SMTP Connection if the client and server uses SMTP (e-Mail applications use this)
etc,.

Note: Protocols used by Applications - Web Application, Mail Applications, Chat applications etc,. any user application - are called Application Layer protocols. But here is the catch. Sometimes applications may skip the Application Layer and directly communicate starting from Transport layer.

         Now, look at the below diagram showing how the above explained Sockets and Network Stack work exactly in a communication process between a Http Client and Http Server. Clearly indicated who does what - that of Server and Client.
Client - Server communication via TCP/IP with the help of Sockets



Wednesday, September 14, 2016

Frequently Bugging Questions - FBQs - Java

Q1) How many instances of data(variables) and behavior(methods) per objects are created during runtime?

Ans) Well, each instance of a class has its own set of non-static class data. But the behavior or methods(both static and non-static) will be created only once in the class area. After all what is the point of having a same method code multiple times!

Q2) Servlet Container, EJB Container...what is a Container?

Q3) What is Serialization in Java
Ans) Just like .txt, .pdf, .doc etc., Serialization(.ser) is a format which can be understood by a JVM or any java program. There are many ways - eg: text files -  we can save java's objects but .ser is the most efficient way.

Q4) Compare HTTP vs HTTPS vs SOAP in terms of Security?

Security Comparison
Q4) What is ThreadSaftey?
Ans? A Class or its object is said to be thread safe if it has
 i) No State or no instance variables
ii) Immutable state or all its instance variables are immutable
iii) State that can only be modified through it's methods which are synchronized

Q5) What is the difference between MOM and Message Broker?
Ans)
Basically, MOM- Message Oriented Middleware - is an enterprise integration system that does the function of transfer of messages from sender to receiver. It can be imagined as a central system that takes a message(in any format - Text/Soap/Json etc) and simply sends it to the target receiver as it is. MOM does not do any transformation. It just sends as is the message received.

Message Broker: This is nothing but a MOM with a special capability of transforming messages from Senders to accepted formats of the receivers and send/distribute them.

Q6) What is an Inner Class in Java?
When you need some functionality which must be a member of a class but can't be achieved with either a member variable or its method, then Inner Class is used.

Features of Inner Class:
1) Functionality achieved by the inner class is very much specific to the Class
2) It need to use the environment of the Outer class like its members etc to achieve the functionality

Q7) Benefit of DI in Unit Testing?
Dependency Injection and ease of doing Unit Testing:
There are no special advantages other than that are offered by DI itself.
Mock objects which are part of JUnit Tests are also injectable just like other dependencies.
In fact, DI does not prevent the use of Mock Objects -- can be considered as an advantage. Since, unit testing would be difficult if we cant use mocks in place of dependencies in DI environment.

Q8) Unable to Connect to SSL Services due to PKIX Path building failed
When you encounter this issue, the normal solution to add Certificate to cacerts which is part of your java environment using keytool. But sometimes it is necessary for you to add all the certificates in the certificate chain till the root need to be added.

Q9) Which .exe file is picked if two directories with same .exe file are present in Windows's system path?
Ans: Windows executes the .exe file from the first detected/found folder in the path.

Q10) What are keytool, keystore and cacerts in Java?
Ans: keystore, keytool and cacerts are provided by Java SE as part of SSL support. Another term that is required  to understand these concepts is Certificate.
Certificate: A certificate is a digitally signed statement of another entity(server of a person or an organisation), stating that the public key along with data sent from the entity is valid. When data is digitally signed, the signature can be verified at the java client side using a keystore file.

keystore: This is a file that jvm uses to store the digitally signed certificates and keys associated with them. cacerts is one such jvm's system wide available file residing in java.home\lib\security dir which contains CA Certificates. CA Certificate is a certificate awarded to an entity who claim that they are by a recognized Certificate Authority(Verizon, Symantec or GoDaddy) with its signature. During HTTPS communication, if a CA-certificate is received from a server, the signature of the Certificate Authority body can be verified in the store. So that the java client can trust the information received from the server is authorized and secure.

Adding Certificates to trust store: Sometimes, if obtaining a certificate is costly, then the organization may choose to send a self signed certificate. In this case, if the received Self Signed Certificate is verifed in the truststore(cacerts), the signature wont be found. Hence, the java client needs to add the certificate to its store so that the future communication can be established.

keytool: This is the utility to manage keystore and certificate etc.

Note:
iOS  has something called keychain that has the certificates
Android has keystore file that contains the certificates
Windows : has its own certificate store

Q11) How to know which path variable windows is reporting while you issue the command java -version?
Ans: for %I in (java.exe) do @echo %~$PATH:I will tell you the exact path on 'path' variable of Environment Variables on machine. This is useful when multiple versions of jre are installed and you are confused why system uses a version of java that you dont want eventhough you set the environment path properly

Q12) How margins apply in a webpage?
Ans: Every web-element has margin. Margin normally refers to the space around the widget or an element. If there are two web elements adjacent to each other, then if you increase the margin of a n element, it pushes the other away. If a widget is inside a container element, and if you increase the margin of the inner widget, the effect falls on the contents of the inner widget since the inner element cant push the container boundaries away. As a result, the text for example of an inner widget inside a container gets shrink. Suppose, the inner widget is another container and its margins are increased, the elements inside it get closer.

Q13) What is Server/Instance/Box etc?
1. Box/Machine: A physical machine - CPU, RAM and ROM - is called a Box. 
2. Instance: Database software running on a particular port on a physical machine or box is called Database-Service-instance. Similarly, if TomCat is installed on the machine, then it is TomCat instance. Likewise, these are called Server instances or Servers. A group of servers is called Cluster.
3. Proxy Server

4. LoadBalancer - F5

Q14)What is High-availability in webbased applications?
High availability means, customers should not get service interruption frequently. Service interruption means the failure of a request processing at server side(middleware or backend). There are various reasons why a request fails at server side but the relevant one in this context is the unavailability of the server - Application/Web Server or Database server. Unavailability means server is down with StackOverflow or OutofMemory or Physically Server is down or Server has reached the maximum limit to handle requests. In order to make the applications highly-available, ensure there is less number of server down issues. There are many solutions and most obvious one is to have a redundancy. Redundancy means keeping multiple servers - Database or Application Servers or Web Servers - with a Loadbalancer. In rare case of LoadBalancer failure, there should be a backup loadbalancer too.

Q15) How to dynamically provide JAVA_HOME path to MAVAN or mvn command?
Ans. Sometimes, when running the command mvn -version will result in JAVA_HOME is not set properly. Setting JAVA_HOME in the system variables(in case of windows) should fix the issue. But if you have multiple versions of java installed and you want mvn to use one dynamically then do the following.
1. Open the command prompt or shell
2. Temporarily set the JAVA_HOME. set JAVA_HOME="path of jdk which does not contain spaces"
3. Now run the mvn -version command to proceed.

How J2EE components work together in any Container - Spring or Application Server

In a Spring+Jersey+Hibernate RESTful webapplication, we can spot various J2EE components - JTA, JPA, Java Bean Validation, JSON-B API for B...