java is an Object  Oriented Programming Language. Which is mostly used to develop Windows based Software  as well as Web Based Project. It is good to have good knowledge about a programming language and practical knowledge for developing program in that particular language. In the technical interview for the post of  Java Developer some basic questions are asked. In this post I am telling about questions at basic level. These questions are related to use of this and super Keyword operators, JVM and Jdk, Interface and access specifier, methods , class, java collections, serializable in java , hashtable , jsp servlet etc.









Q             How are this() and super() used with constructors?  
A             this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor

Q             What is casting?  
A             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.

Q             What is the purpose of the Runtime class?  
A             The purpose of the Runtime class is to provide access to the Java runtime system

Q             Does object serialization support encryption?  
A             Object serialization does not contain any encryption/decryption in itself. It writes to and reads from Java Streams, so it can be coupled with any available encryption technology. Object serialization can be used in many different ways from simple persistence, writing and read to/from files, or for RMI to communicate across hosts.

Q             Why is OutOfMemoryError thrown after writing a large number of objects into an ObjectOutputStream?  
A             The ObjectOutputStream maintains a table mapping objects written into the stream to a handle. The first time an object is written to a stream, its contents are written into the stream; subsequent writes of the object result in a handle to the object being written into the stream. This table maintains references to objects that might otherwise be unreachable by an application, thus, resulting in an unexpected situation of running out of memory. A call to the ObjectOutputStream.reset() method resets the object/handle table to its initial state, allowing all previously written objects to be eligible for garbage collection.

Q             Why is UTFDataFormatException thrown by DataOutputStream.writeUTF() when serializing a String?  
A             DataOutputStream.writeUTF() does not support writing out strings larger than 64K. The first two bytes of a UTF string in the stream are the length of the string. If a java.lang.String can be larger than 64K, it needs to be stored in the stream by an alternative method rather than depending on the default method of storing a String in the stream, writeUTF.

Q             How can I create an ObjectInputStream from an ObjectOutputStream without a file in between?  
A             ObjectOutputStream and ObjectInputStream work to/from any stream object. You could use a ByteArrayOutputStream and then get the array and insert it into a ByteArrayInputStream. You could also use the piped stream classes as well. Any java.io class that extends the OutputStream and InputStream classes can be used.
Alternatively, the ObjectOutputStream> class implements a reset method that discards the memory of having sent an object, so sending an object again will make a copy.

Q             Why a file that contains multiple appended ObjectOutputStreams can’t be deserialized by one ObjectInputStream?  
A             Using the default implementation of serialization, there must be a one-to-one mapping between ObjectOutputStream construction and ObjectInputStream construction. ObjectOutputStream constructor writes a stream header andObjectInputStream reads this stream header. A workaround is to subclass ObjectOutputStream and override writeStreamHeader(). The overriding writeStreamHeader() should call the super writeStreamHeader method if it is the first write to the file and it should call ObjectOutputStream.reset() if it is appending to a pre-existing ObjectOutputStream within the file.

Q             What is a platform?
A             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.

Q             What is the main difference between Java platform and other platforms?
A             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:
The Java Virtual Machine (Java VM)
The Java Application Programming Interface (Java API)

Q             What is the Java Virtual Machine?
A             The Java Virtual Machine is a software that can be ported onto various hardware-based platforms.

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

Q             What is the package?
A             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.

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

Q             Is Java code slower than native code?
A             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.

Q             What is the serialization?
A             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.

Q             How to make a class or a bean serializable?
A             By implementing the java.io.Serializable interface

Q             How many methods in the Serializable interface?
A             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.

Q             What is a transient variable?
A             A transient variable is a variable that may not be serialized. If you don't want some field to be serialized, you can mark that field transient or static.

Q             Which containers use a border layout as their default layout?
A             The Window, Frame and Dialog classes use a border layout as their default layout.

Q             What is synchronization and why is it important?
A             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.

Q             What are synchronized methods and synchronized statements?
A             Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.

Q             What are three ways in which a thread can enter the waiting state?
A             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.

Q             Can a lock be acquired on a class?
A             Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.

Q             What's new with the stop(), suspend() and resume() methods in JDK 1.2?
A             The stop(), suspend() and resume() methods have been deprecated in JDK 1.2.

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

Q             What method is used to specify a container's layout?
A             The setLayout() method is used to specify a container's layout.

Q             Which containers use a FlowLayout as their default layout?
A             The Panel and Applet classes use the FlowLayout as their default layout.

Q             What is thread?
A             A thread is an independent path of execution in a system.

Q             What is multithreading?
A             Multithreading means various threads that run in a system.

Q             How does multithreading take place on a computer with a single CPU?
A             The operating system's task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.

Q             How to create multithread in a program?
A             You have two ways to do so. First, making your class "extends" Thread class. Second, making your class "implements" Runnable interface. Put jobs in a run() method and call start() method to start the thread.

Q             Can Java object be locked down for exclusive use by a given thread?
A             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.

Q             Can each Java object keep track of all the threads that want to exclusively access to it?
A             Yes.

Q             What state does a thread enter when it terminates its processing?
A             When a thread terminates its processing, it enters the dead state.

Q             What invokes a thread's run() method?
A             After a thread is started, via its start() method of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.

Q             What is the purpose of the wait(), notify(), and notifyAll() methods?
A             The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to communicate each other.

Q             What are the high-level thread states?
A             The high-level thread states are ready, running, waiting, and dead.

Q             What is the Collections API?
A             The Collections API is a set of classes and interfaces that support operations on collections of objects.

Q             What is the List interface?
A             The List interface provides support for ordered collections of objects.

Q             How does Java handle integer overflows and underflows?
A             It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.

Q             What is the Vector class?
A             The Vector class provides the capability to implement a growable array of objects

Q             What modifiers may be used with an inner class that is a member of an outer class?
A             A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.

Q             If a method is declared as protected, where may the method be accessed?
A             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.

Q             What is an Iterator interface?
A             The Iterator interface is used to step through the elements of a Collection.

Q             How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
A             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.

Q             What is the difference between yielding and sleeping?
A             When a task invokes its yield() method, it returns to the ready state. When a task invokes its sleep() method, it returns to the waiting state.

Q             Is sizeof a keyword?
A             The sizeof operator is not a keyword.

Q             What are wrapped classes?
A             Wrapped classes are classes that allow primitive types to be accessed as objects.

Q             Does garbage collection guarantee that a program will not run out of memory?
A             No, it doesn't. 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

Q             What is the difference between preemptive scheduling and time slicing?

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


All The Best ....!