Archive for the Category: Java

What is a Java package and how is it used?

A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces. Packages are also used to organize related classes and interfaces into a single API unit and to control accessibility to these classes and interfaces.

Tagged , Comments Off

What is difference between Path and Classpath?

Path and Classpath are operating system level environment variales. Path is used define where the system can find the executables(.exe) files and classpath is used to specify the location .class files.

Tagged , , Comments Off

Are JVM’s platform independent?

JVM’s are not platform independent. JVM’s are platform specific run time implementation provided by the vendor.

Tagged , Comments Off

What is a pointer and does Java support pointers?

Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn’t support the usage of pointers.

Tagged , Comments Off

What is the difference between a JDK and a JVM?

JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.

Tagged , , Comments Off

Can I have multiple main methods in the same class?

No the program fails to compile. The compiler says that the main method is already defined in the class.

Leave a comment

Can you write a Java class that could be used both as an applet as well as an application?

Yes. Add a main() method to the applet.

Leave a comment

How can I share data between two different web applications?

Different servlets may share data within one application via ServletContext. If you have a compelling to put the servlets in different applications, you may wanna consider using EJBs.

Tagged , Leave a comment

What is the difference between static variables and instance variables in a servlet?

According to the Java Language definition, a static variable is shared among all instances of a class, where a non-static variable — also called an instance variable — is specific to a single instance of that class. According to the Servlet specification, a servlet that does not declare SingleThreadModel usually has one and only one […]

Tagged , Leave a comment

How can I return a readily available (static) HTML page to the user instead of generating it in the servlet?

To solve your problem, you can either send a “Redirect” back to the client or use a RequestDispatcher and forward your request to another page: Redirect: A redirection is made using the HttpServletResponse object:   if(condition) { response.sendRedirect(“page1.html”); } else { response.sendRedirect(“page2.html”); }   RequestDispatcher: A request dispatcher can be obtained through the ServletContext. It […]

Tagged , 1 Comment