Showing posts with label interview. Show all posts
Showing posts with label interview. Show all posts

What is Universal Superclass in Java ?

Universal Superclass
--------------------
All the classes which we define are subclasses by default. All the classes have a standard classes called Object as a base class . So Object is a superclass of every class . We don't need to specify the class Object as a base in the definition of our class . It is automatically inherited that is our class will inherit members from the class Object . Object class have seven public methods and two protected methods

Public methods are :
--------------------
1. toString() - returns the String object of the current object.
2. equals() - compares the object passed as an argument with current object, returns true if they are equal.
3. getClass() - returns a object of type Class.
4. hasCode()- calculates the hash code value for an object & returns as a type int.
5. notify() - to wake up a thread associated with the current object.
6. notifyAll() - to wake up all threads associated with the current object
7. wait() - causes a thread to wait for a change in the current object.

Two Protected methods are :
---------------------------
1. clone() - creates an object that is a copy of the current object.
2. finalize() - is called to clean up as an object is destroyed.
Read more...

How JSP Functions ? Lifecycle of JSP .

Java Server Page (JSP) is a serverside program that is similar in design and functionality to JAVA Servlet . JSP program consists of a compination of HTML tags and JSP tags. JSP tags define Java code that is executed before the output of the JSP progam is sent to the browser.

How JSP functions or Lifecycle of JSP?
When a client requests a jsp , First time JSPs are converted into servlets and then compiled before they get executed. The code inside the JSP gets placed into the converted servlets service() method.

JSP has three methods which is automatically called when a JSP is requested.

1. jspInt() 2. jspDestroy() 3. sevice()

1. jspInt() : similar to init() method of a Servlet :- when a JSP is requested , jspInt() is called first.

2. jspDestroy() : similar to destroy() method of a servlet :- automatically called when a JSP terminates. can be used to cleanup the resources used during the execution (eg. disconnecting from database )

3. service() : similar to service() method :- automatically called and makes HTTP connection.
Read more...

Why Java is Secured than other languages?

The Output of C, C++' s compiler is Executable code. But Java complier convert the Java code into byte code (.class file) and these byte codes are then run by Java Virtual Machine (jvm) . JVM is an interpreter which is installed in each client machine that is updated with latest security updates by internet . When this bytecodes are executed , the jvm can take care of the security. So, java is said to be more secure than other programming languages.

Translating the java program into bytes code makes it easier to run a program in variety of environments. For this the JVM needs to be implemented for each platform. The JVM provides a secure runtime environment by managing memory, etc. The dynamic way in which the JVM allocates the various memory areas means that it is almost impossible for a would-be attacker to determine what memory areas to attempt to insert malicious instructions into. Bounds checking on arrays prevent unreferenced memory accesses.
Read more...

 
Copyright 2011 Java Online