The most often asked in the interview (FRENQUENTLY ASKED Interview Questions) Java

xiaoxiao2021-03-06  84

Java Questions & Answers

1. What is the difference badween an applet and an application?

A Java application is made up of a main () method declared as public static void that accepts a string array argument, along with any other classes that main () calls. It lives in the environment that the host OS provides.

A Java applet is made up of at least one public class that has to be subclassed from java.awt.Applet. The applet is confined to living in the user's Web browser, and the browser's security rules, (or Sun's appletviewer, which has fewer Restrictions.

The Differences Between An Applet and An Application Are As Follows:

1. Applets Can Be Embedded in HTML Pages and Downloaded over The Internet Whereas Applications Have No Special Support in Html for Embedding or Download.

2. Applets Can Only Be Executed Inside A Java Compatible Container, Such As a Browser or AppletViewer WHEREAS Applications Are Executed At Command Line by Java.exe or Jview.exe.

3. Applets Execute Under Strict Security Limitations That Disallow Certain Operations (Sandbox Model Security) Whereas Applications Have No Inherents Struancy Restrictions.

4. Applets do not have the main () method as in applications. Instead they operate on an entirely different mechanism where they are initialized by init (), started by start (), stopped by stop () or destroyed by destroy () .

2. What Are Java Beans?

JavaBeans is a portable, platform-independent component model written in the Java programming language, developed in collaboration with industry leaders It enables developers to write reusable components once and run them anywhere -.. Benefiting from the platform-independent power of Java technology JavaBeans acts as a Bridge between proprietary component models and provides a seamless and powerful means for developers to build components that run in ActiveX container applications.Java beans is very powerful tool you can use in your servlet / JSP bridge. you can use the servlets to build ................ ..

3. What is RMI?

RMI stands for Remote Method Invocation. Traditional approaches to executing code on other machines across a network have been confusing as well as tedious and error-prone to implement. The nicest way to think about this problem is that some object happens to live on another machine And that you can send a message to the remote Object and get a result as if the object Lived on your local machine. This Simplification is exactly what Java Remote Method Invocation (RMI) Allows you to do.

4. What Gives Java It's "WRITE ONCE AND RUN Anywhere" Nature?

Java is compiled to be a byte code which is the intermediate language between source code and machine code. This byte code is not platorm specific and hence can be fed to any platform. After being fed to the JVM, which is specific to a particular operating System, The Code Platform Specific Machine Code Is Generated Thus Making Java Platform Independ.

5. How does Java Inheritance Work?

A class can only directly extend one class at a time. Multiple inheritance is only allowed with regard to interfaces. A class can implement many interfaces. But a class can only extend one non-interface class.6. What are native methods? How do YOU USE THEM?

Native methods are used when the implementation of a particular method is present in language other than Java say C, C . To use the native methods in java we use the keyword nativepublic native method_a () This native keyword is signal to the java compiler that the implementation of this method is in a language other than java.Native methods are used when we realize that it would take up a lot of rework to write that piece of already existing code in other language to java.

7. Class A Subclass B Subclass C. All Override Foo (). I Cast C to a and call foo (). What happens? Can c cal1 a-> foo ()?

An Instance of Class C Is of Type Class B And A (Both). So you can cast c to a. You Cannot Cast An Instance of A to C.

8. What does The "static" Keyword Mean in Front of a variable? A method? A class? Curly braces {}?

- Static Variables: Thase Are Class Level Variable Whose Value Remain Same Irrespective of The Number of Instances of the Class.

- static methods: These are those methods that can be called without the need for creating the objects of the class ie they are class level methods They can call only static methods They can not refer to "this" as they are not associated with.. Any particular instance.

- static block: These are called before the main is called and are called only once Subsequent invocation of the java program containing static block would not call it again Hence, they can be used to load libraries say in native function call.-.. - Only Inner Class Could Be Declared AS A "Static". This Declaration Suppress The Generation of the Reference To The Outer Class Object. This means: 1) For the object of creating a Static internal class, we do not need an external class object; 2) You cannot access an external class object from the STATIC internal class object.

9. How Many Different Types of JDBC DRIVERS Are Present? Discuss Them.

There is Four JDBC Driver Types.

Type 1:

JDBC-ODBC

Bridge

Plus Odbc Driver: The First Type of JDBC Driver Is The

JDBC-ODBC

Bridge

. It is a driver that provides JDBC access to databases through ODBC drivers. The ODBC driver must be configured on the client for the bridge to work. This driver type is commonly used for prototyping or when there is no JDBC driver available for a particular DBMS .

Type 2: Native-API partly-Java Driver: The Native to API driver converts JDBC commands to DBMS-specific native calls This is much like the restriction of Type 1 drivers The client must have some binary code loaded on its machine These... Drivers do have an advantage over Type 1 Drivers Because The interface Directly with the database.

Type 3: JDBC-Net Pure Java Driver: The JDBC-Net drivers are a three-tier solution This type of driver translates JDBC calls into a database-independent network protocol that is sent to a middleware server This server then translates this DBMS.. -independent protocol into a DBMS-specific protocol, which is sent to a particular database. The results are then routed back through the middleware server and sent back to the client. This type of solution makes it possible to implement a pure Java client. It also makes it possible to swap databases without affecting the client.Type 4: Native-Protocol Pure Java DriverThese are pure Java drivers that communicate directly with the vendor's database They do this by converting JDBC commands directly into the database engine's native protocol This driver.. Has No Additional Translation Or MiddleWare Layer, Which Improves Performance Tremendously.

10. Does Java Have "goto"?

Yes and no. there is no "goto" Operator Used in Java, But it is a reserved keyword, and one can use break statements to branch to a labelled statement, exactly as one..

11. Why "Bytecode"? Can you review-engineer the code from bytecode?

Yes, with some tools.

12. How does Exception Handling Work in java?

.

2.it allows a clean path for error procation. If the called method encounters a situation it can't manage, it can throw an exception and let the calling method deal with it.

3.by Enlisting The Compiler To Ensure That "Exceptional" Situations Are Anticipated and Accounted For, IT EnForces Powerful Coding.

4.Exceptions are of two types:.. Compiler-enforced exceptions, or checked exceptions and Runtime exceptions, or unchecked exceptions Compiler-enforced (checked) exceptions are instances of the Exception class or one of its subclasses - excluding the RuntimeException branch The compiler expects all checked exceptions to be appropriately handled Checked exceptions must be declared in the throws clause of the method throwing them -. assuming, of course, they're not being caught within that same method The calling method must take care of these. exceptions by either catching or declaring them in its throws clause. Thus, making an exception checked forces us to pay heed to the possibility of it being thrown. An example of a checked exception is java.io.IOException. As the name suggests, it THROWS WHENEVER An Input / Output Operation Is Abnormal Terminated.13. Does Java Have Destructors?

.

But it is firmizers this does a Similar job. The syntax ispublic void finalize () {}

If An Object Has A Finalizer, The Method Is Invoked Before The System Garbage Collects The Object, But Use Finalize () Does Not Guarantee That It Would Be Called B4 Garbage Collector Is Invoked.

14. What does The "final" Keyword Mean in Front of a variable? A Method? A class?

A final variable cannot be true, but it is not constant. For instance, final stringbuffer x = new stringbuffer (); x.append ("hello"); is valid. X Cannot Have a new value in it, but nothing stops Operations on the object that it refers, including destructive operations.Also, a final method can not be overridden or hidden by new access specifications. This means that the compiler can choose to in-line the invocation of such a method. (I do not know IF Any Compiler Actually Does this, But it's true inory.

The Best Example of a final class is string, Which defines a class thing cannot be deive.

15. Access Specifiers: "public", "protected", "private", nothing?

Public? Any other class from any package can instantiate and execute the classes and methodsProtected? Only subclasses and classes inside of the package can access the classes and methodsPrivate? The original class is the only class allowed to execute the methods.And in case if there IS NO Modifier Specified, It Means, ONLY The Class Inside The Package CAN Access this class and its methods, it is also caled "friendly".

转载请注明原文地址:https://www.9cbs.com/read-98292.html

New Post(0)