Java technical interview and answer - java job interview

          

Java technical interview by Rupali Kapil


Explain how to send data from my Java program to a CGI program.
When should we use an event adapter class?
Can you explain in brief life cycle for stateless and stateful beans?
How can we use beans in JSP?
Explain widening conversion and Narrowing conversion.
What is a StringBuffer class and how does it differ from String Class?
How does the native language C or C++ understand data types in JAVA?
Difference between Tomcat and Weblogic server.
Explain different Authentication Options available in Servets
How do I read a line of input at a time in Java?

Explain how to send data from my Java program to a CGI program.

There are two methods of sending data from Java program to a CGI Program:

a.) The first method is that we can use CGI scripting on both client and server by using Java.

 The client-side part covers using GET and POST from applets to talk to CGI programs. The server-side part covers implementing CGI programs in Java that handle GET and POST (regardless of whether the client uses HTML forms or applets), and also includes a URL decoder and CGI form parser in Java.

b.) The second method is by using Servlets and JSP.

Servlets are Java technology's answer to CGI programming. They are programs that run on a Web server and build Web pages. Java servlets are more efficient, easier to use, more powerful, more portable, and cheaper than traditional CGI and than many alternative CGI-like technologies.

Java Server Pages (JSP) is a technology that lets you mix regular, static HTML with dynamically-generated HTML. Many Web pages that are built by CGI programs are mostly static, with the dynamic part limited to a few small locations.

When should we use an event adapter class?

A listener’s class has to implement Listener interface which means all the methods of the interface must be defined in the class. This will become a tedious work when we have many methods in interface and we want to implement only one method. For this we have to define all the methods in a class. So to avoid this type of situation we use Event adapter class. The event listener interfaces that contain more than one method have a corresponding event adapter class that implements the interface and defines each method in the interface with an empty method body. Instead of implementing an event listener interface, you can extend the corresponding event adapter class and define only those methods in which you are interested.

The WindowAdapter class is an example of an event adapter class. It implements WindowListener, and defines its seven methods with empty method bodies. 

Can you explain in brief life cycle for stateless and stateful beans?

Stateless Session Bean Lifecycle:
The stateless session bean does not become passive, so its life cycle has two stages:
1. Does Not Exist: In this stage bean has not been instantiated.
2. Method Ready pool: In the Method Ready Pool stage bean has instances in the memory of the EJB container and it is ready to serve clients. On the startup of the EJB container some instances of the bean are created and placed in the pool. EJB container creates the new instance of the Bean and then sets the session context (setSessioncontext()) and it calls the ejbCreate() method to place the bean in the Method Ready Pool stage. Container calls the ejbRemove() method to move the bean into Does Not Exist state.

Stateful Session Bean Lifecycle:
There are three stages in the lifecycle of Stateful Session Bean. These are:
1. Does Not Exist: In this the bean does not have any instance.
2. Method Ready Pool: In the Method Ready Pool stage bean has instance in the memory of the EJB container and it is ready to serve client. One instance of the Stateful Session Bean serves only one client.
3. Passive: In the Passive state the bean is passivated to conserve the resource. The passivate method is called before the instance enters the "passive" state. The instance should release any resources that it can re-acquire later in the ejbActivate() method. After the passivate method completes, the instance must be in a state that allows the container to use the Java Serialization protocol to externalize and store away the instance's state. ejbRemove or Timeout moves the bean into Does Not Exist stage.

How can we use beans in JSP?

Java Beans are reusable components. They are used to separate Business Logic from Presentation Logic. Internally a bean is just an instance of a class. JSP’s provide three basic tags for working with Beans.

*   <jsp : useBean id="bean name" class="bean class" scope= "page | request | session | application " />

bean name = the name that refers to the bean.

Bean class = name of the java class that defines the bean.

*   <jsp:setProperty name = “id” property = “someProperty” value = “someValue” /

id = the name of the bean as specified in the useBean tag.

property = name of the property to be passed to the bean.

value = value of that particular property .

*   <jsp:getProperty name = “id” property = “someProperty” />

Explain widening conversion and Narrowing conversion.

For a primitive data types, a value narrower data type can be converted to a value of a broader data type without loss of information. This is called Widening conversion. For example an int is directly converted to a double without first having to convert it to a long and a float.

Converting from a broader data type to a narrower data type is called narrowing conversion, which can result in loss of information. For example conversion between char and byte and short are narrowing conversions. For example byte takes 8 bits, short takes 16 bits, int takes 32 bits, long takes 64 bits. Conversion of short to int or int to long is widening conversion and conversion of int to short is a narrowing conversion.

What is a StringBuffer class and how does it differ from String Class?

In contrast to the String class which implements immutable character strings, the StringBuffer class implements mutable character strings. Not only can the character string in a string buffer gets changed, but the buffer’s capacity can also change dynamically. The capacity of a String Buffer is the maximum number of characters that a string buffer can accommodate, before its size is automatically augmented.

Both String and StringBuffer class are thread-safe.

The syntax for initializing String class object is: String str1=”Hello”;

The syntax for initializing StringBuffer class object is:
StringBuffer sbr1= new StringBuffer (“hello”);
StringBuffer sbr2= new StringBuffer (10);
StringBuffer sbr3= new StringBuffer();

How does the native language C or C++ understand data types in JAVA?

Java native Interface (JNI) is a programming framework that allows Java code to interact with code written in another language, typically C or C++. JNI enables one to write native methods to handle situations when an application cannot be written entirely in the Java programming language.

It is also used to modify an existing application written in another programming language to be accessible to Java applications. Many of the standard library classes depend on JNI to provide functionality to the developer and the user. The Java Development Kit (JDK) provides tools and library routines that help the Java programmer interface with native code. It is important that the data types that are passed between Java and native code have the same properties. Like jboolean data type of native language is same as Boolean data type of Java.

Difference between Tomcat and Weblogic server.

Tomcat is a web server which can run servlets and JSP whereas Weblogic is an application server which can run EJBs also. Tomcat is owned by Apache Software Foundation and weblogic is owned by Oracle. Weblogic fully supports the Java Enterprise Edition like EJB but Tomcat does not support EJB. Transaction management can be done in Weblogic but it can’t be done in Tomcat. Weblogic supports both Http and Ftp but Tomcat only supports Http. Oracle WebLogic Server Process Edition also include Business Process Management and Data Mapping functionality. WebLogic supports security policies managed by security administrators. The Oracle WebLogic Server Security Model includes:

-application business logic separated from security code
-complete scope of security coverage for all Java EE and non-Java EE components

Explain different Authentication Options available in Servets

Authentication options available in Servlets:

There are four different options for authentication in servlets

1. Basic Authentication- In this the server uses the username and password provided by the client to authenticate the user. The server gives several attempts (up to 3 attempts) after the three wrong attempts it gives the error page (usually an HTTP 401 Unauthorized error).
2. Form-based authentication- In this the login form is made by the programmer by using HTML. This is more helpful than the basic authentication because we can create more login interface other than username and password for the authentication.
3. Digest Authentication- It is similar to basic authentication but in this the passwords are encrypted using Hash formula. This makes digest more secured.
4. Client certificate Authentication- It requires that each client accessing the resource has a certificate that it send to authenticate itself. This requires SSL protocol.

How do I read a line of input at a time in Java?

The standard input stream is represented by the InputStream object System.in. For reading a whole line at a time BufferedReader is chained to an InputStreamReader that in turn is chained to System.in. For example: This program read line from a file “students” and displays it on screen.

import java.io.*;
import java.util.*;
public class stud
{
public static void main (String args[ ]) throws IOException
{
BufferedReader br= new BufferedReader(new InputStreamReader(newFileInputStream(“students”)));
String s= “”;
while ((s= br.readLine())!=null) System.out.println(s);
}
catch (IOException e)

System.out.println(e);
}
}    

More Java technical interview questions

Explain Java architecture, i.e. typical Java environment.

Java programming language, Java class file format , Java Application Programming Interface, Java virtual machine......

What is user defined Exception? Explain with an example.

A user defined exception is extended by Exception class.
Unconventional actions are dealt with user defined exceptions
Application demanded exceptions other than APIs are defined as user defined exceptions. Ex: When the balance of an account is below zero after withdrawl, an exception can be raised like ‘NegativeBalanceException’...........

What are the different loops available in java? How do we choose the right loop for a specific job?

A loop is a set of statements that is supposed to repeat one or more times. Java supports 3 loops................

Static nested class vs. a non-static one.

A static nested class can not directly access non-static methods or fields of an instance of its enclosing class. They can be accessed by creating the object of the nested inner class. Where as non-static nested ....................

What is chained exceptions in java?

Once an application finds an exception, responds an exception by throwing another exception. It causes another exception. Knowing an exception that causes another exception is very useful.....................

Explain the difference between protected and default access.

The default access specifier is one which is not specified with a key word. If no access specifier (any one of private, protected, public) is mentioned it is known as the default access specifier.............

C++ interview questions

What is friend class in C++?
Explain default constructor. What is a default constructor?
What are recursive functions? What are the advantages and disadvantages of Recursive algorithms?
What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator.
What do you mean by stack unwinding?
What is the use of ‘using’ declaration?
What is the difference between Mutex and Binary semaphore?
Explain how to call a base member function from derived class member function.
Is it possible to overload a constructor?
Overriding vs. overloading
Why does COM require GUIDs?
What happens when an object is destroyed that doesn't have an explicit destructor?
Explain the problem with dynamic type checking.
Define private, protected and public access control.
Explain the different access specifiers for the class member in C++.
What is the importance of mutable keyword?
What is virtual function? Explain with an example.
Explain implementation of traversal of a binary tree.
Explain implementation of deletion from a binary tree.
Click here for more questions and answers .

Database interview questions

Explain the types of indexes?
Define SQL.
Define alternate key.
Delete vs. Truncate table.
Define constraints.
Explain the types of relationships in database.
What are the benifits of normalizing database?
What is normalization?
What is sub-query?
What is "correlated subqueries"?
What is a join and explain different types of joins.
Click here for more questions and answers

Networking interview questions

Can you differentiate among encoding, encryption and hashing?
If you have to generate a hash function then what characteristics are needed in a secure hash function?
What is digital signature? Differentiate between Physical and Digital Signature
What is Authentication Header and how it provides the protection to IP header?
Explain SSL Protocol. How does it protect internet users from various threats?
Define Subnetting.
What is the User Datagram Protocol (UDP)?
Explain TCP Windowing concept.
Explain different layers in the OSI model.
Explain the concept and capabilities of Unicast IP Addresses.
What is IP Multicasting?
Difference between ARP and RARP
What is the difference between POP3 and IMAP Mail Server?
Click here for more questions and answers



Write your comment - Share Knowledge and Experience



 

 
Interview questions
Latest MCQs
» General awareness - Banking » ASP.NET » PL/SQL » Mechanical Engineering
» IAS Prelims GS » Java » Programming Language » Electrical Engineering
» English » C++ » Software Engineering » Electronic Engineering
» Quantitative Aptitude » Oracle » English » Finance
Home | About us | Sitemap | Contact us | We are hiring