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 the base class of all classes?
java.lang.Object and java.lang package is imported by default even without a package declaration.
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 are instance variables, local, member and a class variables?
Instance variables are declared in a class, but outside a method, constructor or any block. Instance variables need not be initialized before using them as they are automatically initialized to their default values.
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.
A field variable is a variable that is declared as a member of a class.
What is a transient variable?
Transient variable is a variable that may not be serialized.
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.
main() method?
Main() method doesn't return anything hence declared void.main() method is called by the JVM even before the instantiation of the class hence it is declared as static. main() method accepts an array of String object as arguement.
protected access specifier?
The protected access modifier cannot be applied to class and interfaces. Methods, fields can be declared protected, however methods, variables and fields in a interface cannot be declared protected.A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package.
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.
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.
static ?
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.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.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).A static method should not refer to instance variables without creating an instance and cannot use "this" operator to refer the instance.
Can an Interface implement or extend another Interface?
Intefaces doesn't provide implementation hence a interface cannot implement another interface. Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface.
Can a class or interface be defined inside an Interface?
Yes it's possible.
What is a Marker Interface?
An Interface which doesn't have any declaration inside but still enforces a mechanism.
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 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.
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.
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 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?
Overriding methods must have the same name, parameter list
Overriding methods must have either same or co-variant return types
Overriding methods mustn't have more restrictive access modifier. i.e. if base class method is public, overriden method can't have private access modifier
Overriding methods mustn't throw any broader checked exception than base class method.
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 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 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 is a native method?
A native method is a method that is implemented in a language other than Java.
Does a class inherit the constructors of its superclass?
A class does not inherit constructors from any of its superclasses.
What does Anonymous class mean?
An anonymous class is just what its name imples -- it has no name. It combines the class declaration and the creation of an instance of the class in one step. An anonymous class must always extend a super class or implement an interface but it cannot have an explicit extends or implements clause.An anonymous class always uses the default constructor from the super class to create an instance.
HelloWorld frenchGreeting = new HelloWorld() {
String name = "tout le monde";
public void greet() {
greetSomeone("tout le monde");
}
public void greetSomeone(String someone) {
name = someone;
System.out.println("Salut " + name);
}
};
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 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
To what value is a variable of the boolean type automatically initialized?
The default value of the boolean type is false.
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. However class name conflicts are solved. 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).
What is constructor chaining and how is it achieved in Java ?
In Java you can call one constructor from another and it’s known as constructor chaining in Java. Don’t confuse between constructor overloading and constructor chaining, former is just a way to declare more than one constructor in Java. this and super keyword is used to call one constructor from other in Java. this() can be used to call other constructor of same class while super() can be used to call constructor from super class in Java. Just keep in mind that this() in realty calls no argument constructor of same class, while this(2) calls another constructor of same class which accepts one integer parameter. Similarly super() can be used to call no argument constructor of super class and super with parameter can be used to call other overloaded constructor of parent class
What is the difference between the Boolean & operator and the && operator?
If an expression involving the Boolean & operator is evaluated, both operands are evaluated. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true only then the second operand is evaluated else skipped.
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 the base class of all classes?
java.lang.Object and java.lang package is imported by default even without a package declaration.
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 are instance variables, local, member and a class variables?
Instance variables are declared in a class, but outside a method, constructor or any block. Instance variables need not be initialized before using them as they are automatically initialized to their default values.
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.
A field variable is a variable that is declared as a member of a class.
What is a transient variable?
Transient variable is a variable that may not be serialized.
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.
main() method?
Main() method doesn't return anything hence declared void.main() method is called by the JVM even before the instantiation of the class hence it is declared as static. main() method accepts an array of String object as arguement.
protected access specifier?
The protected access modifier cannot be applied to class and interfaces. Methods, fields can be declared protected, however methods, variables and fields in a interface cannot be declared protected.A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package.
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.
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.
static ?
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.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.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).A static method should not refer to instance variables without creating an instance and cannot use "this" operator to refer the instance.
Can an Interface implement or extend another Interface?
Intefaces doesn't provide implementation hence a interface cannot implement another interface. Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface.
Can a class or interface be defined inside an Interface?
Yes it's possible.
What is a Marker Interface?
An Interface which doesn't have any declaration inside but still enforces a mechanism.
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 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.
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.
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 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?
Overriding methods must have the same name, parameter list
Overriding methods must have either same or co-variant return types
Overriding methods mustn't have more restrictive access modifier. i.e. if base class method is public, overriden method can't have private access modifier
Overriding methods mustn't throw any broader checked exception than base class method.
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 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 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 is a native method?
A native method is a method that is implemented in a language other than Java.
Does a class inherit the constructors of its superclass?
A class does not inherit constructors from any of its superclasses.
What does Anonymous class mean?
An anonymous class is just what its name imples -- it has no name. It combines the class declaration and the creation of an instance of the class in one step. An anonymous class must always extend a super class or implement an interface but it cannot have an explicit extends or implements clause.An anonymous class always uses the default constructor from the super class to create an instance.
HelloWorld frenchGreeting = new HelloWorld() {
String name = "tout le monde";
public void greet() {
greetSomeone("tout le monde");
}
public void greetSomeone(String someone) {
name = someone;
System.out.println("Salut " + name);
}
};
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 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
To what value is a variable of the boolean type automatically initialized?
The default value of the boolean type is false.
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. However class name conflicts are solved. 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).
What is constructor chaining and how is it achieved in Java ?
In Java you can call one constructor from another and it’s known as constructor chaining in Java. Don’t confuse between constructor overloading and constructor chaining, former is just a way to declare more than one constructor in Java. this and super keyword is used to call one constructor from other in Java. this() can be used to call other constructor of same class while super() can be used to call constructor from super class in Java. Just keep in mind that this() in realty calls no argument constructor of same class, while this(2) calls another constructor of same class which accepts one integer parameter. Similarly super() can be used to call no argument constructor of super class and super with parameter can be used to call other overloaded constructor of parent class
What is the difference between the Boolean & operator and the && operator?
If an expression involving the Boolean & operator is evaluated, both operands are evaluated. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true only then the second operand is evaluated else skipped.
No comments:
Post a Comment