Thursday, September 18, 2014

How to resolve merge conflicts after git rebase ?

Have you faced a merge conflict while performing git rebase operation ? This is quite possible  if two commits modify the same line in the same file. Now git is confused which change to apply.
Git gives us several options in such a case :
  • git rebase --continue
  • git rebase --abort
  • git rebase --skip
1. git rebase --continue
Used in case if you have manually corrected the conflicted files. So after resolving the merge issues manually , use command rebase --continue so that git can continue processing the rest of the rebase.

2. git rebase --abort
Use this command if you want to completely undo the rebase. So the branch will return to the state that was before rebase was called.

3. git rebase --skip
Used to completely skip the commit. None of the changes introduced by the commit will be included.

Happy Learning !!!


Monday, September 1, 2014

How to open or Untar a ".tar.gz" file in Ubuntu ?

Lets say that the name of file is - test.tar.gz
  1. From the terminal, change to the directory where tar file is located.
  2. Now to extract the file to the current directory , run the command 
  3.  tar -zxvf test.tar.gz

    To extract the file to a specific directory , run
    tar -C /directory_name -zxvf test.tar.gz

    NOTE : The extensions .tgz and .tar.gz are equivalent and both signify that a tar file zipped with gzip.
How to Untar a ".tar" file ?
  1. From the terminal, change to the directory where tar file is located.
  2. Now to extract the file to the current directory , run the command 
  3. tar -xvf test.tar

    To extract the file to a specific directory , run
    tar -C /directory_name -xvf test.tar

Tar Usage and Options
  • c – create a archive file.
  • x – extract a archive file.
  • v – show the progress of archive file.
  • f – filename of archive file.
  • t – viewing content of archive file.
  • j – filter archive through bzip2.
  • z – filter archive through gzip.
  • r – append or update files or directories to existing archive file.
  • W – Verify a archive file.
  • wildcards – Specify patters in unix tar command.
 


     

Thursday, May 1, 2014

How to amend the last commit in Git ?


Have you ever faced a situation where you left something out of your last commit ? It may be a file or an extra change to a file you just committed. 

Such kind of scenarios can easily be handled with Git amend command .

How does it work ?
1. Just add the file using git add ( Like what we do for         normal commit ).
    git add <file>

2. Now commit the changes with -amend argument.
    git commit --amend

    If you don't specify a commit message with -m , git picks the previous commit message as    a default.

How to see the amended commit ?
We can use git log --stat to see the amended commit with extra change .

You can also see this page for more information on git commit.

Tuesday, April 29, 2014

Unbound Classpath Variable M2_REPO error in Eclipse

Problem Description :

My Eclipse IDE gives errors whenever I try to build the project . The problems tab shows the message as given below

Unbound classpath variable: 'M2_REPO/...'



Solution :
M2_REPO is a classpath variable that tells eclipse where maven repository is on your disk .


Setting M2_REPO 

  • Open Eclipse Preferences [Window -> Preferences]
  • Go to [Java -> Build Path -> Classpath Variables]
  • Click New and set its name as M2_REPO
  • Click Folder and select your Maven repository directory on your machine . For example,on my machine , its H:\WDP\.m2\repository
  • Rebuild the Project.
  • DONE.








Sunday, March 30, 2014

What is JDBC RowSet ?

A RowSet ( javax.sql.RowSet ) is an object that encapsulates a set of rows from either Java Database Connectivity (JDBC) result sets or tabular data sources like a file or spreadsheet. RowSets support component-based development models like JavaBeans, with a standard set of properties and an event notification mechanism.

Interfaces that extends RowSet are  :
  • JdbcRowSet
  • CachedRowSet
  • WebRowSet
  • JoinRowSet
  • FilteredRowSet

Benefits :
Beside sharing the capabilities of a ResultSet , RowSet adds the following new capabilities :

1.  Function as JavaBeans Component
That means RowSet objects have properties with corresponding getter and setter methods that can be exposed to builder tools (such as those that come with the IDEs JDveloper and Eclipse) that provides the capability to visually manipulate the beans.

In addition , RowSet objects use the JavaBeans event model, in which registered components are notified when certain events occur. The events that trigger notifications are :
  • A cursor movement
  • The update, insertion, or deletion of a row
  • A change to the entire RowSet contents

2.  Add Scrollability or Updatability
If a database driver does not have the ability to scroll or update result sets, RowSet object can be used for the same . A RowSet object is scrollable and updatable by default, so by populating a RowSet object with the contents of a result set, you can effectively make the result set scrollable and updatable.


Types of Rowset :
There are two types of RowSet :
  • Connected - A connected RowSet object connects to the database once and remains connected until the application terminates. Only one of the standard RowSet implementations is a connected RowSet object - JdbcRowSet.
  • Disconnected - A disconnected RowSet object connects to the database, executes a query to retrieve the data from the database and then closes the connection. A program may change the data in a disconnected RowSet while it is disconnected. Modified data can be updated in the database after a disconnected RowSet reestablishes the connection with the database.Disconnected RowSet objects are lightweight and  serializable, and it makes them ideal for sending data over a network. They can even be used for sending data to thin clients such as PDAs and mobile phones.

Saturday, March 29, 2014

How to run a standalone OSGi server

This post shows how to run Equinox as an OSGi stand-alone runtime.

Download org.eclipse.osgi_.jar from here. The same jar exists in eclipse installation directory ( plugin folder ). Copy the jar and paste into a new directory.
Example - C:\osgi\org.eclipse.osgi_3.9.1.v20140110-1610.jar

Starting the OSGi server :
java -jar org.eclipse.osgi_3.9.1.v20140110-1610.jar -console                                                                                                                
starting osgi server

Basic commands to start with :
  • install - Installs the bundle from the given URL
  • start - Starts the bundle with the given numeric or symbolic id.
  • stop - Stops the bundle with the given numeric or symbolic id.
  • ss - Reports a summary status of all installed bundles
  • diag - Reports any resolution problems for the bundle with the given numeric or symbolic id.

Understanding the JDBC architecture.

The JDBC API uses a driver manager and database-specific drivers to provide transparent connectivity to heterogeneous databases.

The JDBC driver manager ensures that the correct driver is used to access each data source.



      
The JDBC Architecture consists of two layers:
  • The JDBC API , which provides the application-to-JDBC Driver Manager connection.
  • The JDBC Driver API , which supports the JDBC Manager-to-Driver Connection.

JDBC Architecture

Thursday, February 27, 2014

java exception interview questions and answers

What is Exception in Java ?
An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions. When an error occurs within a method, the method creates an object and hands it off to the runtime system. The object, called an exception object, contains information about the error, including its type and the state of the program when the error occurred. Creating an exception object and handing it to the runtime system is called throwing an exception.

What happens when a method throws an exception ?
After a method throws an exception, the runtime system attempts to find an exception handler to handle it. The search begins with the method in which the error occurred and proceeds through the call stack in the reverse order in which the methods were called. When an appropriate handler is found, the runtime system passes the exception to the handler. If the runtime system is unable to find an appropriate exception handler,the runtime system terminates.

For example : Suppose the main method calls a method named A . A calls B and B calls a method C . C method throws exception . The problem can be described with the below diagram .



We can understand this in the steps given below :
  1. Exception occurs at method C() . The method creates an exception object and gives it to the runtime system. 
  2. The runtime system starts looking for a matching exception handler . The search starts from method C() but because it does not provide any exception handler , the call propogates down the call stack. 
  3. The runtime system looks for a handler in method B() . B also does not provide any handler so the call propagates down the call stack. 
  4. A() provides a try/catch block that catches the type of exception that was thrown by C() so runtime system passes the exception to this handler.
Explain Java Exception Hierarchy ?
The top level class in exception hierarchy is Throwable. Error and Exception extends from Throwable. Errors are the conditions that can't be recovered from so they are not handled by a java program. Exception is further extended by RuntimeException.

java exception hierarchy


What are important methods of Java Exception Class?
Below are some important methods of Exception class :

public String getMessage() 
Returns a detailed message about the exception that has occurred. This message is initialized in the Throwable constructor.

public Throwable getCause() Returns the cause of the exception as represented by a Throwable object. 

public String toString() Returns the name of the class concatenated with the result of getMessage()

public void printStackTrace() Prints the result of toString() along with the stack trace to System.err, the error output stream.

public StackTraceElement[] getStackTrace() Returns an array containing each element on the stack trace. The element at index 0 represents the top of the call stack, and the last element in the array represents the method at the bottom of the call stack.

public Throwable fillInStackTrace() Fills the stack trace of this Throwable object with the current stack trace, adding to any previous information in the stack trace.

What is OutOfMemoryError in Java?
OutOfMemoryError is when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector. OutOfMemoryError in Java is a subclass of VirtualMachineError.

What is the concept of multi-catch block ?
In multi-catch block , we can catch multiple exceptions in a single catch block.

Benefits : This feature can reduce code duplication and lessen the temptation to catch an overly broad exception.

Example : 
Without multi catch
catch (IOException ex){
       logger.log(ex);
       throw ex;
}
catch (SQLException ex){
       logger.log(ex);
       throw ex;
}

With multi catch
catch(SQLException | SQLException ex)
{
       logger.log(ex);
       throw ex;
}

What is difference between Checked and Unchecked Exception in Java?


Checked exeptions unchecked exceptions
Checked Exceptions follows handle or declare rule. so a method throwing a checked exception should either handle it using try-catch block or decalare it in method signature using throws keyword.Unchecked Exceptions are not required to be handled in the program or to mention them in throws clause.
Exception is the super class of all checked exceptions.RuntimeException is the super class of all unchecked exceptions.
Checked exceptions are error scenarios that are not caused by program, for example FileNotFoundException in reading a file that is not present.Unchecked exceptions are mostly programming bugs , for example NullPointerException when invoking a method on an object reference without making sure that it’s not null.


What is difference between throw and throws keyword in Java?
throws is as much a part of the method signature . Clients know if they call that method, they need to handle that exception by simply throwing it or by catching it and handling it . throws is addressed at compile time. 

public void getUserDetails() throws SQLException{
       // code
 }

throw is the actual act of letting the runtime know that something bad has happened and allows to through the exception manually.

 public public void getUserDetails() {
     if(!user.exists()) {
           throw UserNotFoundException("User does not exists in database");
     }
 }

What happens when exception is thrown by main method?
When exception is thrown by main , Java runtime system terminates.

Can we have the try block without catch or finally block?
NO . try block must have a catch or finally associated with it.

What is difference between ClassNotFoundException and NoClassDefFoundError?
ClassNotFoundException is thrown when an application tries to load in a class through its string name using:
  • The forName method in class Class. 
  • The findSystemClass method in class ClassLoader . 
  • The loadClass method in class ClassLoader.
but no definition for the class with the specified name could be found.

NoClassDefFoundError is thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

What is StackOverflowError?
StackOverflowError error is thrown by JVM when it encounters that there is no memory left in the stack to store variables . Parameters and local variables are allocated on the stack . The common cause for a stack overflow is a bad recursive call. Typically this is caused when your recursive functions doesn't have the correct termination condition, so it ends up calling itself for ever.

What does 'Ducking' the exception mean?
If a method does not handle the exception but simply declares it using throws , the method is said to be ducking the exception.


Tuesday, February 25, 2014

Servlet interview questions

What is a Servlet ?
Servlet can be defined in two ways :
  • As a technology 
  • From web application point of view 
As a technology , servlet represents an API that is partially implemented by application programmers and partially by web server vendors. From web application point of view, Servlet is a java class that is executed by web server to generate dynamic contents.


What is the hierarchy of servlet api ?
The central abstraction in the Servlet API is the Servlet interface. All servlets implement this interface, either directly or , by extending a class that implements it. The implementations of Servlet interface are javax.servlet.GenericServlet andjavax.servlet.http.HttpServlet. Below diagram shows the hierarchy of servlet.




What are the uses of Servlet ?
Typical uses for Servlets are :
  • Processing and/or storing data submitted by an HTML form. 
  • Providing dynamic content, e.g. returning the results of a database query to the client. 
  • Manage state information that does not exist in the stateless HTTP protocol, such as filling the articles into the shopping cart of the appropriate customer

What are the advantages of Servlet over CGI ?
  • In CGI based application, a new process is created for each request . A lot of overhead is involved in creation and destruction of processes . In Servlet , a new thread is created to process a request. 
  •  CGI scripts were platform dependent but Servlet is not. 
  •  A Servlet stays in memory between requests. A CGI program (and probably also an extensive runtime system or interpreter) needs to be loaded and started for each CGI request.

Define servlet life cycle.
  1. Servlet class loading 
  2. Servlet instantiation 
  3. Initialization init() 
  4. Request handling service()
  5. Removal from service destroy()
Step 1, 2 and 3 are executed only once, when the servlet is initially loaded. By default the servlet is not loaded until the first request is received for it.
Step 4 is executed for every HTTP request to the servlet .
Step 5 is executed when the servlet container unloads the servlet.

Why do we need a constructor in a servlet if we use the init method ?
The purpose of init is to initialize the Servlet but before that container needs an instance of the servlet .Constructor is used for the same purpose.


How the servlet is loaded ?
A servlet can be loaded in the following ways : 
  • When the first request for the servlet comes. 
  • At the time of server startup.
How a Servlet is unloaded ?
A Servlet gets unloaded when : Administrator manually unloads the servlet. Server shuts down.


What is the GenericServlet ?
GenericServlet is an abstract class that implements the Servlet interface and the ServletConfig interface. It is named GenericServlet because the class is protocol independent. GenericServlet makes writing servlets easier.
This class also provides simple versions of the lifecycle methods init and destroy and of the methods in ServletConfig interface. It also implements the log method declared in the ServletContext interface.


What is the difference between GenericServlet and HttpServlet ?
Below table shows the differences between GenericServlet and HttpServlet .


GenericServletHttpServlet
GenericServlet is an abstract class that implements the Servlet interface and the ServletConfig interface. An abstract class that simplifies writing HTTP servlets. It extends the GenericServlet base class and provides an framework for handling the HTTP protocol.
GenericServlet is not specific to any protocol.HttpServlet only supports HTTP and HTTPS protocol.


Why is HttpServlet declared as abstract ?
HttpServlet is abstract because the http handler methods in HttpServlet does nothing and must be overridden. The implementation of service method has provided convinience that not all http handlers methods needs to be implemented.
For example if your custom servlet is required to handle the GET request , just implement doGet() method and there is no need to implement the doPost().

Can servlet have a constructor ?
YES , servlet can have a constructor and we can perform operations with that constructor as we normally do.The only thing is that it can not be called explicitly with the new keyword. Servlet container is responsible for instantiating a servlet , so the constructor is only called by the container only.

What are the types of protocols supported by HttpServlet ?
HttpServlet is specifically made for HTTP protocol so it can only suppory HTTP and HTTPS protocols.


What is the difference between doGet() and doPost()?
Below table shows the differences between doGet() and doPost()


doGet()doPost()
The request parameters gets appended to the URL hence visible in address bar.Request parameters are sent as a part of body so are not visible.
Limited data can be sent as request parameters are sent as a part of header and size of http header is fixed.Unlimited data can be sent because request parametrs are sent as part of the body.
Parameters are not encrypted.Parameters are encrypted.
GET request pages can be cached ( Allows bookmarking ).Disllows bookmarking.
GET request should be idempotent i.e repeating the request over and over again should not have any side effect.POST request does not need to be idempotent


When to use doGet() and when doPost()?
As we have seen the differences between a GET and POST request , we should prefer using GET requests apart for the scenarios mentioned below. Use POST if data is sensitive. Use POST if the size of data is greater than 1024 characters.

Can we support both GET and POST from the same Servlet ?
YES .

Can we override the service() method ?
YES we can but we should not . If a class overrides the service() method , then it will have to provide its own implementation for detecting the method type ( GET or POST ) of incoming request , and then invoking the corresponding handler method such as doGet or doPost.

What is a servlet context ?
ServletContext provides an interface of the servlet container to the servlets of an application. It means that the servlets communicates with the servlet container through ServletContext object. Foe example - to get MIME type of a file , dispatch requests or write a log file. There is only one context per web application per java virtual machine.

What are the differences between the ServletConfig and ServletContext ?
Below table shows the differences between ServletConfig and ServletContext.


ServletConfigServletContext
The ServletConfig interface is implemented by the servlet container in order to pass configuration information to a servlet. The server passes an object that implements the ServletConfig interface to the servlet's init() method.A ServletContext defines a set of methods that a servlet uses to communicate with its servlet container.
There is one ServletConfig per servlet.There is one ServletContext for the entire webapp and all the servlets in a webapp share it.

What are the differences between forward() and sendRedirect()?
Below table shows the differences between forward and sendRedirect


forwardsendRedirect
A forward is performed internally by the servlet.A redirect is a two step process, where the web application instructs the browser to fetch a second URL, which differs from the original.
Both resources must be part of the same context.This method can be used to redirect users to resources that are not part of the current context, or even in the same domain.
Forward is marginally faster than redirect.Redirect is marginally slower than a forward, since it requires two browser requests, not one.
Request is forwarded to a new servlet so the request objects remains the same.A completely new request is sent by the browser so the request object changes.
The original URL does not changes.The browser is making a new request , so the URL changes .


What is the difference between the include() and forward()?
Below table shows the differences between include and forward 


includeforward
include() method inserts the contents of the specified resource directly in the flow of the servlet response.forward() forwards the request to another resource in the same context . Response is generated by the same servlet.
Included resource must not attempt to change the response status code or http headers. Any such attempt will be ignored.forwaded resource may be another servlet, jsp or a static html document but the response is issued under the same URL that was originally requested.

What are wrapper classes and what is their purpose ?
The wrapper classes can be used to create custom implementations of the servlet request and response types. The classes are constructed with the standard HttpServletRequest and HttpServletResponse instances respectively and their default behavior is to pass all method calls directly to the underlying objects.

HttpServletRequestWrapper and HttpServletResponseWrapper are the servlet wrapper classes.

What is a deployment descriptor ?
Deployment descriptor ( DD ) is an xml file that defines component's deployment settings. The information provided by the deployment descriptor is declarative and therefore can be modified without changing the source code. The server reads the DD at runtime and acts upon the components accordingly.

What is the difference between the getRequestDispatcher(String path) method of ServletRequest interface and ServletContext interface ?
The getRequestDispatcher(String path)of ServletRequest accepts the relative path , relative to the current servlet. On the other hand, the same method in ServletContext can't accept relative paths . All the paths must start with "/" and are interpreted as relative to the current context root.

What is preinitialization of a servlet ?
Container does not initialize the servlets as soon as it starts up, it initializes a servlet when it receives a request for that servlet first time. This is called lazy loading. The servlet specification defines the element, which can be specified in the deployment descriptor to make the servlet container load and initialize the servlet as soon as it starts up. The process of loading a servlet before any request comes in is called preloading or preinitializing a servlet.

What is the  <load-on-startup> element ?
The  element of a deployment descriptor is used to load a servlet file when the server starts instead of waiting for the first request. It is also used to specify the order in which the files are to be loaded. The  element is defined in deployment descriptor ( web.xml ).

<servlet>

   <servlet-name>name</servlet-name>
   <servlet-class>class</servlet-class>
   <load-on-startup>1</load-on-startup>
</servlet>

What is servlet lazy loading?
Container does not initialize the servlets as soon as it starts up, it initializes a servlet when it receives a request for that servlet first time. This is called lazy loading.

What is Servlet Chaining?
Servlet Chaining means the output of one servlet act as a input to another servlet. Servlet Aliasing allows us to invoke more than one servlet in sequence when the URL is opened with a common servlet alias. The output from first Servlet is sent as input to other Servlet and so on. The Output from the last Servlet is sent back to the browser. The entire process is called Servlet Chaining.

What are the functions of the Servlet container?
The various functions of a servlet container are :
Lifecycle Management
Container is responsible for managing the life cycle of the servlets.

Communication Management
Servlet container manages the communication between webserver and a servlet.

Multithreading support
Container creates a new thread each time a new request comes for a servlet.

Declarative Security
Servlet container manages the security through deployment descriptor file.

JSP Support
Servlet container is responsible for translating JSPs into servlets and maintaining them.

Monday, February 24, 2014

Object Oriented Programming ( OOP ) concepts interview questions

What is an Object ? 
Well It is the most basic concept and a key to understand the Object-Oriented programming . Object is an entity that has two characteristics , State and Behavior . Some examples of real world object can be : Bike , Chair , Dog etc. Lets take an example of a Bike . Bike has some state ( current gear , current speed ) and behavior ( change gear , apply brake ) . One way to begin thinking in an object-oriented way is to identify the state and behavior of real world objects . Software objects are also similar to the real world objects. They too contains State and Behavior . An Object stores its state in fields and exposes the behavior through methods.

What is Class ? 
Class is a blueprint from which objects of same type can be created . Lets take an example of a Bike again . There are thousands of bikes with the same characteristics i.e having same make and model . They are created from the same prototype / blueprint called class.

What are the principles concepts of OOPS? 
The principle concepts of OOPs are :

  • Inheritance 
  • Polymorphism
  • Abstraction 
  • Encapsulation
What is Inheritance? 
Inheritance is the capability of one class to acquire the common state and behavior of another class while adding its own functionality . In Object Oriented programming , the concept of inheritance provides the idea of re-usability . This means we can add additional features to a class without modifying it. 

How to achieve Inheritance in Java ? 
extends keyword is used to inherit features of a class .

What is Polymorphism? 
Polymorphism means ability of one type to take more than one form . This can also be applied in Java where in sub-classes of a class can define their own unique behaviors and yet share some of the common functionalites of the parent class. 
Example : Lets take an example of Bike . A company can produce different kind of bikes say , a mountain bike , and a roadbike . Now the two different types of bikes inherit the common features of a bike but also define their own separate features. 

How to achieve Polymorphism in Java ? 
Overloading and Overriding are the two ways to achieve Polymorphism.

What is Abstraction? 
Abstraction is an essential element of Object Oriented programming . It refers to the act of presenting essential features without including the background details or explanations. We can say that abstraction is purposeful suppression , hiding of some details of a process or artifact , in order to bring out more clearly other aspects , details or structures. Abstraction can be of control ( abstraction of actions ) or data . 

How to achieve Abstraction in Java ?
Abstract classes and Interfaces are used to achieve Abstraction in Java.

What is Encapsulation?
Encapsulation is the binding of data and its associated functions in a single unit called Class . Access to the code and data inside the wrapper is tightly controlled through a well defined interface. Encapsulation provides a protective barrier that prevents the access of code and data from outside the class. 

The main benefit of encapsulation is the ability to re-factor the implemented code without breaking the code of others and thus provides flexibility and maintainability.

What is the difference between abstraction and encapsulation? 
The two concepts are distinct , but closely related and are often found together. 

  • Abstraction focuses on the outside view of an object and hides any unnecessary detail while Encapsulation provides a protective barrier that prevents the access of code and data from outside the class. 
  • Abstraction solves the problem in the design side while Encapsulation is the Implementation and infact I would say that Encapsulation in effect provides Abstraction.


Explain the different types and forms of Polymorphism. 
Polymorphism is of two types i.e Compile time and run time polymorphism. Compile time polymorphism is method overloading. Runtime time polymorphism is done using inheritance and interface. 

Different forms of polymorphism are - Method overloading and  Method overriding ( through inheritance and interfaces ).

What is runtime polymorphism or dynamic method dispatch? 
In Java, runtime polymorphism is a process in which call to an overridden method is resolved at runtime rather than at compile-time. The overridden method is called through the reference variable of the superclass but the determination of actual method to be invoked is based on the type of object created at run time.

What is Dynamic Binding? 
Resolving the actual method to be invoked on basis of a method call is called Binding.Methods can be resolved at compile time or run time. 
Types of binding are : 

  • Static binding ( early binding ) - Method call is resolved at compile time.
  • Dynamic binding ( late binding ) - Method call is resolved at run time.
What is method overloading? 
Defining multiple methods with same name in the same class but different arguments is overloading . The benefit of method overloading is that it allows you to implement methods that support the same semantic operation but differ by argument number or type.
Important points about Overloading :

  • Overloaded methods MUST change either the number of arguments or the type of arguments. 
  • Overloaded methods CAN change the access modifier. 
  • Overloaded methods CAN declare new or broader checked exceptions.
  • A method can be overloaded in the same class or in a subclass.
What is method overriding? 
Method overriding occurs when sub class declares a method that has the same type arguments as a method declared by one of its superclass. The key benefit of overriding is the ability to define behavior that’s specific to a particular subclass type. The overriding method cannot have a more restrictive access modifier than the method being overridden. The overriding method cannot have more restrictive access modifier. The subclass can not override a method marked final or static.

What are the differences between method overloading and method overriding?
Below table shows the differences :
ParametersOverloadingOverriding
ArgumentsMust changeMust not change
Return typeCan changeCan’t change except for covariant returns
ExceptionsCan changeCan reduce or eliminate. Must not throw new or broader checked exceptions
AccessCan changeMust not make more restrictive (can be less restrictive)
InvocationReference type determines which overloaded version is selected. Happens at compile time.Object type determines which method is selected. Happens at runtime.

Can we override already overloaded method ? 
YES , sub classes can override the overloaded methods.

Is it possible to override the main method?
Static method can't be overridden in Java.