Friday, July 6, 2012

The detailes study of Exception and Errors


The Exception and errors are always problematic in Java.At time if we face such errors we are unable to repair and out total effort is wasted because of some unknown errors occures at runtime.Let us discuss
about these irretating exception and errors in details.


Difference


The Error is occur at run time and can't abe repair at time.Most of the time the errors occurs at time and its JVM erros.It can't be repairable for example out of memory Error


The exception occur because of the user's invalid input.But it possible to recover immediately.These exception are compile time exception.For example File not Found Exception is thrown because of file path has not found means invalid path has given. Another one NullPointerexception means some place in the class expecting some value but value not present in the method so it throws null pointer exception.


Out of memory Exception: 


This exception is thrown when the heap memory is full.


StackoverFlow exception


This exception we get once stack is full of occupied.

Is Java plantform independent? How?


if Java is platform independent then its should run in all the machine without installing any specific software.But it requires to install JVM in all the OS why?Java in platform independent by means of its wonderful byte code conversion and Virtual CPU called JVM.Actually the compiled source code gives the instruction to the CPU to execute the set of programe.But In Java the compiled byte codes give the instruction to the virtual CPU instead of CPU. This Java compiled code gives the instruction to the JVM to execute the set of task.The JVM has installed in all the physical devices.

After the instruction given to Virtual CPU instead of CPU the java designer decided to give all the execution of task in the virtual CPU itself.The virtual CPU finally called as JVM.So if JVM present in the physical system then all the Java program take executed through the JVM. So all the platform dependent code into the JVM.This is totally differ from the Turbo C compiler the turbo c generate the platform dependent code and execute the task through the CPU.But in Java all the task execute through the Virtual CPU.

In Java all the platform dependent code has written in Java Virtual Machine.So finally JVM directly  communicated to the CPU and execute the task which is know as platform independent.This means no matter which physical platform its running.But lot of way is there to break JVM and run platform independent. Java means portability but we can break the java code to act Java as a platform dependent

Thursday, July 5, 2012

Complete details about mutable and immutable


The detailed study about the mutable and immutable objects.


Basic definition:


Mutable 


if the object "value" is editable or changeable those objects are mutable objects.Example String buffer.


Immutable 


if the object value is not changeable or editable those objects are immutable object.Example String and
all wrapper classes like Integer,Float etc..,


How to make an object immutable


Rules:


1.Mark the object as private
2.Dont provide an mutators.
3.Make sure that method should not overridden by any other class by making class final(Strong immutability) also making method as final(weak immutability)
4.if the field is not declared with private or immutable make deep clone by making way in and way out


Problem and solution for making Immuatable object


If the field is having mutable object themself then we its create the problem while making object as immutable.


Solution


Just provide the getter method that getter method supposed return the
mutable object and it will return the clone of original object.

Study about Final Finally finalize in Java


The complete detaile study of Java Final ,Finally and Finalize key words.


Final 
Final is the key word in Java and it can be added before variable method and class as well.


Final Variable
if the final keyword added for variable the variable can become constant.


Example:


Inside the program if user try to change the a value as 20 it will through an exception.


Final method
if the method has declared with final keyword it can not be override.


Final class
if the class has declared with final keyword the class will hot be inherited which means it cant be sub classed.


Finally 
Finally is the keyword in Java.Finally always used along with Try catch. Finally is used when the exceptions caught or not still Finally will be executed. The purpose of finally key word is always it will execute along with try block even thought exception is caught or not.


Example 






This program explained like here always i want to execute some information along with try block or user needs to confirm my try block executed successfully.


Finalize


Java does not have destructor this job will taken care by garbage colletor.Garbage collector will do cleanup process periodically if the object no longer called by any thread. when the periodically clean up the object at the time finalize method will be called by Garbage collector.But no body sure when the garbage collector called the finalize method. This works with mark and sweep algorithm.

Thursday, March 15, 2012

Static word Magic in Java

Static keyword sensation in java In Java static keyword plays major role and its the strong memory allocation. The Java provides the static as the one time initialization.It deals with memory once.
For example once the variable of class has declared as static one permanent memory will be allocated in heap memory.
Even when ever the new variable has created for the class the instance of the class will be same.
So its called as one time initialization.
Static can be used in Method, Class, Variable.
Lets see the difference of static class and static variable and static methods.
One the static class declared we can access the class using its name without creating the instance of the class because it has one time initialization.
Once the variable has declared with static then the variable value is single and never be dynamic
Once the method is declared with static the same method we can access using the class name anywhere. This is the simple majic about the static keyword in java.

Wednesday, March 14, 2012

how to lock the thread free and safe based on double linked list

how to lock the thread free and safe based on double linked list Here is the solution it tired. Please have the solution and let me know the comments of your idea how to implement the efficient way if any

How to add the skin for applet application.

How to add the skin for applet application. There is a lot of way we can add the skin for applet application. The one way is that the SyntheticaAddons. Its available in exe file application.Need to install this application and apply the skin just copy and paste the jar. here is the link given to go to synthetica tool http://www.jyloo.com/syntheticaaddons/

Data Structure Interview Question.

Data Structure Interview Question. How to find the loop in the linked list? or how to connect the linked list? here is the solution. The three way solution provided in the below link. Its really useful and highly efficient way of solve the problem http://ostermiller.org/find_loop_singly_linked_list.html

Tuesday, March 13, 2012

What are the frequent interview questions about XML parser? Difference between two xml parsers? when will use what parser?

What are the frequent interview questions about XML parser? Difference between two xml parsers? when will use what parser?
Answer: There are two main parser in SAX and DOM are most popular parser to process the xml file in java.
Read and Write Difference: SAX: This parser can only used for reading the xml document but not manupulating the data in xml document. DOM: This parser can read and manupulate data in xml document.
Sequential Access and Random Access: SAX can be accessed sequentially to process the xml document and DOM can be accessed ramdomly to process the xml document. Call back mechanism and Tree: SAX uses call back mechanism and event stream to process sequentially the large amount of xml data. wheras DOm procees the tree structure of ramdom access of large amount of data.
Information set: SAX doesn't retain all the information comment in xml document but DOM will retain all the comments located in the xml document.
Speed and Memory of both parsers: SAx is much faster than compared to any other parser DOM is slower due to save all the xml data into single memory.

Monday, March 12, 2012

What is the purpose of ^(carret operator) this operator in java

What is the purpose of ^(carret operator) this operator in java The carret operator doesn't mean the exponentiation.But its means the exclusive-or means "XOR" operation in java. This will do XOR operation for the given value Please look the below example.

Thursday, December 3, 2009

Servlets Interview Question

What is the difference between the getRequestDispatcher(String path) ServletRequest interface and ServletContext interface?

The getRequestDispatcher(String path) method of ServletRequest interface accepts parameter the path to the resource to be included or forwarded to, which can be relative to the request of the calling servlet. If the path begins with a "/" it is interpreted as relative to the current context root.

The getRequestDispatcher(String path) method of ServletContext interface cannot accepts relative paths. All path must sart with a "/" and are interpreted as relative to curent context root. If the resource is not available, or if the server has not implemented a RequestDispatcher object for that type of resource, getRequestDispatcher will return null. Your servlet should be prepared to deal with this condition.

What is the use of ServletContext ?

Using ServletContext, We can access data from its environment. Servlet context is common to all Servlets so all Servlets share the information through ServeltContext.

Is there any way to generate PDF'S dynamically in servlets?

We need to use iText. A open source library for java. Please refer sourceforge site for sample servlet examples.

What is the difference between using getSession(true) and getSession(false) methods?

getSession(true) - This method will check whether already a session is existing for the user. If a session is existing, it will return that session object, Otherwise it will create new session object and return taht object.

getSession(false) - This method will check existence of session. If session exists, then it returns the reference of that session object, if not, this methods will return null.

 Advertisement

  1

2

3

Servlets Interview Question

Which code line must be set before any of the lines that use the PrintWriter?

setContentType() method must be set.

Which protocol will be used by browser and servlet to communicate ?

HTTP

In how many ways we can track the sessions?

Method1) By URL rewriting

Method2) Using Session object

Getting Session form HttpServletRequest object
HttpSession session = request.getSession(true);

Get a Value from the session
session.getValue(session.getId());

Adding values to session
cart = new Cart();
session.putValue(session.getId(), cart);

At the end of the session, we can inactivate the session by using the following command
session.invalidate();

Method 3) Using cookies

Method 4) Using hidden fields

How Can You invoke other web resources (or other servlet / jsp ) ?

Servelt can invoke other Web resources in two ways: indirect and direct.

Indirect Way : Servlet will return the resultant HTML to the browser which will point to another Servlet (Web resource)

Direct Way : We can call another Web resource (Servelt / Jsp) from Servelt program itself, by using RequestDispatcher object.

You can get this object using getRequestDispatcher("URL") method. You can get this object from either a request or a Context.

Example:
RequestDispatcher dispatcher = request.getRequestDispatcher("/jspsample.jsp");
if (dispatcher != null)
dispatcher.forward(request, response);
}

How Can you include other Resources in the Response?

Using include method of a RequestDispatcher object.

Included WebComponent (Servlet / Jsp) cannot set headers or call any method (for example, setCookie) that affects the headers of the response.

Example : RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/banner");
            if (dispatcher != null)
            dispatcher.include(request, response);
}

  1

2

3