registration
Are you an Employer?

Core Java interview questions & Answers

List of Topics
Core Java Interview Questions

Core Java Interview questions

  • What Is The Most Important Feature Of Java?

    Java is a platform independent language.

  • What Do You Mean By Platform Independence?

    Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (Linux,Solaris,etc).

  • Are Jvm's Platform Independent?

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

  • What Is A Jvm?

    JVM is Java Virtual Machine which is a run time environment for the compiled java class files.

  • 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.

  • 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.

  • What Is The Base Class Of All Classes?

    java.lang.Object

  • Does Java Support Multiple Inheritance?

    Java doesn't support multiple inheritance.

  • Is Java A Pure Object Oriented Language?

    Java uses primitive data types and hence is not a pure object oriented language.

  • Are Arrays Primitive Data Types?

    In Java, Arrays are objects.

  • 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.

  • What Are Local Variables?

    Local varaiables are those which are declared within a block of code like methods. Local variables should be initialised before accessing them.

  • What Are Instance Variables?

    Instance variables are those which are defined at the class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values.

  • How To Define A Constant Variable In Java?

    The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed also. static final int PI = 2.14; is an example for constant.

  • Should A Main Method Be Compulsorily Declared In All Java Classes?

    No not required. main method should be defined only if the source class is a java application.

  • What Is The Return Type Of The Main Method?

    Main method doesn't return anything hence declared void.

  • Why Is The Main Method Declared Static?

    main method is called by the JVM even before the instantiation of the class hence it is declared as static.

  • What Is The Arguement Of Main Method?

    main method accepts an array of String object as arguement.

  • Can A Main Method Be Overloaded?

    Yes. You can have any number of main methods with different method signature and implementation in the class.

  • Can A Main Method Be Declared Final?

    Yes. Any inheriting class will not be able to have it's own default main method.

  • Does The Order Of Public And Static Declaration Matter In Main Method?

    No it doesn't matter but void should always come before main().

  • Can A Source File Contain More Than One Class Declaration?

    Yes a single source file can contain any number of Class declarations but only one of the class can be declared as public.

  • What Is A Package?

    Package is a collection of related classes and interfaces. package declaration should be first statement in a java class.

  • Which Package Is Imported By Default?

    java.lang package is imported by default even without a package declaration.

  • Can A Class Declared As Private Be Accessed Outside It's Package?

    Not possible.

  • Can A Class Be Declared As Protected?

    A class can't be declared as protected. only methods can be declared as protected.

  • What Is The Access Scope Of A Protected Method?

    A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package.

  • What Is The Purpose Of Declaring A Variable As Final?

    A final variable's value can't be changed. final variables should be initialized before using them.

  • What Is The Impact Of Declaring A Method As Final?

    A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation.

  • I Don't Want My Class To Be Inherited By Any Other Class. What Should I Do?

    You should declared your class as final. But you can't define your class as final, if it is an abstract class. A class declared as final can't be extended by any other class.

  • Can You Give Few Examples Of Final Classes Defined In Java Api?

    java.lang.String,java.lang.Math are final classes.

  • How Is Final Different From Finally And Finalize?

    final is a modifier which can be applied to a class or a method or a variable. final class can't be inherited, final method can't be overridden and final variable can't be changed.

    finally is an exception handling code section which gets executed whether an exception is raised or not by the try block code segment.

    finalize() is a method of Object class which will be executed by the JVM just before garbage collecting object to give a final chance for resource releasing activity.

  • Can A Class Be Declared As Static?

    No a class cannot be defined as static. Only a method,a variable or a block of code can be declared as static.

  • When Will You Define A Method As Static?

    When a method needs to be accessed even before the creation of the object of the class then we should declare the method as static.

  • What Are The Restriction Imposed On A Static Method Or A Static Block Of Code?

    A static method should not refer to instance variables without creating an instance and cannot use "this" operator to refer the instance.

  • I Want To Print "hello" Even Before Main Is Executed. How Will You Acheive That?

    Print the statement inside a static block of code. Static blocks get executed when the class gets loaded into the memory and even before the creation of an object. Hence it will be executed before the main method. And it will be executed only once.

  • What Is The Importance Of Static Variable?

    static variables are class level variables where all objects of the class refer to the same variable. If one object changes the value then the change gets reflected in all the objects.

  • Can We Declare A Static Variable Inside A Method?

    Static variables are class level variables and they can't be declared inside a method. If declared, the class will not compile.

  • What Is An Abstract Class And What Is It's Purpose?

    A Class which doesn't provide complete implementation is defined as an abstract class. Abstract classes enforce abstraction.

  • Can A Abstract Class Be Declared Final?

    Not possible. An abstract class without being inherited is of no use and hence will result in compile time error.

  • What Is Use Of A Abstract Variable?

    Variables can't be declared as abstract. only classes and methods can be declared as abstract.

  • Can You Create An Object Of An Abstract Class?

    Not possible. Abstract classes can't be instantiated.

  • Can A Abstract Class Be Defined Without Any Abstract Methods?

    Yes it's possible. This is basically to avoid instance creation of the class.

  • Class C Implements Interface I Containing Method M1 And M2 Declarations. Class C Has Provided Implementation For Method M2. Can I Create An Object Of Class C?

    No not possible. Class C should provide implementation for all the methods in the Interface I. Since Class C didn't provide implementation for m1 method, it has to be declared as abstract. Abstract classes can't be instantiated.

  • Can A Method Inside A Interface Be Declared As Final?

    No not possible. Doing so will result in compilation error. public and abstract are the only applicable modifiers for method declaration in an interface.

  • Can An Interface Implement Another Interface?

    Intefaces doesn't provide implementation hence a interface cannot implement another interface.

  • Can An Interface Extend Another Interface?

    Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface.

  • Can A Class Extend More Than One Class?

    Not possible. A Class can extend only one class but can implement any number of Interfaces.

  • Why Is An Interface Be Able To Extend More Than One Interface But A Class Can't Extend More Than One Class?

    Basically Java doesn't allow multiple inheritance, so a Class is restricted to extend only one Class. But an Interface is a pure abstraction model and doesn't have inheritance hierarchy like classes(do remember that the base class of all classes is Object). So an Interface is allowed to extend more than one Interface.

  • Can An Interface Be Final?

    Not possible. Doing it will result in compilation error.

  • Can A Class Be Defined Inside An Interface?

    Yes it's possible.

  • Can An Interface Be Defined Inside A Class?

    Yes it's possible.

  • What Is A Marker Interface?

    An Interface which doesn't have any declaration inside but still enforces a mechanism.

  • Which Oo Concept Is Achieved By Using Overloading And Overriding?

    Polymorphism.

  • If I Only Change The Return Type, Does The Method Become Overloaded?

    No it doesn't. There should be a change in method arguements for a method to be overloaded.

  • Why Does Java Not Support Operator Overloading?

    Operator overloading makes the code very difficult to read and maintain. To maintain code simplicity, Java doesn't support operator overloading.

  • Can We Define Private And Protected Modifiers For Variables In Interfaces?

    No

  • What Is Externalizable?

    Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in)

  • What Modifiers Are Allowed For Methods In An Interface?

    Only public and abstract modifiers are allowed for methods in interfaces.

  • What Is A Local, Member And A Class Variable?

    Variables declared within a method are "local" variables. Variables declared within the class i.e not within any methods are "member" variables (global variables). Variables declared within the class i.e not within any methods and are defined as "static" are class variables.

  • What Is An Abstract Method?

    An abstract method is a method whose implementation is deferred to a subclass.

  • What Value Does Read() Return When It Has Reached The End Of A File?

    The read() method returns -1 when it has reached the end of a file.

  • Can A Byte Object Be Cast To A Double Value?

    No, an object cannot be cast to a primitive value.

  • What Is The Difference Between A Static And A Non-static Inner Class?

    A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.

  • What Is An Object's Lock And Which Object's Have Locks?

    An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock. All objects and classes have locks. A class's lock is acquired on the class's Class object.

  • What Is The % Operator?

    It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.

  • When Can An Object Reference Be Cast To An Interface Reference?

    An object reference be cast to an interface reference when the object implements the referenced interface.

  • Which Class Is Extended By All Other Classes?

    The Object class is extended by all other classes.

  • Which Non-unicode Letter Characters May Be Used As The First Character Of An Identifier?

    The non-Unicode letter characters $ and _ may appear as the first character of an identifier.

  • What Restrictions Are Placed On Method Overloading?

    Two methods may not have the same name and argument list but different return types.

  • What Is Transient Variable?

    Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can't be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null.

  • What Is Collection Api?

    The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces.

    Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.

    Example of interfaces: Collection, Set, List and Map.

  • What Is Casting?

    There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.

  • What Is The Return Type Of A Program's Main() Method?

    void.

  • If A Variable Is Declared As Private, Where May The Variable Be Accessed?

    A private variable may only be accessed within the class in which it is declared.

  • What Do You Understand By Private, Protected And Public?

    These are accessibility modifiers. Private is the most restrictive, while public is the least restrictive. There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package.

  • What Is Downcasting ?

    Downcasting is the casting from a general to a more specific type, i.e. casting down the hierarchy.

  • What Modifiers May Be Used With An Inner Class That Is A Member Of An Outer Class?

    A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.

  • How Many Bits Are Used To Represent Unicode, Ascii, Utf-16, And Utf-8 Characters?

    Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.

  • What Restrictions Are Placed On The Location Of A Package Statement Within A Source Code File?

    A package statement must appear as the first line in a source code file (excluding blank lines and comments).

  • What Is A Native Method?

    A native method is a method that is implemented in a language other than Java.

  • What Are Order Of Precedence And Associativity, And How Are They Used?

    Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left.

  • Can An Anonymous Class Be Declared As Implementing An Interface And Extending A Class?

    An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.

  • What Is The Range Of The Char Type?

    The range of the char type is 0 to 2^16 - 1.

  • What Is The Range Of The Short Type?

    The range of the short type is -(2^15) to 2^15 - 1.

  • Why Isn't There Operator Overloading?

    Because C++ has proven by example that operator overloading makes code almost impossible to maintain.

  • What Does It Mean That A Method Or Field Is "static"?

    Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That's how library methods like System. out. println() work. out is a static field in the java.lang.System class.

  • Is Null A Keyword?

    The null value is not a keyword.

  • Which Characters May Be Used As The Second Character Of An Identifier,but Not As The First Character Of An Identifier?

    The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier.

  • Is The Ternary Operator Written X : Y ? Z Or X ? Y : Z ?

    It is written x ? y : z.

  • How Is Rounding Performed Under Integer Division?

    The fractional part of the result is truncated. This is known as rounding toward zero.

  • If A Class Is Declared Without Any Access Modifiers, Where May The Class Be Accessed?

    A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.

  • Does A Class Inherit The Constructors Of Its Superclass?

    A class does not inherit constructors from any of its superclasses.

  • Name The Eight Primitive Java Types.

    The eight primitive types are byte, char, short, int, long, float, double, and boolean.

  • What Restrictions Are Placed On The Values Of Each Case Of A Switch Statement?

    During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.

  • What Is The Difference Between A While Statement And A Do Statement?

    A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.

  • What Modifiers Can Be Used With A Local Inner Class?

    A local inner class may be final or abstract.

  • When Does The Compiler Supply A Default Constructor For A Class?

    The compiler supplies a default constructor for a class if no other constructors are provided.

  • If A Method Is Declared As Protected, Where May The Method Be Accessed?

    A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

  • What Are The Legal Operands Of The Instanceof Operator?

    The left operand is an object reference or null value and the right operand is a class, interface, or array type.

  • Are True And False Keywords?

    The values true and false are not keywords.

  • What Happens When You Add A Double Value To A String?

    The result is a String object.

  • What Is The Diffrence Between Inner Class And Nested Class?

    When a class is defined within a scope od another class, then it becomes inner class. If the access modifier of the inner class is static, then it becomes nested class.

  • Can An Abstract Class Be Final?

    An abstract class may not be declared as final.

  • What Is Numeric Promotion?

    Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required.

  • What Is The Difference Between A Public And A Non-public Class?

    A public class may be accessed outside of its package. A non-public class may not be accessed outside of its package.

  • To What Value Is A Variable Of The Boolean Type Automatically Initialized?

    The default value of the boolean type is false

  • What Is The Difference Between The Prefix And Postfix Forms Of The ++ Operator?

    The prefix form performs the increment operation and returns the value of the increment operation. The postfix form returns the current value all of the expression and then performs the increment operation on that value.

  • What Restrictions Are Placed On Method Overriding?

    Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method.

  • 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.

  • What Modifiers May Be Used With A Top-level Class?

    A top-level class may be public, abstract, or final.

  • What Is The Difference Between An If Statement And A Switch Statement?

    The if statement is used to select among two alternatives. It uses a boolean expression to decide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternative should be executed.

  • Can A Method Be Overloaded Based On Different Return Type But Same Argument Type ?

    No, because the methods can be called without using their return type in which case there is ambiquity for the compiler

  • What Happens To A Static Var That Is Defined Within A Method Of A Class ?

    Can't do it. You'll get a compilation error

  • How Many Static Init Can You Have ?

    As many as you want, but the static initializers and class variable initializers are executed in textual order and may not refer to class variables declared in the class whose declarations appear textually after the use, even though these class variables are in scope.

  • What Is The Difference Between Method Overriding And Overloading?

    Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments

  • What Is Constructor Chaining And How Is It Achieved In Java ?

    A child object constructor always first needs to construct its parent (which in turn calls its parent constructor.). In Java it is done via an implicit call to the no-args constructor as the first statement.

  • What Is The Difference Between The Boolean & Operator And The && Operator?

    If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.

  • Which Java Operator Is Right Associative?

    The = operator is right associative.

  • Can A Double Value Be Cast To A Byte?

    Yes, a double value can be cast to a byte.

  • What Is The Difference Between A Break Statement And A Continue Statement?

    A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.

  • Can A For Statement Loop Indefinitely?

    Yes, a for statement can loop indefinitely. For example, consider the following: for(;;) ;

  • To What Value Is A Variable Of The String Type Automatically Initialized?

    The default value of an String type is null.

  • What Is The Difference Between A Field Variable And A Local Variable?

    A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.

  • How Are This() And Super() Used With Constructors?

    this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.

  • What Does It Mean That A Class Or Member Is Final?

    A final class cannot be inherited. A final method cannot be overridden in a subclass. A final field cannot be changed after it's initialized, and it must include an initializer statement where it's declared.

  • What Does It Mean That A Method Or Class Is Abstract?

    An abstract class cannot be instantiated. Abstract methods may only be included in abstract classes. However, an abstract class is not required to have any abstract methods, though most of them do. Each subclass of an abstract class must override the abstract methods of its superclasses or it also should be declared abstract.

  • Can An Anonymous Class Be Declared As Implementing An Interface And Extending A Class?

    An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.

  • What Is The Catch Or Declare Rule For Method Declarations?

    If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause.

  • What Are Some Alternatives To Inheritance?

    Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).

  • What Are The Different Identifier States Of A Thread?

    The different identifiers of a Thread are: R - Running or runnable thread, S - Suspended thread, CW - Thread waiting on a condition variable, MW - Thread waiting on a monitor lock, MS - Thread suspended waiting on a monitor lock.

  • What Is Garbage Collection? What Is The Process That Is Responsible For Doing That In Java?

    Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process.

  • What Kind Of Thread Is The Garbage Collector Thread?

    It is a daemon thread.

  • What Is A Daemon Thread?

    These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly.

  • How Will You Invoke Any External Process In Java?

    Runtime.getRuntime().exec(….)

  • What Is The Finalize Method Do?

    Before the invalid objects get garbage collected, the JVM give the user a chance to clean up some resources before it got garbage collected.

  • What Is Mutable Object And Immutable Object?

    If a object value is changeable then we can call it as Mutable object. (Ex., StringBuffer, …) If you are not allowed to change the value of an object, it is immutable object. (Ex., String, Integer, Float, …)

  • What Is The Basic Difference Between String And Stringbuffer Object?

    String is an immutable object. StringBuffer is a mutable object.

  • What Is The Purpose Of Void Class?

    The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void.

  • What Is Reflection?

    Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions.

  • What Is The Base Class For Error And Exception?

    Throwable

  • What Is The Byte Range?

    128 to 127

  • What Is The Implementation Of Destroy Method In Java.. Is It Native Or Java Code?

    This method is not implemented.

  • What Are The Approaches That You Will Follow For Making A Program Very Efficient?

    By avoiding too much of static methods avoiding the excessive and unnecessary use of synchronized methods Selection of related classes based on the application (meaning synchronized classes for multiuser and non-synchronized classes for single user) Usage of appropriate design patterns Using cache methodologies for remote invocations Avoiding creation of variables within a loop and lot more.

  • What Is A Databasemetadata?

    Comprehensive information about the database as a whole.

  • What Is Locale?

    A Locale object represents a specific geographical, political, or cultural region.

  • How Will You Load A Specific Locale?

    Using ResourceBundle.getBundle(…);

  • What Is Jit And Its Use?

    Really, just a very fast compiler… In this incarnation, pretty much a one-pass compiler — no offline computations. So you can’t look at the whole method, rank the expressions according to which ones are re-used the most, and then generate code. In theory terms, it’s an on-line problem.

  • Is Jvm A Compiler Or An Interpreter?

    Interpreter

  • What Is The Purpose Of Assert Keyword Used In Jdk1.4.x?

    In order to validate certain expressions. It effectively replaces the if block and automatically throws the AssertionError on failure. This keyword should be used for the critical arguments. Meaning, without that the method does nothing.

  • How Will You Get The Platform Dependent Values Like Line Separator, Path Separator, Etc., ?

    Using Sytem.getProperty(…) (line.separator, path.separator, …)

  • Is "abc" A Primitive Value?

    The String literal “abc” is not a primitive value. It is a String object.

  • What Is Singleton?

    It is one of the design pattern. This falls in the creational pattern of the design pattern. There will be only one instance for that entire JVM. You can achieve this by having the private constructor in the class. For eg., public class Singleton { private static final Singleton s = new Singleton(); private Singleton() { } public static Singleton getInstance() { return s; } // all non static methods … }

  • Can You Instantiate The Math Class?

    You can’t instantiate the math class. All the methods in this class are static. And the constructor is not public.

  • What Are The Methods In Object?

    clone, equals, wait, finalize, getClass, hashCode, notify, notifyAll, toString.

  • What Is Aggregation?

    It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite method through its reference, then it is called aggregation.

  • What Is Composition?

    Holding the reference of the other class within some other class is known as composition.

  • What Is Inner Class?

    If the methods of the inner class can only be accessed via the instance of the inner class, then it is called inner class.

  • What Is Nested Class?

    If all the methods of a inner class is static then it is a nested class.

  • What Is The Major Difference Between Linkedlist And Arraylist?

    LinkedList are meant for sequential accessing. ArrayList are meant for random accessing.

  • What Is The Significance Of Listiterator?

    You can iterate back and forth.

  • What Is The Final Keyword Denotes?

    final keyword denotes that it is the final implementation for that method or variable or class. You can’t override that method/variable/class any more.

  • What Is Skeleton And Stub? What Is The Purpose Of Those?

    Stub is a client side representation of the server, which takes care of communicating with the remote server. Skeleton is the server side representation. But that is no more in use… it is deprecated long before in JDK.

  • Why Does It Take So Much Time To Access An Applet Having Swing Components The First Time?

    Because behind every swing component are many Java objects and resources. This takes time to create them in memory. JDK 1.3 from Sun has some improvements which may lead to faster execution of Swing applications.

  • What Is The Difference Between Instanceof And Isinstance?

    instanceof is used to check to see if an object can be cast into a specified type without throwing a cast class exception. isInstance() Determines if the specified Object is assignment-compatible with the object represented by this Class. This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is non-null and can be cast to the reference type represented by this Class object without raising a ClassCastException. It returns false otherwise.

  • What Does The "final" Keyword Mean In Front Of A Variable? A Method? A Class?

    FINAL for a variable: value is constant. FINAL for a method: cannot be overridden. FINAL for a class: cannot be derived.

  • Describe What Happens When An Object Is Created In Java?

    Several things happen in a particular order to ensure the object is constructed properly: Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implemenation-specific data includes pointers to class and method data. The instance variables of the objects are initialized to their default values. The constructor for the most derived class is invoked. The first thing a constructor does is call the consctructor for its superclasses. This process continues until the constrcutor for java.lang.Object is called, as java.lang.Object is the base class for all objects in java. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last.

  • What Is The Difference Amongst Jvm Spec, Jvm Implementation, Jvm Runtime ?

    The JVM spec is the blueprint for the JVM generated and owned by Sun. The JVM implementation is the actual implementation of the spec by a vendor and the JVM runtime is the actual running instance of a JVM implementation.

  • How Does Java Handle Integer Overflows And Underflows?

    It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.

  • Why Are There No Global Variables In Java?

    Global variables are considered bad form for a variety of reasons: Adding state variables breaks referential transparency (you no longer can understand a statement or expression on its own: you need to understand it in the context of the settings of the global variables), State variables lessen the cohesion of a program: you need to know more to understand how something works. A major point of Object-Oriented programming is to break up global state into more easily understood collections of local state, When you add one variable, you limit the use of your program to one instance. What you thought was global, someone else might think of as local: they may want to run two copies of your program at once. For these reasons, Java decided to ban global variables.

  • Whats The Difference Between Notify() And Notifyall()?

    notify() is used to unblock one waiting thread; notifyAll() is used to unblock all of them. Using notify() is preferable (for efficiency) when only one blocked thread can benefit from the change (for example, when freeing a buffer back into a pool). notifyAll() is necessary (for correctness) if multiple threads should resume (for example, when releasing a “writer” lock on a file might permit all “readers” to resume).

  • How Can My Application Get To Know When A Httpsession Is Removed?

    Define a Class HttpSessionNotifier which implements HttpSessionBindingListener and implement the functionality what you need in valueUnbound() method. Create an instance of that class and put that instance in HttpSession.

  • What Interface Must An Object Implement Before It Can Be Written To A Stream As An Object?

    An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.

  • What Is Your Platform's Default Character Encoding?

    If you are running Java on English Windows platforms, it is probably Cp1252. If you are running Java on English Solaris platforms, it is most likely 8859_1.

  • What An I/o Filter?

    An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.

  • What Is The Purpose Of Finalization?

    The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.

  • Which Class Should You Use To Obtain Design Information About An Object?

    The Class class is used to obtain information about an object’s design.

  • What Is The Purpose Of The System Class?

    The purpose of the System class is to provide access to system resources.

  • Can We Use The Constructor, Instead Of Init(), To Initialize Servlet?

    Yes , of course you can use the constructor instead of init(). There’s nothing to stop you. But you shouldn’t. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or Servlet Context.

  • How Can A Servlet Refresh Automatically If Some New Data Has Entered The Database?

    You can use a client-side Refresh or Server Push.

  • The Code In A Finally Clause Will Never Fail To Execute, Right?

    Using System.exit(1); in try block will not allow finally code to execute.

  • How Many Messaging Models Do Jms Provide For And What Are They?

    JMS provide for two messaging models, publish-and-subscribe and point-to-point queuing.

  • What Information Is Needed To Create A Tcp Socket?

    The Local System?s IP Address and Port Number. And the Remote System’s IPAddress and Port Number.

  • What Class.forname Will Do While Loading Drivers?

    It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS.

  • How Many Jsp Scripting Elements Are There And What Are They?

    There are three scripting language elements: declarations, scriptlets, expressions.

  • What Are Stored Procedures? How Is It Useful?

    A stored procedure is a set of statements/commands which reside in the database. The stored procedure is pre-compiled and saves the database the effort of parsing and compiling sql statements everytime a query is run. Each database has its own stored procedure language, usually a variant of C with a SQL preproceesor. Newer versions of db’s support writing stored procedures in Java and Perl too. Before the advent of 3-tier/n-tier architecture it was pretty common for stored procs to implement the business logic( A lot of systems still do it). The biggest advantage is of course speed. Also certain kind of data manipulations are not achieved in SQL. Stored procs provide a mechanism to do these manipulations. Stored procs are also useful when you want to do Batch updates/exports/houseKeeping kind of stuff on the db. The overhead of a JDBC Connection may be significant in these cases.

  • How Do I Include Static Files Within A Jsp Page?

    Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase. Do note that you should always supply a relative URL for the file attribute. Although you can also include static resources using the action, this is not advisable as the inclusion is then performed for each and every request.

  • Why Does Jcomponent Have Add() And Remove() Methods But Component Does Not?

    Because JComponent is a subclass of Container, and can contain other components and jcomponents.

  • How Can I Implement A Thread-safe Jsp Page?

    You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive <%@ page isThreadSafe="false" % > within your JSP page.

  • What Is The Difference Between Procedural And Object-oriented Programs?

    a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOP program, unit of program is object, which is nothing but combination of data and code.
    b) In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible with in the object and which in turn assures the security of the code.

  • What Are Encapsulation, Inheritance And Polymorphism?

    Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse.

    Inheritance is the process by which one object acquires the properties of another object.

    Polymorphism is the feature that allows one interface to be used for general class actions.

  • What Is The Difference Between Assignment And Initialization?

    Assignment can be done as many times as desired whereas initialization can be done only once.

  • What Is Oops?

    Object oriented programming organizes a program around its data, i. e. , objects and a set of well defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code.

  • What Are Class, Constructor And Primitive Data Types?

    Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.

  • What Is An Object And How Do You Allocate Memory To It?

    Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.

  • What Is The Difference Between Constructor And Method?

    Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.

  • What Are Methods And How Are They Defined?

    Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes. Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method. A method’s signature is a combination of the first three parts mentioned above.

  • What Is The Use Of Bin And Lib In Jdk?

    Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.

  • How Many Ways Can An Argument Be Passed To A Subroutine And Explain Them?

    An argument can be passed in two ways.

    Passing by value: This method copies the value of an argument into the formal parameter of the subroutine.

    Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.

  • What Is The Difference Between An Argument And A Parameter?

    While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.

  • How Would You Implement A Thread Pool?

    The ThreadPool class is a generic implementation of a thread pool, which takes the following input Size of the pool to be constructed and name of the class which implements Runnable (which has a visible default constructor) and constructs a thread pool with active threads that are waiting for activation. once the threads have finished processing they come back and wait once again in the pool.

  • What Are The Advantages And Disadvantages Of Reference Counting In Garbage Collection?

    An advantage of this scheme is that it can run in small chunks of time closely linked with the execution of the program. These characteristic makes it particularly suitable for real-time environments where the program can't be interrupted for very long time. A disadvantage of reference counting is that it does not detect cycles. A cycle is two or more objects that refer to one another. Another disadvantage is the overhead of incrementing and decrementing the reference count each time. Because of these disadvantages, reference counting currently is out of favor.

  • Why Java Is Said To Be Pass-by-value ?

    When assigning an object to a variable, we are actually assigning the memory address of that object to the variable. So the value passed is actually the memory location of the object. This results in object aliasing, meaning you can have many variables referring to the same object on the heap.

  • What Are The Access Modifiers Available In Java?

    Access modifier specify where a method or attribute can be used.

    • Public is accessible from anywhere.
    • Protected is accessible from the same class and its subclasses.
    • Package/Default are accessible from the same package.
    • Private is only accessible from within the class.
  • What Is The Difference Between A Switch Statement And An If Statement?

    If statement is used to select from two alternatives. It uses a boolean expression to decide which alternative should be executed. The expression in if must be a boolean value. The switch statement is used to select from multiple alternatives. The case values must be promoted to an to int value.

  • What Are Synchronized Methods And Synchronized Statements?

    Synchronized methods are methods that are declared with the keyword synchronized. thread executes a synchronized method only after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. It is a block of code declared with synchronized keyword. A synchronized statement can be executed only after a thread has acquired the lock for the object or class referenced in the synchronized statement.

  • What Are The Different Ways In Which A Thread Can Enter Into Waiting State?

    There are three ways for a thread to enter into waiting state. By invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method.

  • What Is The Difference Between Static And Non Static Variables ?

    A static variable is associated with the class as a whole rather than with specific instances of a class. There will be only one value for static variable for all instances of that class. Non-static variables take on unique values with each object instance.

  • What Is The Difference Between Notify And Notifyall Method?

    notify wakes up a single thread that is waiting for object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. notifyAll Wakes up all threads that are waiting on this object's monitor. A thread waits on an object's monitor by calling one of the wait methods.

  • What Are Different Type Of Exceptions In Java?

    There are two types of exceptions in java. Checked exceptions and Unchecked exceptions. Any exception that is is derived from Throwable and Exception is called checked exception except RuntimeException and its sub classes. The compiler will check whether the exception is caught or not at compile time. We need to catch the checked exception or declare in the throws clause. Any exception that is derived from Error and Runtime Exception is called unchecked exception. We don't need to explicitly catch a unchecked exception.

  • Explain About The Select Method With An Example?

    Select part is useful in selecting text or part of the text. Arguments specified for the select command are the same as applicable to substring. First index is usually represents the start of the index. End of line makers are counted as one character. Example t.select (10,15) .

  • Can There Be An Abstract Class With No Abstract Methods In It?

    Yes.

  • Can We Define Private And Protected Modifiers For Variables In Interfaces?

    No.

  • What Is Garbage Collection? What Is The Process That Is Responsible For Doing That In Java?

    Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process.

  • Can There Be An Abstract Class With No Abstract Methods In It?

    Yes.

  • Can An Interface Have An Inner Class?

    Yes.

    public interface abc {
    static int i=0;
    void dd();
    class a1 {
    a1() {
    int j;
    System.out.println("in interfia");
    };
    public static void main(String a1[]) {
    System.out.println("in interfia"); } } }
  • What Is User Defined Exception?

    Apart from the exceptions already defined in Java package libraries, user can define his own exception classes by extending Exception class.

  • What Is The Difference Between Logical Data Independence And Physical Data Independence?

    Logical Data Independence - meaning immunity of external schemas to changed in conceptual schema.

    Physical Data Independence - meaning immunity of conceptual schema to changes in the internal schema.

  • What Are The Practical Benefits, If Any, Of Importing A Specific Class Rather Than An Entire Package (e.g. Import Java.net.* Versus Import Java.net.socket)?

    It makes no difference in the generated class files since only the classes that are actually used are referenced by the generated class file. There is another practical benefit to importing single classes, and this arises when two (or more) packages have classes with the same name. Take java.util.Timer and javax.swing.Timer, for example. If I import java.util.* and javax.swing.* and then try to use "Timer", I get an error while compiling (the class name is ambiguous between both packages). Let’s say what you really wanted was the javax.swing.Timer class, and the only classes you plan on using in java.util are Collection and HashMap. In this case, some people will prefer to import java.util.Collection and import java.util.HashMap instead of importing java.util.*. This will now allow them to use Timer, Collection, HashMap, and other javax.swing classes without using fully qualified class names in.

  • How Many Methods Do U Implement If Implement The Serializable Interface?

    The Serializable interface is just a "marker" interface, with no methods of its own to implement. Other ’marker’ interfaces are
    java.rmi.Remote
    java.util.EventListener

  • What Does The "abstract" Keyword Mean In Front Of A Method? A Class?

    Abstract keyword declares either a method or a class. If a method has a abstract keyword in front of it,it is called abstract method.Abstract method has no body.It has only arguments and return type.Abstract methods act as placeholder methods that are implemented in the subclasses.

    Abstract classes can’t be instantiated.If a class is declared as abstract,no objects of that class can be created.If a class contains any abstract method it must be declared as abstract.

  • You Can Create A String Object As String Str = "abc"; Why Cant A Button Object Be Created As Button Bt = "abc";? Explain

    The main reason you cannot create a button by Button bt= "abc"; is because "abc" is a literal string (something slightly different than a String object, by-the-way) and bt is a Button object. The only object in Java that can be assigned a literal String is java.lang.String. Important to note that you are NOT calling a java.lang.String constuctor when you type String s = "abc";

  • Can Rmi And Corba Based Applications Interact ?

    Yes they can. RMI is available with IIOP as the transport protocol instead of JRMP.

  • What Is Passed By Reference And Pass By Value ?

    All Java method arguments are passed by value. However, Java does manipulate objects by reference, and all object variables themselves are references.

  • What Is A "stateless" Protocol ?

    Without getting into lengthy debates, it is generally accepted that protocols like HTTP are stateless i.e. there is no retention of state between a transaction which is a single request response combination.

  • Difference Between A Class And An Object ?

    A class is a definition or prototype whereas an object is an instance or living representation of the prototype.

  • What Are The Four Corner Stones Of Oop?

    Abstraction, Encapsulation, Polymorphism and Inheritance.

  • 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 independent.

  • How Can A Dead Thread Be Restarted?

    A dead thread cannot be restarted.

  • What Happens If An Exception Is Not Caught?

    An uncaught exception results in the uncaughtException() method of the thread’s ThreadGroup being invoked, which eventually results in the termination of the program in which it is thrown.

  • What Is A Compilation Unit?

    A compilation unit is a Java source code file.

  • What Is A Task's Priority And How Is It Used In Scheduling?

    A task’s priority is an integer value that identifies the relative order in which it should be executed with respect to other tasks. The scheduler attempts to schedule higher priority tasks before lower priority tasks.

  • What Value Does Readline() Return When It Has Reached The End Of A File?

    The readLine() method returns null when it has reached the end of a file.

  • Can An Object's Finalize() Method Be Invoked While It Is Reachable?

    An object’s finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object’s finalize() method may be invoked by other objects.

  • Does Garbage Collection Guarantee That A Program Will Not Run Out Of Memory?

    Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection.

  • Is Sizeof A Keyword?

    The sizeof operator is not a keyword.

  • What State Does A Thread Enter When It Terminates Its Processing?

    When a thread terminates its processing, it enters the dead state.

  • Can A Lock Be Acquired On A Class?

    Yes, a lock can be acquired on a class. This lock is acquired on the class’s Class object.

  • How Are Observer And Observable Used?

    Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.

  • What Is A Transient Variable?

    transient variable is a variable that may not be serialized.

  • Wha Is The Output From System.out.println("hello"+null); ?

    Hellonull.

  • What Are E And Pi?

    E is the base of the natural logarithm and PI is mathematical value pi.

  • If An Object Is Garbage Collected, Can It Become Reachable Again?

    Once an object is garbage collected, it ceases to exist. It can no longer become reachable again.

  • Can An Exception Be Rethrown?

    Yes, an exception can be rethrown.

  • What Is The Purpose Of The File Class?

    The File class is used to create objects that provide access to the files and directories of a local file system.

  • Is A Class Subclass Of Itself?

    No. A class is not a subclass of itself.

  • What Modifiers May Be Used With An Interface Declaration?

    An interface may be declared as public or abstract.

  • What Classes Of Exceptions May Be Caught By A Catch Clause?

    A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.

  • What Is The Difference Between The Reader/writer Class Hierarchy And The Inputstream/outputstream Class Hierarchy?

    The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.

  • Can An Object Be Garbage Collected While It Is Still Reachable?

    A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected.

  • What Is An Object's Lock And Which Object's Have Locks?

    An object’s lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object’s lock. All objects and classes have locks. A class’s lock is acquired on the class’s Class object.

  • How Are Commas Used In The Intialization And Iteration Parts Of A For Statement?

    Commas are used to separate multiple statements within the initialization and iteration parts of a for statement.

  • What Must A Class Do To Implement An Interface?

    It must provide all of the methods in the interface and identify the interface in its implements clause.

  • What Is The Difference Between Preemptive Scheduling And Time Slicing?

    Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.

  • What Restrictions Are Placed On The Location Of A Package Statement Within A Source Code File?

    A package statement must appear as the first line in a source code file (excluding blank lines and comments).

  • What Are Wrapped Classes?

    Wrapped classes are classes that allow primitive types to be accessed as objects.

  • Is It Possible To Specify Multiple Jndi Names When Deploying An Ejb?

    No. To achieve this you have to deploy your EJB multiple times each specifying a different JNDI name.

  • What Is Java And Their Uses?

    Java is an object-programming language that was designed to be portable across multiple platforms and operating systems. Developed by Sun Microsystems, Java is modeled after the C++ programming language and includes special features that make it ideal for programs on the Internet. Still, you may be wondering why Java is suddenly receiving so much hype, and what possible improvements could have been made to this new language so as to push aside a well-established language such as C++.

    First and foremost, Java makes it easy to put interactive graphics and other special effects on a World Wide Web page. As with any programming language, Java lets you write programs. Special Java programs, called applets, execute inside a Web page with a capacity matching that of any traditional program. Furthermore, when you run a Java applet, the remote server, Java transmits the applet to your browser across the Internet. So rather than going out to a computer store to buy software, Java applets let you download applications automatically when you need them.

  • What Is Hotjava?

    Programmers often mention the name "HotJava" in the same breath as Java. Whereas Java is a programming language, HotJava was the first Web browser that could download and play (execute) Java applets. HotJava, created by Sun, is simply a browser, much like the Netscape Navigator or Microsoft's Internet Explorer.

    Although HotJava was the first browser to support Java applets, many browsers now support or will soon support applets. Starting with Netscape Navigator 2.0, for example, you can play Java applets for many platforms (Windows 95, the Mac, and so on). Another distinguishing feature of HotJava is that unlike most browsers which are written in C/C++, the HotJava browser is written with the Java programming language.

  • How Can You Say Java Is Object Oriented?

    Java is an object-oriented programming language which means you can use Java to develop your programs in terms of data and the methods (functions) that operate on the data. In Java, a class is a collection of the data and methods which describe an object with which your program works. Think of an object as a "thing," such as a graphics image, a dialog box, or a file.

    Java applets can arrange classes in hierarchical fashion which means you can build new classes from existing classes, improving upon or extending the existing class's capabilities. Everything in Java, except for a few primitive types such as numbers, characters, and boolean (true and false) types, is an object. Java comes with an extensive set of classes that you can use in your programs. In fact, a Java applet itself is a Java class.

  • Why Java Is Platform Independent? Explain.

    When you write and compile a Java applet, you end up with a platform-independent file called a bytecode. Like a standard program, a bytecode consists of ones and zeros. Unlike a standard program, however, the bytecode is not processor specific. In other words, the bytecode does not correspond to an Intel Pentium or a Motorola processor. Instead, after the server downloads the bytecode to your browser, special code within the browser reads and interprets the bytecode, in turn running the applet. To run the bytecode in this way, the interpreter translates the platform independent ones and zeros into ones and zeros your computer's processor understands. In other words, it maps the bytecode to ones and zeros that correspond to the current processor, such as a Pentium.

    Each computer platform (Mac, Windows, and so on) can have its own Java interpreter. However, the bytecode file that the server downloads to each browser is identical. In this way, you use the same bytecode on a browser running on a Mac, a PC, or a Silicon Graphics workstation. The multi-platform bytecode file is just one aspect of Java's portability. Java's designers also took the extra effort to remove any platform dependence in the Java language. Thus, you will not find any hardware specific references in Java.

  • Why Java Is Secure? Explain.

    A computer virus is a program written by someone who to maliciously damage the files you have stored on your disks or your computer's disk itself. To encounter a virus from across the Internet, you must download and run a program. Unfortunately, with Java applets, a remote sever downloads the applet to a browser on your system which, in turn, runs the applet. At first glance these downloaded Java applets are an ideal way for malicious programmers to create viruses. Luckily, the Java developers designed Java with networking in mind. Therefore, Java has several built-in security defenses which reduce a programmer's ability to use Java to create a virus.

    First, Java applets cannot read or write local files that reside on your disk. In this way, the applet cannot store the virus on your disk or attach the virus to a file. That the applet simply cannot perform disk input and output. Second, Java applets are "blind" to your computer's memory layout. Specifically, Java applets do not have pointers to memory, and programmers cannot use this traditional back door to your computer. Third, Java cannot use memory outside its own memory space. By building these precautions into programming language itself, the Java developers have greatly impaired Java's use in creating and transmitting computer viruses.

  • Why Do People Says "java Is Robust"?

    When people talk about code being robust, they are referring to the code's reliability. Although Java has not eliminated unreliable code, it has made writing high-quality software easier. To begin, Java eliminates many of the memory problems that are common in languages such as C and C++. Java does not support direct access to pointers to memory. As a result, a Java applet cannot corrupt your computer's memory. Also, Java performs run-time checks (while the applet is running) to make sure that all array and string references are within each items's bounds. In other programming languages, many software bugs result from the program not freeing memory that ought to be freed or freeing the same memory more than once. Java, on the other hand, performs automatic garbage collection (which releases unused memory), eliminating the program's need to free unused memory.

    Next, Java is more strongly typed than C++ and requires method declarations, which reduces the potential for type-mismatch errors. Finally, Java institutes an error trapping method known as exception handling. When a program error occurs Java signals the program with an exception, which provides the program with a chance to recover from the error- and warns the user that something caused a specific operation to fail.

  • How Java Is Similar To C?

    If you are already familiar with C/C++, you will find that Java is actually a simpler language to master. Java incorporates the basic tenets of object-oriented design, yet it eliminates some of the more complicated of the other language, such as multiple inheritance and templates. Many of the language keywords are the same or have only minor differences, which increases portability.

    If you are a C programmer dreading the seemingly inevitable push toward C++, you may rejoice over Java's cleaner approach to object-oriented programming. In fact, you want to skip C++ altogether and learn Java instead. Java's manageable selection of predefined classes are both useful and easy to understand. Many of the common operations that may take you hundreds or thousands of lines of code are already done for you. For example, you can write a simple network chat program without having to know much about sockets, protocols, and other low-level network issues.

  • What's The Difference Between Applets And Standalone Program?

    Sun designed Java from the start to fit hand-in-glove on the Internet. Applets are special Java programs that execute from within a Web browser. In contrast, a Java application (an application program as opposed to an applet) does not run within a browser. As it turns out, Java applets are not much different from standalone Java application. You can start developing your Java program from either an applet or an application and cross over any time. For example, assume that you are writing a new Java-based application that is initially designed as a standalone (non-Internet) game for Mac computers. At the end of your program's development cycle, you decide that you want it to run on Web browsers. Your task to make it into a Web-based applet involves very trivial changes, and the addition of some simple HTML code. At the same time, you will find that the game will also run on computers other than Macs! The point you should remember is that Java applets run within browsers across the Web, whereas Java application programs do not.

  • Why Java Applets Are More Useful For Intranets As Compared To Internet?

    An intranet is an in-house version of the Internet. An intranet uses the same technologies, software, and equipment that the Internet uses (primarily TCP/IP). Whereas the Internet has information servers miles away controlled by other organizations, your company controls the servers and client computers inside your office in an intranet. During the past year, intranets have experienced explosive popularity growth because they offer a very low cost way for companies to maintain and distribute internal information in an easy-to-use format.

    Because intranets work like the Internet, Java also finds a home on company intranets. All the techniques that you will learn and, in fact the same applets that you will use for the Internet, may be applied in your intranet. You may find that Java applets will help you solve special software problems within the intranet. You can use applets to provide a friendly interface to company databases, documentation stores, equipment controls, and so on, while running on any computer from a Mac to a PC to a UNIX workstation.

  • How Can You Set The Applet Size?

    Java applets run within their own window: Within your HTML file, you set the size of an applet window, using the <APPLET> tag's WIDTH and HEIGHT attributes. The size values you specify for each attribute are in pixels. For example, the following <APPLET> entry creates applet window that is 30 pixels tall by 100 pixels wide:

    <APPLET CODE=clock.class  WIDTH=100 HEIGHT=30> </APPLET>
  • How Can You Set An Applet's Height And Width As A Percentage?

    You use the <APPLET> tag WIDTH and HEIGHT attributes to specify the pixel size of an applet window. In addition to letting you specify the applet window size in terms of pixels, many browsers let you specify the applet window's size as a percentage of the browser's window's size. You do this by specifying a percentage value for the HEIGHT and WIDTH attributes within the <APPLET> tag. For example, the following <APPLET> entry creates an applet window based on 50% of the height and 100% of the width of the browser's window:

    <applet code=test.class width=100% height=50%> </applet>.
  • What Is Codebase?

    The Java applets your browser executes reside in a file with the .class extension. When you create a Web page, you can store you Java .class files in a directory which is different from the directory that contains the page's HTML files. Within the HTML <APPLET> tag, you can use the CODEBASE attribute to specify the directory within which the applet's .class files reside. The CODEBASE location can be a directory on the same computer or a directory at another computer. The CODEBASE attribute specifies (to the browser) the base URL (relative or specifies) of the directory that contain the .class files. If an <APPLET> tag does not use the CODEBASE attribute, the browser uses the current directory (the one containing the HTML file) to locate the .class files. The following <APPLET> tag directs the browser to look for the applet files in the directory called /server_a/applets.

    <APPLET CODE="MyFirst.class"CODEBASE^"/server_a/applets" WIDTH=300 
    HEIGHT=300>.</APPLET>
  • What Is Appletviewer?

    Most Java development environments include a special program called an appletviewer. using the appletviewer, you can execute your applet just as if it were running within a Web page displayed a browser. In most cases, the appletviewer can run your applet faster than a browser, making the appletviewer convenient for testing your applet. As you develop your applet, you will want to run it each time you add features. By using the appletviewer, you can quickly try out your applet without starting your Java-enabled Web browser. You run the appletviewer that accompanies Sun's Java Developer's Kit from the command line, specifying the name of the HTML file that contains the <APPLET> entry for applet you want to view:

    C:> appletviewer SomeFileName.HTML <ENTER>
  • Explain, Java Is Compatible With All Servers But Not All Browsers?

    When a Java applet runs over a network, two sides are working. One is the server, which is responsible for maintaining and handling browser requests for the various files it controls. On the server side, a Java applet is just a file like any other file an HTTP server already handles. You do not need any special server software for Java since the real work of executing the Java applet is performed by the browser, not the server.

    On the other side is the client, or browser, which request, receives, and interprets files from the server. The browser is responsible for displaying the Web page, playing sounds, running animations and. in general, determining the type of data the server is sending and handling that data accordingly.

    When a Web page contains a Java applet, the page's HTML file will contain an <APPLET> entry. If the browser is Java-enabled, the browser will request the applet file from the server. The server, in turn, will send the applet's bytecode to the browser, which will start its Java interpreter to execute the code.

  • What Is The Program Development Process?

    • Depending on what development package you use to create your Java programs, will go about compiling, organizing, and testing your programs in different ways. However, the general development process is mostly the same no matter which package or platform you use.
    • As discussed, the end result of the Java programs development process is a bytecode file which the server downloads to the browser for interpretation and execution. When you compile your Java source file, you are creating a bytecode file. Java source-code files, on the other hand, contain the class definitions and program statements you write using the Java language. In addition to the Java source-code files, you must create a small HTML file, which the browser uses to invoke your applet.
    • After the compiler creates the bytecode and you create an HTML file, you can test your applet using either your browser or an appletviewer. If your applet contains errors, many Java development environments provide a debugger program that you can use to track down the errors. When you are ready to release your applet to the public, you must place the applet and a corresponding HTML file on a Web server.
    • Therefore, the general development cycle of a Java applet includes the creation of source-code and HTML files, compiling the source into bytecode, testing the bytecode through an appletviewer, detecting and removing any errors from the applet using a debugger and, finally, releasing the applet for use on a Web server.
  • What Is The File Type?

    • When you create Java source-code files that contain classes and methods, you need to be aware of the Java file-naming convention. Each Java source-code file must end with the Java extension. In addition, the file's name must match the name of the public class the file defines. For example, if your source-code file creates a class named MorphaMatic, your source-code file must use the name MorphaMatic.java. As you can see, the letters of the source-code file name must match the class name exactly, including the use of upper and lowercase letters.
    • The HTML file that you use to run the applet can have any name. As a rule, however, you should use the standard extension for your system, typically .html or .htm. Also, to help organize your files, you may want to use a name similar to that of your applet for the HTML file name, such as MorphaMatic. html.
    • Finally, the bytecode file the Java compiler creates will have the .class extension. In this case, the bytecode file will have the name MorphaMatic.class. As discussed, the .class file is the file the Web server downloads to your browser which, in turn, interprets and executes the files's contents.
  • What Is Javac_g?

    As you have learned, the javac compiler examines your source-code files and produces the bytecode .class files. As your Java applets become more complex, it may become difficult for you to locate errors (bugs) within your code. To help you locate such errors, most Java development environments provide a special debugger program. In the case of the Sun's Java Developer's Kit, the debugger program is named jdb (for Java debugger). To provide jdb with more information to work with, the Sun's JDK provides special version of the compiler named javac__g. Sun designed the javac _g compiler for use with debuggers. Essentially, javacjg is a non-optimized version of the javac compiler which place tables of information within the bytecode that the debugger can use to track down errors. To compile a Java applet using the javac__g compiler, you simply specify the applet source-file named within the javac^g command line, as shown here:

    C:JAVACODE> javac „ g SomeFile.Java <Enter>
  • How To Optimize The Javac Output?

    When you compare the performance of a Java program against that of a C/C++ program, you will find that the current generation of Java programs can be as much as twenty times slower than their C/C++ counterparts. This performance loss is mostly due to the fact that the browser musf interpret the Java bytecode and convert it into the computer's native code (such as a Pentium or Motorola-specific code) before the code can run. In C/C++, the code is in the processor's native format to begin with, so this time-consuming translation step is not required. Remember, however, that Java's generic bytecode allows the same Java code to run on multiple platforms.
    The Java designers are working on various solutions to speed up Java. In the meantime, you can use the -O compiler switch with javac, which may increase the applet's performance. The -0 switch directs javac to optimize its bytecode by "inlining" static, final and private methods. For now, don't worry what "inlining" such code means other than it may improve your applet performance. Unfortunately, when you use inlining, you may increase the size of your bytecode file, which will increase the applet's download time. The following Javac command illustrates how you use the -0 switch:

    C:JAVACODE> javac -O  MyFirst.java  <Enter>
  • What Is The Difference Between Java Applets And Applications?

    • With Java, you can create two types of programs: an applet or an application. As you have learned, a Java applet is a program that executes from within a Web browser. A Java application, on the other hand, is a program that is independent of the browser and can run as a standalone program.
    • Because an applet is run from within a Web browser, it has the advantage of having an existing vindow and the ability to respond to user interface events provided though the browser. In addition, because applets are designed for network use Java is much restrictive in the types of access that applets can have to your file system than it is with non-network applications.
    • As you will, when you write a Java application, you must specify a main method (much like the C/ C++ main), which the program executes when it begins. Within the main method, you specify the functionality that your application performs. With an applet, on the other hand, you need to write additional methods that respond to events which are an important part of the applet's life cycle. The methods include init, start, stop, destroy and paint. Each of these events has a corresponding method and, when the event occurs, Java will call the appropriate method to handle it.
    • When you write your first Java programs, you can write them as if .they were applets and use the appletviewer to execute them. As it turns out, you can later convert your applet to an application by replacing your init method with a main method.
  • Can You Explain The Cs Option Of Java Interpreter?

    When you develop Java using Sun's JDK, you normally compile your source by using the javac compiler. If no compile errors exist, you then run your application using the java interpreter. As a shortcut, you can specify the -cs command-line switch when you invoke the java interpreter. The java command, in turn, will automatically compile out-of-date (modified) source-code files for you.
    By using the -cs switch, you can make changes to your source and immediately execute the java interpreter without having to manually run the java compiler yourself. The java interpreter knows which files it needs to recompile by comparing each file's modification dates against the corresponding class modification date. Normally, programmers use the -cs option when they have made a minor change to the source files and know that the files contain no compilation errors. The following command illustrates the use of the -cs switch:

    C: JAVACODE> Java -cs MyProgram <Enter>
  • What Is The Statements?

    A Java program consists of instructions that you want the computer to perform. Within a Java applet, you use statements to express these instructions in a format the Java compiler understands. If you are already familiar with C/C++, you will discover that Java statements are very similar. For example, the following statements produce a programs which prints the words "Hello, Java!" in applet window:

    import java.applet.*; import java.awt.Graphics;
    public class hello_java extends Applet {
    public void paint(Graphics g) {
    g.drawstring("Hello,  Java!",  20,  20); } }
  • What Is Style And Indentation?

    As you write Java programs, you will discover that you have considerable flexibility in how you line your statements and indent lines. Some editor programs help you line up indented lines and indent new block. If you have already programmed in another language, you probably have your own style of indentation. Java does not impose any specific style, However, you may want to be consistent with your own style and always be conscious that a well-formatted program is easier to read and maintain. For example, the following two programs function equivalently. However, one is much easier to read than the other:

    import java.applet. * ;
    public class am_i_readable extends 
    Applet{public void  init()
    {
    System.out.println("Can you guess whatI do?");
    }
    }
      
    
    import java.applet.*;
     public class am__i_readable extends Applet 
    { 
    public void init() 
    {    
    System.out.println("Can you guess  what I do?"); 
    } 
    }
  • What Is The Program Compilation Process?

    When you create programs, you will normally follow the same steps. To begin, you will use an editor to create your source file. Next, you will compile the program using a Java compiler. If the program contains syntax errors, you must edit the source file, correct the errors, and re-compile.
    After the program successfully compiles, the compiler generates a new file, known as bytecode. By using a Java interpreter, or appletviewer, you can execute the bytecode to test if it runs successfully. If the program does not work as you expected, you must review the source code to locate the error. After you correct the error, you must compile the source code to create a new byte code file. You can then test the new program to ensure that it performs the desired task. This illustrates the program development process.

  • What Is Java Literals?

    Literals correspond to a specific value in your Java program. For example, if you type the number 7 (the literal number 7) in a Java program, Java will treat the value as an int type. If you use the character JC within single quotes (V), Java will treat it as a char type. Likewise, if you place the literal x within double quotes Ox'), Java will treat it as a String. Depending on the literal you are using, Java provides special rules for hexadecimal, octal, characters, strings and boolean values. As you will learn, you can force a literal to be a certain type. For example, Java will treat the number 1 as an int. But you can force Java to treat the value as the type long by appending the L character to the literal number: 1L.

  • What Is The Primitive Type Byte?

    A byte is a primitive Java data type that uses eight bites to represent a number ranging from -128 to 127. The following statements declare two byte variables. The first variable, flag_bits, can store one value. The second byte variable, data_table, is an array, capable of holding four values. In this case, the Java compiler will preassign the array elements using the values specified between the left and right braces:

    • byte flag__bits;
    • byte data__table = { 32, 16, 8, 4 }; // Creates an array.
  • What Is The Primitive Type Short?

    The type short is a primitive Java data type that uses two bytes to represent a number in the range -32768 to 32767. The Java type short is identical to the two-byte hit in many C/C++ compilers.
    The following statements declare two variables of type short:
    short age;
    short height, width;

  • Why Call By Value Prevents Parameter Value Change?

    • When you pass primitive types such as the types float, boolean, hit and char to a method, Java passes the variables by value. In other words, Java makes a copy of the original variable which the method can access and the original remains unchanged. Within a method, the code can change the values as much as it needs because Java created these values as copies of the originals.
    • Wherever you pass a primitive type as a parameter to a method, Java copies this parameter to a special memory location known as the stack. The stack maintains information about variables used by the method while the method executes. When the method is complete, Java discards the stack's contents and the copies of the variables you passed into the method are gone forever.
    • Because Java copies your original primitive type parameters, there is never any danger of a method altering your original values. Remember, this only applies to primitive types, which are automatically passed by value. Objects and arrays are not passed by value (instead they are passed by reference) and they are in danger of being changed.
  • What Is Remote Method Invocation (rmi)?

    As you develop more complicated Java applets, and as other developers publish their own applet, you may find that you need to have your Java objects invoke other Java object methods residing on other computers. This is a natural extension of Java—you are able to use Java-based resources throughout the Web to give your applet additional functionality. Remote Method Invocation (RMI) lets methods within your Java objects be invoked from Java code that may be running in a different virtual machine, often on another computer.

  • What Is Java Jit Compilers?

    • When your Java-enabled browser connects to a server and tries to view a Web page that contains a Java applet, the server transmits the bytecode for that applet to your computer. Before your browser can run the applet, it must interpret the bytecode data. The Java interpreter performs the task of interpreting the bytecode data.
    • As you have learned, using an interpreter to read bytecode files makes it possible for the same bytecode to run on any computer (such as a Window-based or Mac-based computer) that supports Java. The big drawback is that interpreters can be 20 to 40 times slower than code that was custom or native, for a specific computer.
    • As it turns out, a new type of browser-side software, called a Just-In-Time compiler (JIT), can convert (compile) the bytecode file directly into native code optimized for the computer that is browsing it. The JIT compiler will take the bytecode data sent by the server and compile it just before the applet needs to run. The compiled code will execute as fast as any application you already use on your computer. As you might expect, the major compiler and IDE manufacturers, such as Borland, Microsoft, Symantec and Metroworks, are all developing JIT compilers.
  • What Is The Java Idl System?

    The Interface Definition Language (IDL) is an industry standard format useful for letting a Java client transparently invoke existing IDL object that reside on a remote server. In addition, it allows a Java server to define objects that can be transparently invoked from IDL clients. The Java IDL system lets you define remote interfaces using the IDL interface definition language which you can then compile with the idlgen stub generator tool to generate Java interface definitions and Java client and server stubs.

  • What Is Java Beans?

    Java Beans is the name of a project at JavaSoft to define a set of standard component software APIs (Application Programmers Interface) for the Java platform. By developing these standards, it becomes possible for software developers to develop reusable software components that end-users can then hook together using application-builder tools. In addition, these API's make it easier for developers to bridge to existing component models such as Microsoft's ActiveX, Apple's OpenDoc and Netscape's LiveConnect.

  • What Is Object-oriented Programming?

    To programmers, an object is a collection of data and methods are a set of operations that manipulate the data. Object-oriented programming provides a way of looking at programs in terms of the objects (things) that make up a system. After you have identified your system's objects, you can determine the operations normally performed on the object. If you have a document object, for example, common operations might include printing, spell-checking, faxing or even discarding.

    Object-oriented programming does not require a special programming language such as Java.You can write object-oriented programs in such languages as C++ or Java or C#. However, as you will learn, languages described as "object-oriented" normally provide class-based data structures that let your programs group the data and methods into one variable. Objects-oriented programming has many advantages, primarily object reuse and ease of understanding. As it turns out, you can often use the object that you write for one program in another program. Rather than building a collection of function libraries, object-oriented programmers build class libraries. Likewise, by grouping an object's data and methods, object-oriented programs are often more readily understood than their non-object- based counterparts.

  • What Is Abstraction?

    Abstraction is the process of looking at an object in terms of its methods (the operations), while temporarily ignoring the underlying details of the object's implementation. Programmers use abstraction to simplify the design and implementation of complex programs. For example, if you are told to write a word processor, the task might at first seem insurmountable. However, using abstraction, you begin to realize that a word processor actually consists of objects such as a document object that users will create, save, spell-check and print. By viewing programs in abstract terms, you can better understand the required programming. In Java, the class is the primary tool for supporting abstraction.

  • What Is Encapsulation?

    As you read articles and books about object-oriented programming and Java, you might encounter the term encapsulation. In the simplest sense, encapsulation is the combination of data and methods into a single data structure. Encapsulation groups together all the components of an object. In the "object-oriented" sense, encapsulation also defines how your programs can reference an object's data. Because you can divide a Java class into public and private sections; you can control the degree to which class users can modify or access the class data. For example, programs can only access an object's private data using public methods defined within the class. Encapsulating an object's data in this way protects the data from program misuses. In Java, the class is the fundamental tool for encapsulation.

  • How Does The Application Server Handle The Jms Connection?

    1. App server creates the server session and stores them in a pool.
    2. Connection consumer uses the server session to put messages in the session of the JMS.
    3. Server session is the one that spawns the JMS session.
    4. Applications written by the Application programmers creates the message listener.
  • What Is A Superclass?

    When you derive one class from another in Java, you establish relationships between the various classes. The parent class (or the class it is being derived from) is often called the superclass or base class. The superclass is really an ordinary class which is being extended by another class. In other words, you do not need to do anything special to the class in order for it to become a superclass. Any of the classes you write may some day become a superclass if someone decides to create a new subclass derived from your class.

    Of course, you can prevent a class from becoming a superclass (that is, do not allow it to be extended). If you use the final keyword at the start of the class declaration, the class cannot be extended.

  • Explain The Abstract Class Modifier?

    As you have learned, Java lets you extend an existing class with a subclass. Over time, you may start to develop your own class libraries whose classes you anticipate other programmers will extend. For some classes, there may be times when it does not make sense to implement a method until you know how a programmer will extend the class. In such cases, you can define the method as abstract, which forces a programmer who is extending the class to implement the method.

    When you use the abstract keyword within a class, a program cannot create an instance of that class. As briefly discussed, abstract classes usually have abstract methods which the class did not implement. Instead, a subclass extends the abstract class and the subclass must supply the abstract method's implementation. To declare a class abstract, simply include the abstract keyword within the class definition, as shown:

    public abstract class Some abstract Class
    {
    }
  • What Is The Final Class Modifier?

    As you have learned, Java lets one class extend another. When you design a class, there may be times when you don't want another programmer to extend the class. In such cases, by including the final keyword within a class definition, you prevent the class from being subclassed. The following statement illustrates the use of the final keyword within a class definition:

    public final class TheBuckStopsHere
    {
    }
  • Explain The Public Class Modifier.

    As you develop Java programs, there may be times when you create classes that you don't want the code outside of the class package (the class file) to access or even to have the knowledge of.
    When you use the public keyword within a class declaration, you make that class visible (and accessible) everywhere. A non-public class, on the other hand, is visible only to the package within which it is defined. To control access to a class, do not include the public keyword within the class declaration. Java only lets you place one public class within a source-code file. For example, the following statement illustrates the use of the public keyword within a class:

    public class ImEverywhereYouWantMeToBe
    {
    }
  • What Is The Public Field Modifier?

    A variable's scope defines the locations within a program where the variable is known. Within a class definition, you can control a class member variable's scope by preceding a variable's declaration with the public, private or protected keywords. A public variable is visible (accessible) everywhere in the program where the class itself is visible (accessible). To declare a variable public, simply use the public keyword at the start of the variable declaration, as shown:
    public int seeMeEveryWhere;

  • Explain The Private Field Modifier?

    To control a class member variable's scope, you can precede the variable's declaration with the public, private or protected key words. A private variable is only visible within its class. Subclasses cannot access private variables. To declare a variable private, simply use the private keyword at the start of the variable declaration, as shown:
    private int InvisibleOutside;

  • Explain The Protected Field Modifier?

    To control a class member variable's scope, you can precede the variable's declaration with the public, private ox protected keywords. A protected variable is one that is only visible within its class, within subclasses or within the package that the class is part of. The different between a private class member and a protected class member is that & private class member is not accessible within a subclass. To declare a variable protected, simply use the protected keyword at the start of the variable declaration, as shown:

    protected int ImProtected;

  • Can You Explain The Private Protected Field Modifier?

    To control a class member variable's scope, you can precede the variable's declaration with the public, private or protected keywords. A private protected variable is only visible within its class and within subclasses of the class. The difference between a protected class member and a private protected variable is that a private protected variable is not accessible within its package. To declare a variable private protected, simply use the private protected keyword at the start of variable declaration, as shown:

    private protected int ImPrivateProtected;

  • What Is The Static Field Modifier?

    Class member variables are often called instance variables because each instance of the class, each object, gets its own copy of each variables. Depending on your program's purpose, there may be times when the class objects need to share information. In such cases, you can specify one or more class variables as shared among the objects. To share a variable among class objects, you declare the variable as static, as shown:

    public static int ShareThisValue;

    In this case, if object changes the value of the ShareThisValue variables, each object will see the updated value.

  • What Is The Final Field Modifier?

    When you declare variable in a class final, you tell the compiler that the -variable has a constant value that program should not change. To define a final variable, you must also include an initializer that assigns a value to the constant. For example, the following statement creates a constant value named MAXJCEYS, to which the program assigns the value 256:

    protected static final int MAX_KEYS = 256;

  • Explain The Transient Field Modifier?

    When you declare a variable in a class transient, you tell Java that the variable is not a part of the object's persistent state. Currently, Java does not use the transient keyword. However, future (persistent) versions of Java may use the transient keyword to tell the compiler that the program is using the variable for "scratch pad" purposes and that the compiler does not need to save the variable to disk. The following statement illustrates the use of the transient keyword:

    transient float temp__swap__value;

  • Explain The Use Of Volatile Field Modifier?

    When you compile a program, the compiler will examine your code and perform some "tricks" behind the scenes that optimize your program's performance. Under certain circumstances, you may want to force the compiler not to optimize a variable. Optimization can make certain assumptions about where and how memory is handled. If, for example, you are building an interface to memory-mapped device, you may need to suppress optimization. To protect a variable from being optimized, you should use the volatile keyword, as shown:

    volatile double system_bit_flags;

  • What Is Default Constructors?

    When you create your classes, you should always provide one or more constructor methods. However, if you do not specify constructor, Java will provide a default constructor for you. Java's default constructor will allocate memory to hold the object and will then initialize all instance variables to their defaults. Java will not provide a default constructor, however, if your class specifies one or more constructor for the class.

  • What Is The Public Method Modifier?

    Using the public, private and protected keywords, you can control a variable's scope. In a similar way, Java lets you use these attributes with class methods as well. A public method is visible everywhere that the class is visible. To declare a method as public, simply precede the method header with the public keyword, as shown:

    public float myPublicMethod();

  • What Is The Private Method Modifier?

    Using the public, private and protected keywords, you can control a variable's scope. In a similar way, Java lets you use these attributes with class methods as well. A private method is only visible within its class. Subclasses cannot access private methods. To declare a method as private, simply precede the method header with the private keyword, as shown:

    private int myPrivateMethod();

  • What Is The Protected Method Modifier?

    Using the public, private and protected keywords, you can control a variable's scope. In a similar way, Java lets you use these attributes with class methods as well. A protected method is only visible within its class, within subclasses or within the class package. To declare a method as protected, simply precede the method header with the protected keyword, as shown:

    protected int myProtectedMethod();

  • Explain The Private Protected Method Modifier?

    Using the public, private and protected keywords, you can control a variable's scope. In a similar way, Java lets you use these attributes with class methods as well. A private protected method is only visible within its class and within subclasses of the class. The difference between a protected method and a private protected method is that a private protected method is not accessible throughout the class package. To declare method as private protected, simply precede the method header with the private protected keyword, as shown:

    private protected int myPrivateProtectedMethod();

  • Can You Explain The Final Method Modifier?

    Java lets you extend one class (the superclass) with another (the subclass). When a subclass extends a class, the subclass can override the superclass methods. In some cases depending on a method's , purpose, you may want to prevent a subclass from overriding a specific method. When you declare a class method as final, another class cannot override the methods. Methods which you declare static or private are implicitly final. To declare a method as final, simply precede the method header with the final keyword, as shown:

    public final CannotOverrideThisMethod();

  • What Is The Abstract Method Modifier?

    When the abstract keyword precedes a class method, you cannot create an instance of the class containing the method. Abstract methods do not provide an implementation. Instead, your abstract method definition only indicates the arguments return type. When a subclass extends the class containing the abstract method, the subclass is required to supply the implementation for the abstract method. To declare a method abstract, simply provides the abstract keyword , as follows:
    public abstract void implementMeLater(int x) ;

  • What Is The Synchronized Method Modifier?

    Java supports multiple threads of execution which appear to execute simultaneously within your program. Depending on your program's processing, there may be times when you must guarantee that two or more threads cannot access method at the same time. To control the number of threads that can access a method at any one time, you use the synchronized keyword. When the Java compiler encounters the synchronized keyword, the compiler will include special code that locks the method as one thread starts executing the method's instruction and later unlocks the method as the thread exits. Normally, programs synchronize methods that access shared data. The following statement illustrates the use of the synchronized keyword:

    synchronized void refreshData( )

  • Explain The Init Method?

    When a Web browser (or an appletviewer) runs a Java applet, the applet's execution starts with the init method. Think of the Java init method as similar to the main function in C/C++, at which the program's execution starts. However, unlike the C/C++ main function, when the Java init method ends, the applet does not end. Most applets use init to initialize key variables (hence, the name init). If you do not supply an init method within your applet, Java will run its own default init method which is defined in the Applet class library. The following statements illustrate the format of an init method:

    public void init()
    {
    //statements
    }

    The public keyword tells the Java compiler that another object (in this case, the browser) can call the init method from outside of the Applet class. The void keyword tells the Java compiler that the init method does not return a value to the browser. As you can see from the empty parentheses following the method name, init does not use any parameters.

  • What Is The Destroy Method?

    Each time your applet ends, Java automatically calls the destroy method to free up memory the applet was using. The destroy method is the compliment of the init method. However, you normally do not need to override, the destroy method unless you have specific resources that you need to remove, such as large graphical files or special threads that your applet has created. In short, the destroy method provides a convenient way to group your applet's "clean up" processing into one location, as shown:

    public void destroy() 
    {
      // Statements here 
    }
    
  • What Is Multithreading?

    Multithreading is the ability to have various parts of a program perform steps seemingly at the same time. For example, many Web browsers let users view various pages and click on hot links while the browser is downloading various pictures, text, sounds, and while drawing objects on the screen, The Java design began with the goal of supporting multiple threads of execution. Java lets programs interleave multiple program steps through the use of threads.

  • How Java Uses The String And Stringbuffer Classes?

    Java strings are immutable, which means after you create a String object, you cannot change that object's contents. The Java designers found that most of the time, programmers do not need to change a string after it is created. By making String objects immutable, Java can provide better error protection and more efficient handling of strings. However, in case you do need to change the String, you can use a class called StringBuffer as a temporary "scratchpad" which you use to make changes. In short, your programs can change the String objects you store within a Stringbuffer and later copy the buffer's contents back to the String object after your alterations are complete.

    In short, you should use String objects for "frozen" character strings whose contents you don't expect to change. In contrast, you should use the StringBuffer class for strings you expect to change in content or size. Within your programs, you can take advantage of features from both classes because both provide methods to easily convert between the two.

  • What Is The Epoch Date?

    Within a Java program, you can create a Date object by specifying a year, month, date and optionally, the hour, minute and second as parameters to the constructor function. You can also create a Date object with no arguments to the constructor, in which case the Date object will contain the current date and time. Finally, you can create a Date object by specifying the number of milliseconds since the epoch date, which is midnight GMT, January 1st, 1970. The Date class uses the epoch date as a reference point which lets your programs refer to subsequent dates in terms of a single long integer. You cannot set a year before 1970.

  • What Is An Arrays?

    Sometimes you will need to manipulate a series of related objects within an array object. Arrays let your programs work conveniently with a group of related objects. In short, an array simply lets you store and access a set of objects of the same type within the same variable. For example, you can use an array to keep track of grades for fifty students or to store a series of file names.

    Even though Java arrays are similar in syntax to C/C++ arrays, they have subtle differences. In Java, an array is basically an object that points to a set of other objects or primitive data types. The only visible difference between arrays and objects is that arrays have a special syntax to make them behave like the arrays found in other languages. Unlike C and C++, however, Java arrays cannot change in size, nor can a program use an out-of-bound index with a Java array. Also, you declare and create arrays in Java very differently than in C/C++.

  • What Is Binary Search?

    You know that you can find an element in an array by searching each element of the array one by one. Unfortunately, sequential searches are very inefficient for large arrays. If your array is sorted, you can use a binary search instead to locate a value within the array. A binary search repeatedly subdivides the array until it finds your desired element. For example, you have undoubtedly searched for a word in a dictionary. A sequential search is equivalent to searching each word one by one, starting from the very first word. If the word is much past the first page, this type of search is a very inefficient process.

    A binary search is equivalent to opening a dictionary in the middle, and then deciding if the word is in the first half or second half of the book. You then open the next section in the middle and if the word is in the first half or second half of that section. You can then repeat this process of dividing the book in half until you find the word for which you are looking. If you have never tried, pick a word and try to find it in a dictionary using a binary search technique. You might be surprised at how few divisions it takes to get very close to the word you are looking for. A binary search is very efficient. However, the array must be sorted for it to work.

  • Can A Private Method Of A Superclass Be Declared Within A Subclass?

    Sure. A private field or method or inner class belongs to its declared class and hides from its subclasses. There is no way for private stuff to have a runtime overloading or overriding (polymorphism) features.

  • What Is Quick Sort?

    For large arrays, you need an efficient sorting technique. One of the most efficient techniques is the quick sort. The quick sort technique takes the middle element of an array and sub-divides the array into two smaller arrays. One array will contain elements greater than the middle value of the original array. Conversely, the other array will contain elements that are less than the middle value. The quick sort will repeat this process for each new array until the final arrays contain only a single element. At this point, the single element arrays are in the proper order, as shown below

  • What Is The Difference Between Final, Finally And Finalize?

    •  final—declare constant
    •  finally—handles exception
    •  Finalize—helps in garbage collection.
  • In System.out.println( ), What Is System, Out And Println?

    System is a predefined final class, out is a PrintStream object and println is a built-in overloaded method in the out object.

  • What Is Meant By "abstract Interface"?

    First, an interface is abstract. That means you cannot have any implementation in an interface. All the methods declared in an interface are abstract methods or signatures of the methods.

  • What Is The Difference Between Swing And Awt Components?

    AWT components are heavy-weight, whereas Swing components are lightweight. Heavy weight components depend on the local windowing toolkit. For example, java.awt. Button is a heavy weight component, when it is running on the Java platform for Unix platform, it maps to a real Motif button.

  • Why Java Does Not Support Pointers?

    Because pointers are unsafe. Java uses reference types to hide pointers and programmers feel easier to deal with reference types without pointers. 

  • What Are Parsers? Dom Vs Sax Parser.

    Parsers are fundamental xml components, a bridge between XML documents and applications that process that XML. The parser is responsible for handling xml syntax, checking the contents of the document against constraints established in a DTD or Schema.

  • What Is A Platform?

    A platform is the hardware or software environment in which a program runs. Most platforms can be described as a combination of the operating system and hardware, like Windows 2000/XP, Linux, Solaris and MacOS.

  • What Is The Main Difference Between Java Platform And Other Platforms?

    The Java platform differs from most other platforms in that it's a software-only platform that runs on top of other hardware-based platforms, The Java platform has two components:

    1. The Java Virtual Machine (Java VM).
    2. The Java Application Programming Interface (Java API).
  • What Is The Java Virtual Machine?

    The Java Virtual Machine is software that can be ported onto various hardware-based platforms.

  • What Is The Java Api?

    The Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets.

  • What Is The Package?

    The package is a Java namespace or part of Java libraries. The Java API is grouped into libraries of related classes and interfaces; these libraries are known as packages.

  • What Is Native Code?

    The native code is a code that after you compile it, the compiled code runs on a specific hardware platform.

  • Is Java Code Slower Than Native Code?

    Not really. As a platform-independent environment, the Java platform can be a bit slower than native code. However, smart compilers, well-tuned interpreters, and just-in-time bytecode compilers can bring performance close to that of native code without threatening portability.

  • What Is The Serialization?

    The serialization is a kind of mechanism that makes a class or a bean persistence by having its properties or fields and state information saved and restored to and from storage.

  • How To Make A Class Or A Bean Serializable?

    By implementing either the java.io.Serializable interface or the java.io.Externalizable interface. As long as one class in a class's inheritance hierarchy implements Serializable or Externalizable, that class is serializable.

  • How Many Methods Are There In The Serializable Interface?

    There is no method in the Serializable interface. The Serializable interface acts as a marker, telling the object serialization tools that your class is serializable.

  • How Many Methods Are There In The Externalizable Interface?

    There are two methods in the Externalizable interface. You have to implement these two methods in order to make your class externalizable. These two methods are

    • readExternal() and
    • writeExternal().
  • Which Containers Use A Border Layout As Their Default Layout?

    The Window, Frame and Dialog classes use a border layout as their default layout.

  • What Is Synchronization And Why Is It Important?

    With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often causes dirty data and leads to significant errors.

  • What Are Three Ways In Which A Thread Can Enter The Waiting State?

    A thread can enter the waiting state by invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock or by invoking an object's wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.

  • What Is The Preferred Size Of A Component?

    The preferred size of a component is the minimum component size that will allow the component to display normally.

  • Can Java Object Be Locked Down For Exclusive Use By A Given Thread?

    Yes. You can lock an object by putting it in a "synchronized" block. The locked object is inaccessible to any thread other than the one that explicitly claimed it.

  • Can Each Java Object Keep Track Of All The Threads That Want To Exclusively Access It?

    Yes.

  • What Is The Purpose Of The Wait(), Notify() And Notifyall() Methods?

    The wait(), notify(), and notifyAll() methods are used to provide an efficient way for threads to wait for a shared resource. When a thread executes an object's wait() method, it enters the waiting state. It only enters the ready state after another thread invokes the object's notify() or notifyAll() methods.

  • What Are The High-level Thread States?

    The high-level thread states are ready, running, waiting and dead.

  • What Is The Collections Api?

    The Collections API is a set of classes and interfaces that support operations on collections of objects.

  • What Is The List Interface?

    The List interface provides support for ordered collections of objects.

  • How Many Bits Are Used To Represent Unicode, Ascii, Utf-16 And Utf-8 Characters?

    • Unicode requires 16 bits.
    • ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits.
    • UTF-8 represents characters using 8, 16, and 18 bit patterns.
    • UTF-16 uses 16-bit and larger bit patterns.
  • What Is The Properties Class?

    The properties class is a subclass of Hashtable that can be read from or written to a stream. It also provides the capability to specify a set of default values to be used.

  • What Is The Purpose Of The Runtime Class?

    The purpose of the Runtime class is to provide access to the Java runtime system.

  • What Is The Purpose Of The Finally Clause Of A Try-catch-finally Statement?

    The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.

  • What Is The Locale Class?

    The Locale class is used to tailor program output to the conventions of a particular geographic, political or cultural region.

  • What Is A Protected Method?

    A protected method is a method that can be accessed by any method in its package and inherited by any subclass of its class.

  • What Is A Static Method?

    A static method is a method that belongs to the class rather than any object of the class and doesn't apply to an object or even require that any objects of the class have been instantiated.

  • What Is The Difference Between A Window And A Frame?

    A frame is a resizable, movable window with title bar and close button. Usually it contains Panels. Its derived from a window and has a borderlayout by default.

    A window is a Container and has BorderLayout by default. A window must have a parent Frame mentioned in the constructor.

  • What Are Peerless Components?

    The peerless components are called light weight components.

  • What Is The Difference Between The Reader/writer Class Hierarchy And The Inputstream/outputstream Class Hierarchy?

    The Reader/Writer class hierarchy is character-oriented and the InputStream/OutputStream class hierarchy is byte-oriented.

  • What Is The Difference Between Throw And Throws Keywords?

    The throw keyword denotes a statement that causes an exception to be initiated. It takes the Exception object to be thrown as argument. The exception will be caught by an immediately encompassing try-catch construction or propagated further up the calling hierarchy. The throws keyword is a modifier of a method that designates that exceptions may come out of the method, either by virtue of the method throwing the exception itself or because it fails to catch such exceptions that a method it calls may throw.

  • Name Primitive Java Types?

    The primitive Java types are byte, char, short, int, long, float, double and boolean.

  • How Can A Gui Component Handle Its Own Events?

    A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.

  • What Advantage Do Java's Layout Managers Provide Over Traditional Windowing Systems?

    Java uses layout managers to layout components in a consistent manner across all windowing platforms. Since Java's layout managers aren't tied to absolute sizing and positioning, they are able to accommodate platform-specific differences among windowing systems.

  • What Are The Problems Faced By Java Programmers Who Don't Use Layout Managers?

    Without layout managers, Java programmers are faced with determining how their GUI will be displayed across multiple windowing systems and finding a common sizing and positioning that will work within the constraints imposed by each windowing system.

  • What Is The Difference Between Static And Non-static Variables?

    A static variable is associated with the class as a whole, rather than with specific instances of a class. Non-static variables take on unique values with each object instance.

  • What Is The Difference Between The Paint() And Repaint() Methods?

    The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.

  • What Is A Container In A Gui?

    A Container contains and arranges other components (including other containers) through the use of layout managers, which use specific layout policies to determine where components should go as a function of the size of the container.

  • Is Iterator A Class Or Interface? What Is Its Use?

    Iterator is an interface which is used to step through the elements of a Collection.

  • How You Can Force The Garbage Collection?

    Garbage collection is an automatic process and can't be forced.

  • Describe The Principles Of Oops?

    There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation.

  • Explain The Encapsulation Principle?

    Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by the other code defined outside the wrapper.

  • Explain The Inheritance Principle?

    Inheritance is the process by which one object acquires the properties of another object.

  • How To Define An Abstract Class?

    A class containing abstract method is called Abstract class. An Abstract class can't be instantiated.
    Example of Abstract class: abstract

    class testAbstractClass {
    protected String myString;
    public String getMyString() { return myString;
    }
    public abstract string anyAbstractFunction{);
    }
  • How To Define An Interface?

    In Java, Interface defines the methods but does not implement them. Interface can include constants. A class that implements the interfaces is bound to implement all the methods defined in Interface.
    Example of Interface:

    public interface samplelnterface { 
    public void functionOne(); 
    public long CONSTANTJDNE = 1000;
    }
  • Explain The Polymorphism Principle?

    The meaning of Polymorphism is something like one name, many forms. Polymorphism enables one entity to be used as a general category for different types of actions. The specific action is determined by the exact nature of the situation. The concept of polymorphism can be explained as "one interface, multiple methods".

  • Explain The Different Forms Of Polymorphism?

    From a practical programming viewpoint, polymorphism exists in three distinct forms in Java:

    • Method overloading
    • Method overriding through inheritance
    • Method overriding through the Java interface.
  • What Are Access Specifiers Available In Java?

    Access specifiers are keywords that determine the type of access to the member of a class. These are:

    • Public
    • Protected
    • Private
    • Defaults.
  • What Do You Understand By A Variable?

    The variables play a very important role in computer programming. Variables enable programmers to write flexible programs. It is a memory location that has been named so that it can be easily be referred to in the program. The variable is used to hold the data and it can be changed during the course of the execution of the program.

  • What Do You Understand By Numeric Promotion?

    The Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In the numerical promotion process the byte, char and short values are converted to int values. The int values are also converted to long values, if necessary the long and float values are converted to double values, as required.

  • Differentiate Between A Class And An Object.

    A Class is only the definition or prototype of real life object. Whereas an object is an instance or living representation of real life object. Every object belongs to a class and every class contains one or more related objects.

  • What Is The Use Of Object And Class Classes?

    The Object class is the superclass of all other classes and it is highest-level class in the Java class hierarchy. Instances of the class Class represent classes and interfaces in a running Java application. Every array also belongs to a class that is reflected as a Class object that is shared by all arrays with the same element type and number of dimensions. The primitive Java types (boolean, byte, char, short, int, long, float and double) and the keyword void are also represented as Class objects.

  • What Do You Understand By Casting In Java Language?

    The process of converting one datatype to another in Java language is called Casting.

  • What Are The Types Of Casting?

    There are two types of casting in Java, these are Implicit casting and Explicit casting.

  • What Do You Understand By Downcasting?

    The process of Downcasting refers to the casting from a general to a more specific type, i.e; casting down the hierarchy.

  • What Do You Understand By Final Value?

    FINAL for a variable: value is constant.

    FINAL for a method: cannot be overridden.

    FINAL for a class: cannot be derived.

  • What Are Keyboard Events?

    When Java generates a keyboard event, it passes an Event object that contains information about the key pressed, Java recognizes normal keys, modifier keys, and special keys, For normal keys, the event object contains the key's ASCII value. For the function, arrow and other special keys, there are no ASCII codes, so Java uses special Java-defined code. You have learned how to detect modifier keys. The modifier keys are stored in the modifiers variable in the Event object.

  • What Is The Intersection And Union Methods?

    When your program uses Rectangle objects, you may need to determine the screen region that holds both objects or two Rectangle objects intersect, to find the intersection or the union of two rectangles, you can use the Rectangle class intersection and union methods. The intersection method returns the area where two Rectangle objects overlap. That is, the intersecting method return the area that two Rectangle objects have in common.

    The union method, on the other hand, behaves differently than you might expect. The union method returns the smallest rectangle that encloses two Rectangle objects, instead of returning just the area covered by both objects. This illustrates the behavior of the intersection and union methods.

  • What Are Controls And Their Different Types In Awt?

    Controls are components that allow a user to interact with your application and the AWT supports the following types of controls:

    Labels, Push Buttons, Check Boxes, Choice Lists, Lists, Scrollbars, Text Components.

    These controls are the subclasses of the Component.

  • What Is The Difference Between Choice And List?

    A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices and only one item may be selected from a choice. A List may be displayed in such a way that several list items are visible and it supports the selection of one or more list items.

  • What Is The Difference Between Scrollbar And Scrollpane?

    A Scrollbar is a Component, but not a Container whereas Scrollpane is a Container and handles its own events and perform its own scrolling.

  • Which Containers Use A Flow Layout As Their Default Layout?

    Panel and Applet classes use the FlowLayout as their default layout.

  • What Are Wrapper Classes?

    Wrapper classes are classes that allow primitive types to be accessed as objects.

  • What Is The Difference Between Set And List?

    Set stores elements in an unordered way but does not contain duplicate elements, where as list stores elements in an ordered way but may contain duplicate elements.

  • How Can The Checkbox Class Be Used To Create A Radio Button?

    By associating Checkbox objects with a CheckboxGroup.

  • Which Textcomponent Method Is Used To Set A Textcomponent To The Read-only State?

    setEditable().

  • What Methods Are Used To Get And Set The Text Label Displayed By A Button Object?

    getLabel() and setLabel().

  • What Is The Difference Between Yield() And Sleep()?

    When a object invokes yield() it returns to ready state. But when an object invokes sleep() method enters to not ready state.

  • How To Handle A Web Browser Resize Operation?

    You know how important it is to suspend your threads when Java calls an applet's stop method. Normally, Java calls the stop method when a browser leaves the corresponding Web page. However, in some cases, a Web browser will unexpectedly call an applet's stop method. When a browser window is resized, the browser may first call the stop method and then the start method. If you only stop a thread when its applet stops and create a new thread when the applet restarts, the applet will probably not behave the way that a user expects. To prevent unwanted behavior after resizing the browser, your program should suspend threads when the applet stops and resume the threads when the applet starts.

  • Explain The Concept Of Hashtables?

    A hashtable is a data structure that lets you look up stored items using an associated key. With an array, you can quickly access an element by specifying an integer index. The limitation of an array is that the look up key can only be an integer. With a hashtable, on the other hand, you can associate an item with a key and then use the key to look up the item. You can use an object of any type as a key in a hashtable. For example, you might specify the license-plate number as the key and use the key to look up the vehicle owner's record. To distinguish one item from the next, the associated key that you use must be unique for each item, as in the case of a vehicle's license plate number.