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 Variable, operators, JVM and Jdk, Interface and access specifier. 





interview questions on java for freshers


Basics Important Questions  for freshers from Core Java



Q             Can there be an abstract class with no abstract methods in it?  
A             Yes.
Q             Can an Interface be final?
A             No.
Q             Can an Interface have an inner class?  
A             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");
                        }
            }
 }

Q             Can we define private and protected modifiers for variables in interfaces?  
A             No

Q             What is Externalizable?  
A             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)

Q             What modifiers are allowed for methods in an Interface?  
A             Only public and abstract modifiers are allowed for methods in interfaces.

Q             What is a local, member and a class variable?  
A             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

Q             I made my class Cloneable but I still get 'Can't access protected method clone. Why?  
A             you have to implement your own public clone() method, even if it doesn't do anything special and just calls super.clone().

Q             Can we overload main method in java?  
A             Yes. But the main method with String args[] is called when you call the program (java Test1) Have a look at this demo.
 public class Test1{
            public static void main(String[] args){
                        System.out.println("in main method");
            }
            public static void main(String args[],String arg){
                        System.out.println("in overload method");
            }
}
Q             What are some alternatives to inheritance?  
A             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).

Q             Why isn't there operator overloading?  
A             Because C++ has proven by example that operator overloading makes code almost impossible to maintain. In fact there very nearly wasn't even method overloading in Java, but it was thought that this was too useful for some very basic methods like print(). Note that some of the classes like DataOutputStream have unoverloaded methods like writeInt() and writeByte().

Q             What does it mean that a method or field is "static"?  
A             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.

Q             Difference between JRE And JVM AND JDK  

Java Development Kit (JDK)
A software development environment for writing applets and applications in the Java programming language. Technically, the JDK is the correct name for all versions of the Java platform.
Java virtual machine
A software "execution engine" that safely and compatibly executes the byte codes in Java class files on a microprocessor (whether in a computer or in another electronic device
Java Runtime Environment (JRE)
A subset of the Java Development Kit (JDK) for end-users and developers who want to redistribute the runtime environment alone. The Java runtime environment consists of the Java virtual machine1, the Java core classes, and supporting files.

Q             Why do threads block on I/O?  
A             Threads block on i/o (that is enters the waiting state) so that other threads may execute while the i/o Operation is performed

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 leads to significant errors.

Q             Is null a keyword?  
A             The null value is not a keyword.

Q             Which characters may be used as the second character of an identifier, but not as the first character of an identifier?  
A             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.

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             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 are wrapped classes?  
A             Wrapped classes are classes that allow primitive types to be accessed as objects.

Q             What restrictions are placed on the location of a package statement within a source code file?  
A             A package statement must appear as the first line in a source code file (excluding blank lines and comments).

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.

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

Q             What is order of precedence and Associativity, and how are they used?  
A             Order of precedence determines the order in which operators are evaluated in expressions. Associativity determines whether an expression is evaluated left-to-right or right-to-left

Q             What is the catch or declare rule for method declarations?  
A             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.

Q             Can an anonymous class be declared as implementing an interface and extending a class?  
A             An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.

Q             What is the range of the char type?  
A             The range of the char type is 0 to 2^16 - 1.

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

Q             What is the difference between the Boolean & operator and the && operator?  
A             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.

Q             How many times may an object's finalize() method be invoked by the garbage collector?  
A             An object's finalize() method may only be invoked once by the garbage collector.

Q             What is the purpose of the finally clause of a try-catch-finally statement?  
A             The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.

Q             What is the argument type of a program's main() method?  
A             A program's main() method takes an argument of the String[] type.

Q             Which Java operator is right associative?  
A             The = operator is right associative.

Q             Can a double value be cast to a byte?  
A             Yes, a double value can be cast to a byte.

Q             What is the difference between a break statement and a continue statement?  
A             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.

Q             What must a class do to implement an interface?  
A             It must provide all of the methods in the interface and identify the interface in its implements clause.

Q             What is the advantage of the event-delegation model over the earlier event-inheritance model?  
A             The event-delegation model has two advantages over the event-inheritance model. First, it enables event handling to be handled by objects other than the ones that generate the events (or their containers). This allows a clean separation between a component's design and its use. The other advantage of the event-delegation model is that it performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to repeatedly process unhandled events, as is the case of the event-inheritance model.

Q             How are commas used in the intialization and iteration parts of a for statement?  
A             Commas are used to separate multiple statements within the initialization and iteration parts of a for statement.

Q             What is an abstract method?  
A             An abstract method is a method whose implementation is deferred to a subclass.

Q             What value does read() return when it has reached the end of a file?  
A             The read() method returns -1 when it has reached the end of a file.

Q             Can a Byte object be cast to a double value?  
A             No, an object cannot be cast to a primitive value.

Q             What is the difference between a static and a non-static inner class?  
A             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.

Q             If a variable is declared as private, where may the variable be accessed?  
A             A private variable may only be accessed within the class in which it is declared.

Q             What is an object's lock and which object's have locks?  
A             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.

Q             What is the % operator?  
A             It is referred to as the “modulo” or “remainder” operator. It returns the remainder of dividing the first operand by the second operand.

To read more on core java questions and answer click here -

Short Questions Answer from Core Java



Keywords: Java Technical Questions, Java Interview Questions,