Tuesday, November 30, 2010

DownCasting vs UpCasting

Take one Super class and one sub Class.

public class ClassA {

public void callMe(){
System.out.println(" I am in Class A");
}
}


Sub Class : 
public class ClassB extends ClassA {

public void callMe(){
System.out.println(" I am in Class B");
}
}




What is Upcasting in Java?

System.out.println(" -------------------UpCasting Example --------------------- ");
ClassB childClassObject  = new ClassB();
ClassA parentClassObject = new ClassA();

ClassA classAObject = childClassObject;
classAObject.callMe();

System.out.println("--------------------------------------------------------------");



What is DownCasting in Java?

System.out.println("-----------Down Casting Example-------------------------------");
ClassB classBObject = (ClassB) parentClassObject;
classBObject.callMe();
System.out.println("---------------------------------------------------------------");


Does Java Supports the DownCasting ?
Strictly Speaking No.

This is the Wonderful Link:

NOTES:
If an Class Object is upcasted to It's super class, then we cant allow you to use the properties
in that Class. It allows use only the Properties in the super class.
Example : Once an Object of Class Cat is upcasted to Animal Class. So Now onwards the object
of Cat behaves like an Object of Animal Class. So it is not allowed to use the Properties of
Cat Class.
Example :



http://javaforyou.wordpress.com/2008/06/22/casting-reference-variables-downcasting-upcasting/

Sunday, November 28, 2010

Servlets

Question : What is Servlet?
Definition 1: A small Java program that runs within a web server.servlets
 receive and response to the request from the Web Clients usually across HTTP.
              2) It runs completely inside the JVM.
Definition 2: A servlet is a java class therefore needs to be executed inside
 the JVM, by a service we called Servlet engine.


Question: What is JSDK?
Answer: All servlets API classes and Simple servlet enables web server are 
combined into Java Servlet Development Kit(JSDK).

Question :What are life cycle methods of the servlet interface?
Ans: The interface servlet defines the methods for the servlet life cycle. those are
         1) init Method() :  servlet constructed and initialized
         2) service method() : calls from clients are handled here.
         3) destroy method() :  servlet is taken out of service and destroyed.

Question : Who calls the service() method ?
Ans: called by the servlet container to allow the servlet to handle the request.

Explain the Hierarchal of the servlets ?
Answer :   Servlet [ interface
            |   implements
GenericServlet [ abstract Class ]
           | extends
 HttpServlet   [ Abstract Class ]
          |
          ---------> implements [ serializable ]
          ---------> implements [ servlet ]
         ----------> implements [ ServletConfig ]
Question : What is servlet Config?
Ans : It is an interface, used by the servlet container used to pass information to 
servlet during initialization.

Question : What is servletContext ?
Ans : It is an Interface, used by the servlet to communicate with the servlet container
to get the information such as MIME type of a file , write to a log file.

Note: ServletContext is the object contained within the servletConfig object, where this
 object is passed to the servlet by the servlet container during servlet initialization.


Note: There is only one context with the one web application or with one JVM.


Question : advantages of servlets over the CGI?
Answer : Platform Independent : because servlets written in java language.
              Performance: CGI creates a new process to handle a new request,Servlet creates a new thread.

Array based Queue Implementation in Java

Array Based queue Implementation in java :


import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Queue;




public class ArrayQueue implements Queue {


    Object queueObjects[];
    private int front;
    private int back;
    private int currentSize;
    
    
    public ArrayQueue(){
this(5);
makeEmpty();
    }
    public ArrayQueue(int DEFAULT_CAPACITY)
    {
this.queueObjects = new Object[DEFAULT_CAPACITY];
    }
    
    public static void main(String[] args) throws UnderFlowException{
ArrayQueue obj = new ArrayQueue();
obj.enqueue(new String("sekhar"));
obj.enqueue(new String("Ramu"));
System.out.println("Object Front "+obj.dequeue());
    }
    public void makeEmpty(){
currentSize = 0;
front = 0;
back = -1;
    }
    /*
     * Remove an item from the Queue which is at the front position.    
     */
    public Object dequeue() throws UnderFlowException {
      if(isMyQueueEmpty()){
   throw new UnderFlowException("ArrayQueue dequeue");
      }
 Object returnValue = queueObjects[front];
 front--;
 currentSize--;
        return returnValue;
      
    }
    public boolean isMyQueueEmpty(){

return currentSize == 0;

    }
    public boolean checkFront(int front){

return front == currentSize;
    }
    public void enqueue(Object o){

if(currentSize == queueObjects.length){
   //Increase the Size of the Queue to Accommdate the new Objects
   ensureCapacity();
}
else{
   queueObjects[++back] = o;
   currentSize++;
   front = currentSize - 1;
}
    }
    
    public void ensureCapacity()
    {
int newCapacity = queueObjects.length * 2;
Object oldData[] = queueObjects;
queueObjects = Arrays.copyOf(oldData, newCapacity);
    }

ArrayList implementation in Java

Here is the ArrayList implementation in Java:

package com;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MyArrayList {
    public Object objectArray[] ;
    private int size;
  
    MyArrayList(){
this(10);
    }
    MyArrayList(int initialCapacity){
this.objectArray = new Object[initialCapacity];
    }  
    public void add(int index , Object o){
if(index > size || index < 0){
   throw new IndexOutOfBoundsException("Index : "+index+" Size :"+size);
}
System.arraycopy(objectArray, index, objectArray,index+1,size - index);
objectArray[index] = o;
size++;
    }  
    public static void main(String[] args) {
String s = null;
MyArrayList myObj = null;
for(Integer i=0; i < 20; i++){
   s= new String("Sek"+i);
   System.out.println(" s == "+s);
   myObj = new MyArrayList();
   myObj.add(s);
}
myObj.size();
    }  
    public void add(Object o){
System.out.println(" Get the Current length of the Object array : "+objectArray.length);
//Before adding an Element increase the Size of the array First.
ensureCapacity(size+1);
objectArray[size++] = o;
    }  
    public void ensureCapacity(int minCapacity){
int oldCapacity = objectArray.length;
if(minCapacity > oldCapacity){
   Object oldData[] = objectArray;
   /*Then increase the size of the ObjectArray....
   ArrayList increases the size by 50% of the current size.*/
   int newCapacity = (oldCapacity * 3)/2 + 1;
   if(newCapacity < minCapacity){
newCapacity = minCapacity;
   }
   System.out.println(" New Capacity : "+newCapacity);
   objectArray = Arrays.copyOf(oldData, newCapacity);
}
    }
    public Object get(int index){
return index;
    }
    public int size(){
return objectArray.length;
    }
    public void clear(){
//Remove all elements.
    }
    public int indexOf(Object o){
int index = 0;
return index;
    }
    public Object remove(int index){
rangeCheck(index);
Object oldValue = objectArray[index];
int numOfElementsToMove = size - index - 1;
if(numOfElementsToMove > 0){
   System.arraycopy(objectArray, index+1, objectArray, index, numOfElementsToMove);
}
objectArray[--size] = 0;
return oldValue;
    }
    private void rangeCheck(int index) {
if(index > size){
   throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
}
    }
    @Override
    public String toString(){
return null;
    }
}

Saturday, November 27, 2010

Jsp Basics

Note 1 : _JspInit() , _jspService(), _jspDestroy()  are called the life cycle methods of the JSP.
Note 2 : _jspInit() & _jspDestroy() can override ..


Four phases in jsp life cycle ;
1) translation : tranforming the jsp into  java file( this is translation) and servlet class file (compilation).
2) Initialization :  loads class file and creates the instance of servlet done by jsp engine.


duties by web container :
3) Execution : execute the client request by calling the servlet method '_jspService()'
4) Finilazation : calling the _jspDestroy() to free the resources acquired by the servlet.


What is the advantage of JSP?
Ans : 1) Write HTML
          2) Read and maintain the HTML.


Note: JSP runs entirely on ServerSide.


Question : When does the page Translation occurs?
Ans: 1) Typically at each instance the jsp got modified.
         2)  Never done for each request.




What is Web Container ?
Ans : It is a part of web server contains servlet engine and jsp engine responsible
 for executing the servlets and jsp's.


Note : webserver does not support for the EJB.
Note : Application server supports all the three servlets , JSP's and EJB's.


Example , webserver : Tomcat  & JRunner.
Example : Application server : weblogic , JBoss.


http://geekexplains.blogspot.com/2008/06/whats-jsp-life-cycle-of-jsp-javaserver.html

Question : Explain the hirerachy of JSP servlets.


Ans: The Servlet Class which is generated from the JSP page. 


                    Servlet -- Interface -- javax.servlet Package
                        |
                    JSP Page -- Interface
                       |
                HTTPJspPage -- Interface-- Javax.servlet.jsp package
                      |
                 Generated Servlet class from the JSP...


The JSPPage Inteface has two methods which must be Implemented by all classes
those are 1 ) jspInit() 2) jspDestroy()   
HTTPJspPage-- This Interface declares method _jspService().


                       

Annonations in java 1.5

What is Annonation ?
Ans : Annonations are generally a way to add meta-data(data about data) to the Element
an Element can be a class, method , variable.And these metadata processed by the tools
compilers and javadocs.

Friday, November 26, 2010

variable number of arguments

Question : What is Variable number arguments :
Ans : It is a new feature in java 1.5 [ also called as tiger ] 
Example : public static void mymethod(String ... objects)
                 {
                          for(String  s : myString)
                  {
                      Syso("String : "+s);
                 }
              }

Note : variable number of arguments type statements should be last argument  in the 
          method definition.


Example :
                 This code is correct :


      int n = 43000;
      int number = 500;
      String name = "sekhae23";
     String myName = "Karri,sekhar";
     myMethod(n,number,myName,name);


   public static void  myMethod(int x,int y,String ... objects){
       //Observer variable number of arguments argument is last ....
for(String s : objects){
   System.out.println(" S >>>> "+s);
}
System.out.println(" ");
    }
Below code snippet is Wrong :

     int n = 43000;
     String myName = "Karri,sekhar";
     String name = "sekhae23";
     int number = 500;
     myMethod(myName,name,n,number);

   public static void  myMethod(String ... objects,int x,int y){
       //Observer variable number of arguments argument is last ....
for(String s : objects){
    System.out.println(" S >>>> "+s);
}
System.out.println(" ");
    }



Observation :   One Method can have only one variable number of arguments argument.



Thursday, November 25, 2010

My Interview Questions

Question : What are the new features in Java 1.6 ?
Answer :
a) Collections framework enhancements.
  1. Added new interfaces .
   a)deque : double ended queue.
   b)NavigableSet : a sorted set may be accessed or traversed either ascending or descending order.
   c)NavigableMap : a sorted map may be accessed or traversed either ascending or descending order.
 2. Added New Concrete classes :
     a) ArrayDeque - efficient resizable-array implementation of the Deque interface.
    b) AbstractMap.SimpleEntry - simple mutable implementation of Map.Entry
3.  Added methods to Arrays class:
    a) The Arrays utility class now has methods copyOf and copyOfRange that can 
       efficiently resize, truncate, or copy subarrays for arrays of all types.
Example Before:
int[] newArray = new int[newLength];
System.arraycopy(oldArray, 0, newArray, 0, oldArray.length);
After:int[] newArray = Arrays.copyOf(a, newLength);
b) Java Web Start and Java Plug-in Common Enhancements
c) Internationalization Support.
Internationalization is the process of designing an application so that it can be adapted
 to various languages and regions without engineering changes.
d)Enhancements in Java I/O.
  i) New Class console :
   The method System.console() returns the unique console associated with the
   Java Virtual Machine.
ii)  New Methods added to Class File :
   a) Methods: getTotalSpace, getFreeSpace, getUsableSpace.
Read this link :
Question : What's new in the java 1.5 ?
Answer : 1) Annonations
              2) Generics
              3) New Syntax "for" loop.
              4) Variable number of arguments.
              5) AutoBoxing.
              6) Static Import
             7) Type Safe enum
             8) Concurrent locks
             9) RMIC not Required
            10) Thread pool Executer
            11) Count Down latch
            12) Cyclic Barrier
            13)Blocking.
Question : How many objects will get create in the below scenario ?


Ans : 2 Objects...


                   1)      String a = "abc";
                   2)      String b = new String("abc");
Explanation : For the statement [ String a = "abc" ] it creates one Object in the String
 Constant Pool.For the Second Statement [ String b = new String("abc") ] it Creates
 another object in the heap memory , and placed it in the string constant pool , and 
 finally reference is added to the variable 'b'.


Note The creation of two strings with the same sequence of letters without the use
of the new keyword will create pointers to the same String in the Java String literal pool.
and creates only one object.


The String literal pool is a way Java conserves resources.

Some Important points about string literals:
  • Equivalent String Literals (even those stored in separate classes in separate packs)
  •  will refer to the same String object.
  • In general, String Literals are not eligible for garbage collection. Ever.
  • Strings created at run-time(with new Operator) will always be distinct from those created from String Literals.
  • You can reuse String Literals with run-time Strings by utilizing the intern() method.
  • The best way to check for String equality is to use the equals() method.
This is the Wonderful link :

Question : Is Serializable is marker interface?
Answer : Yes..
Question : Explain how abstraction and encapsulation achieved in Java?

 Abstraction :  suppose say List interface is an Abstraction , it do what it promises to do,
  but hide all the details of the implementation .
   In other sense we can say  it deals with the outside view of an object (interface). 
definition of abstraction is about ignoring the things that don't matter so you can 
focus on the things that do matter.    

Encapsulation :Encapsulation actually means putting data and operations on that data
 together (for example in a class).


"Information/Data hiding is accomplished in java by using Modifiers -
 By keeping the instance variables private or protected." 


Question : How to achieve Encapsulation in java ?
Ans : Define a class with all the data members declared as private so that they are
 not publically accessible to any other class and all the methods that works upon
(or) uses these data members as public. In this way encapsulation is achieved in Java.


Observation : A real world example of Abstraction and Encapsulation ?
Answer :  Very very Good Article :
  http://www.javahelpline.com/2009/06/abstraction-and-encapsulation.html
An Abstraction is a perspective and Encapsulation is an implementation to achieve
that perspective.

Define Perspective  : Appearance of things


 Question What is MVP Pattern ?
Model : Model is an interface defining the data to be displayed 
View: Interface displays the data and en routes the events to the presenter.
Presenter : It Retrieves data from the model,persists it and formats it for 
                   display in the view.


Simply,...
 Model : stores the data.
View : Represents the data.
Presenter :  Co-ordinates the Application.


Question : What is MVC Pattern ?
Though MVC comes in different flavors, control flow is generally as follows:

The user interacts with the user interface in some way. (for example,
 presses a mouse button).

The controller handles the input event from the user interface, often via
 a registered handler or callback and converts the event into appropriate
 user action, understandable for the model.

The controller notifies the model of the user action, possibly resulting 
in a change in the model's state. (For example, the controller updates
 the user's shopping cart.)

A view queries the model in order to generate an appropriate user
 interface (for example, the view lists the shopping cart's contents). 

The view gets its own data from the model. In some implementations, 
the controller may issue a general instruction to the view to render itself.

 In others, the view is automatically notified by the model of changes in
 state (Observer) which require a screen update.

The user interface waits for further user interactions, which restarts 
the cycle.

Question : What is the difference between the MVC and MVP ?
Answer
 In MVP: instead of controller we have Presenter.
In MVP: presenter have an capability of interpret the user events and 
perform any sort of logic necessary to map them to commands to manipulate
the model in the intended order.

Additionally the View in the MVP is responsible to hand over the user events 
to the Presenter,. which is the Job of Controller in MVC pattern.
And the Model in the MVP is strictly a domain Model in MVP.


image
              source from the blog : http://blog.vuscode.com
              Question : What are the differences between thread and process in Java?
              Answer:   1)   Process is separate one and thread is a part of the process.
                             2)  Thread is light weight process, where process is heavy weight.
                             3)  Threads can communicate between threads directly , where
                                  Processes must use IPC to  Communicate with other threads.
                             4) Threads share the address space of the process, where Processes having 
                                 their own address space.
                             5) Process is program in execution, where thread is separate path of 
                                execution in a program.

              Tuesday, November 23, 2010

              Thread Interview Questions

              Question : How wil you Define a Thread ?
              Answer : 1) By Extending the Thread class.
                             2) By Implementing the Runnable Interface.


              A Runnable Interface defines a type of class that can be run by a thread.


              Question : What is the difference between the below code snip-t?
                Code snippet  :
                                        class MyThread extends Thread {
                                     public void run() {
                                              System.out.println("Important job running in MyThread");
                                      }

                                      public void run(String s) {
                                            System.out.println("String in run is " + s);
                                    }

                                }

              In above code even though we write two run methods run() and run(String s) ,the
              method run(String s) will be ignored by the thread class.

              unless you call it yourself.

              The Thread class expects a run() method with no argument and it will execute this
              method for you in separate call stack after the thread has been created.
              The Thread class wont call the run(String s) and even if u call yourself the thread 
              class it wont execute this in a new thread with separate call stack. It is just like a 
              normal method.


              Question : Advantage of defining a thread by implementing the Runnable interface?
              Answer Implementing the Runnable interface gives you a way to extend from
               any class you like, but still define behavior that will be run by a separate thread.
               It looks like this:
              Note : Every thread of Execution begins as an instance of Thread class,Regardless 
              whether you run() method is in the Thread subclass or in a Runnable Implementation.


              Question : What is run() method ?
              Answer : run() method is the job for the thread to execute.


              Note : By defining a thread using the Runnable interface, we separating the thread 
              and JOB of that thread, because thread specific code will be in the thread class and the thread job will be in run() method(which lies in the class that implements the runnable interface).


              Question : What is the meaning of the below code ?
              Answer : line no  10  : public class MyRunnable implements Runnable{
                              line no  20 : public static void main(String[] args) {
                              line no  30 :  MyRunnable r = new MyRunnable();
                              line no  40 : Thread t = new Thread(r);
                      }
              in line-no : 30 we are instantiating Runnable class,  and in Line 40 , passing your
               runnable to thread.
              If you create a thread using a non argument constructor, the thread will call it's own
              run() method, when it's time to start working.But in line 40 we are telling to new thread
              that use my own run method.(job) instead of run() method in thread class when it's 
              time to start working, the runnable you are passing to thread constructor is called the
              target or  target Runnable.
              Note : Passing the same runnable target to different threads means, assigning same job to different threads.


              Question : What are the other constructors in a thread class ?
              Answer : 1)  Thread()  
                             2) Thread(Runnable target)
                             3) Thread(Runnable target,String name)
                             4) Thread(String name)


              Question : When the new stack will allocate for a thread ?
              Answer : A new Stack for thread allocated only when the start() method has been
               invoked on that thread.


              Question : Where the memory for thread will get allocated?
              Answer: Inside the JVM, each thread is awarded a Java stack, which contains data 
              no other thread can access.Including the local variables, parameters and return values
              of each method the thread has invoked.


              Question : What is new state of a thread ?
              Answer : A Thread is created but not yet started means start() method of thread is not 
              yet called.


              Question : What is thread alive ?
              Answer : A thread is alive once the Start() method is called on that thread.


              Question : How long the thread will be alive?
              Answer : Until it completes it's execution i.e.. till finishes it's run(job) method.


              Question : How to assign a job to the thread ?
              Ans : By the The runnable target to the Thread class constructor.
                                                or
                       By extending the thread class.


              Question : What happens when you call the start() method on thread ?
              Answer :   1)  A new thread of execution starts ( with new call stack)
                               2)  The thread moves from the new state to runnable state.
                               3)  When the thread gets the chance to execute it's target run() method
                                    will get called.


              Question : Can i start the completed (or) dead thread again ?
              Answer :   we cannot start the thread once it is dead (by finished executing the
                                run() method) however we can call other methods on that except the
                               start() method.


              Note : One Thread cannot put another thread in sleep.
              Note : The Default priority of the thread is 5 .
              Note : A thread gets the priority of the thread which created this created.


              Question : What is yield() method will do ?
              Answer : So while yield() might—and often does—make a running thread give
               up its slot to another runnable thread of the same priority, there's no guarantee.
              A yield() won't ever cause a thread to go to the waiting/sleeping/ blocking state. 
              At most, a yield() will cause a thread to go from running to runnable, but
              again, it might have no effect at all.


              Question : Is volatile variable is synchronized ?
              Answer : Yes, volatile is the Synchronized variable.


              Question : When should i use the Volatile Variable ?
              Ans: We can declare a variable as volatile, when that variable accessed/modified
              by a multiple threads independently, and asynchronously.


              Question : Explain the difference between the waiting state and blocked state?
              Waiting State : A thread can enter to the Waiting state by calling the wait()
              method (or) by calling the join() method. A Waiting thread can be activated
              by any other thread by using the notify(),notify-all()method. Merely the waiting
              thread is waiting for a call from another thread, (or) for any thread to finish it's job. 
              When a Thread went into waiting state, it relinquishes all it's current locks.


              Blocked State: A thread can enter into this state by calling wait() method. Here 
              thread waits for a signal/semaphore/monitor to come out from wait state.
              When a Thread enters into block state it relinquishes all it's current locks.


              Explain scenario where a Thread enters into Waiting state and blocking state?
              Ans: When thread acquires lock on a object, it releases all it's monitors or locks 
              to enter into the waiting state. And if any other thread notify this thread by calling 
              the notify().notifyall() method. Then this thread try to acquire all the locks (or)
              monitors it previously released. If other thread acquires this monitor (or) lock 
              already then this thread will put in Blocked state.


              Note: A thread which is in blocked state will move directly to running state
              after acquired lock or signal received like semaphore/signal/monitor.
              But, a waiting state thread notified by other thread by notify and notifyall then
              this thread will move to ReadytoRun() state,instead of running method.


              Question : When a Thread enters into dead state from blocked state()?
              Ans: When a thread blocked for I/O socket if that socket is closed by another thread.
              then this thread will move to dead State.
              Question : Where the Yielding thread will go?
              Ans: A yielding thread will go to Ready-to-run Method.
              Question :  What is sleeping state()?
              Ans: When a thread enters into Sleeping state it wont release all the locks it currently 
              hold and once after the elapsed time is over it moves to ready-to-run state().
              Question : What is blocked-on-Synchronization State?
              Ans : A thread may move to this thread, while it is waiting for lock on an Object.
              It enters into ready-to-run() state once it got the object's lock.


              Question : Explain the thread Synchronization concept with an Example ?
              Answer
              Below are the two methods synchronized on the instances they are called on.
              --------------------------------------------------------------------------------------------

              public synchronized void log1(String msg1,String msg2){
              System.out.println(" >>> "+Thread.currentThread().getName());
              System.out.println(" Message 1  "+msg1);
              System.out.println(" Message 1  "+msg2);
              try{
              Thread.sleep(5*60*1000);
              }catch(Exception e){
              e.printStackTrace();
              }
              }
              ----------------------------------------------------------------------------------------------

              public void log2(String msg1,String msg2){
              synchronized(this){
              System.out.println(" >>> "+Thread.currentThread().getName());
              System.out.println(" Message2  "+msg1);
              System.out.println(" Message2  "+msg2);
              }
              }
              -----------------------------------------------------------------------------------------------

              Observation :


              Now create two threads and pass the same instance to the both threads.
              then if one thread executing one synchronized block, another thread can't able
              to execute another synchronized block.Because both blocks having the 
              lock on the instances they are called on.


              IF you call two threads with different instance then two threads can execute 
              parallel...
              Below is the Complete Java Code :
              ....................... ...................... . . . . . . . . . . .. . .. . . . . .. . .....................................

              package newPackage;
              public class LogClass {


              public synchronized void log1(String msg1,String msg2){
              System.out.println(" >>> "+Thread.currentThread().getName());
              System.out.println(" Message 1  "+msg1);
              System.out.println(" Message 1  "+msg2);
              try{
              Thread.sleep(5*60*1000);
              }catch(Exception e){
              e.printStackTrace();
              }
              }

              public void log2(String msg1,String msg2){
              synchronized(this){
              System.out.println(" >>> "+Thread.currentThread().getName());
              System.out.println(" Message2  "+msg1);
              System.out.println(" Message2  "+msg2);
              }
              }
              }
              -------------------------------------------------------------------------------------------
              package newPackage;
              public class Another extends Thread{
              protected LogClass logObject = null;
              public void run(){
              if(Thread.currentThread().getName().equals("ThreadA")){
              logObject.log1("sekhar","Kiran");
              }
              if(Thread.currentThread().getName().equals("ThreadB")){
              logObject.log2("Ravi","Pandu");
              }
              }
              public  Another(LogClass a) {
              this.logObject = a;
              }
              }
              -------------------------------------------------------------------------------------------
              package newPackage;

              public class CreateThread {

              public static void main(String[] args) {
              LogClass a = new LogClass();
              Thread threadA = new Another(a);
              Thread threadB = new Another(a);
              threadA.setName("ThreadA");
              threadB.setName("ThreadB");
              threadA.start();
              threadB.start();
              }
              }
              Good link :
              http://tutorials.jenkov.com/java-concurrency/synchronized.html

              Question : Tell me something about the volatile variable?

              point 1 : The value of the variable never be cached thread -locally.All reads and writes will go
              Straightly to main memory.
              Point 2 : A variable need to declared as volatile, where it value modified by several threads
              Asynchronously.
              Point 3 : Access to this variable is synchronized itself.

              AWS certification question

              AWS AWS Hi! this is for questions related to AWS questions. EC2 instances EC2 storage types cold HDD : 1. Defines performance in terms...