• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/34

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

34 Cards in this Set

  • Front
  • Back

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 final, finalize() and finally?

final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can’t be overridden. A final variable can’t change from its initialized value. finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection. finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address this contingency.

What is UNICODE?
Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other.
What is Garbage Collection and how to call it explicitly?
When an object is no longer referred to by any variable, java automatically reclaims memory used by that object. This is known as garbage collection. System. gc() method may be used to call it explicitly.
What are Transient and Volatile Modifiers?
Transient: The transient modifier applies to variables only and it is not stored as part of its object’s Persistent state. Transient variables are not serialized. Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.
What is difference between overloading and overriding?-
a) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method. b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass. c) In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass. d) Overloading must have different method signatures whereas overriding must have same signature.
What is meant by Inheritance and what are its advantages?-
Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.

What is the difference between this() and super()?-

- this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.
What modifiers may be used with top-level class?
public, abstract and final can be used for top-level class.
What are inner class and anonymous class?
Inner class : classes defined in other classes, including those defined in methods are called inner classes. An inner class can have any accessibility including private. Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.
What is a reflection package?
java. lang. reflect package has the ability to analyze itself in runtime.
What is an abstract class?
An abstract class is a class designed with implementation gaps for subclasses to fill in and is deliberately incomplete.
What is the difference between Integer and int?
a) Integer is a class defined in the java. lang package, whereas int is a primitive data type defined in the Java language itself. Java does not automatically convert from one to the other. b) Integer can be used as an argument for a method that requires an object, whereas int can be used for calculations.
What is the difference between abstract class and interface?-
a) All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract. b) In abstract class, key word abstract must be used for the methods whereas interface we need not use that keyword for the methods. c) Abstract class must have subclasses whereas interface can’t have subclasses.
Can you have an inner class inside a method and what variables can you access?

Yes, we can have an inner class inside a method and final variables can be accessed.

What is the difference between String String Buffer and String Builder?

a) String objects are constants and immutable whereas StringBuffer objects are not. b) String class supports constant strings whereas StringBuffer class supports growable and modifiable strings.

As of release JDK 5, this class has been supplemented with an equivalent class designed for use by a single thread, {StringBuilder}. The StringBuilder class should generally be used in preference to this one, as it supports all of the same operations but it is faster, as it performs no synchronization

What is the difference between exception and error?
The exception class defines mild error conditions that your program encounters. Exceptions can occur when trying to open the file, which does not exist, the network connection is disrupted, operands being manipulated are out of prescribed ranges, the class file you are interested in loading is missing. The error class defines serious error conditions that you should not attempt to recover from. In most cases it is advisable to let the program terminate when such an error is encountered.

What is the difference between process and thread?

Process is a program in execution whereas thread is a separate path of execution in a program.
What is multithreading and what are the methods for inter-thread communication and what is the class in which these methods are defined?-

Multithreading is the mechanism in which more than one thread run independent of each other within the process. wait (), notify () and notifyAll() methods can be used for inter-thread communication and these methods are in Object class. wait() : When a thread executes a call to wait() method, it surrenders the object lock and enters into a waiting state. notify() or notifyAll() : To remove a thread from the waiting state, some other thread must make a call to notify() or notifyAll() method on the same object.

What is the class and interface in java to create thread and which is the most advantageous method?

Thread class and Runnable interface can be used to create threads and using Runnable interface is the most advantageous method to create threads because we need not extend thread class here.

Briefly define high level thread states.

* NEW
A thread that has not yet started is in this state.

* RUNNABLE
A thread executing in the Java virtual machine is in this state.

* BLOCKED
A thread that is blocked waiting for a monitor lock is in this state.

* WAITING
A thread that is waiting indefinitely for another thread to perform a particular action is in this state.

* TIMED_WAITING
A thread that is waiting for another thread to perform an action for up to a specified waiting time is in this state.

* TERMINATED
A thread that has exited is in this state.

What is the difference between Runtime (unchecked) exceptions and checked exceptions?

Exception (checked exceptions) - Methods must explicitly declare the exceptions they throw and classes that invoke those methods must catch those exceptions.

RuntimeException (unchecked exception) -
Methods do not declare RuntimeExceptions and thus calling methods do not know about a RuntimeException nor do they have to handle them.

When to use checked and unchecked exceptions is a matter of debate. Proponents of checked exceptions argue that checked exceptions provide more documentation. Opponents say that checked exceptions lead to unstable method signatures (adding an exception changes the method signature), exposes the implementation and leads to unreadable code with multiple check blocks. If using unchecked exceptions, they should be documented
A catch all Exception block catch (Exception e) will catch all exceptions including RuntimeExceptions.
Explain the different ways of creating a thread
Implement the run method of the Runnable interface, then invoke start.

Subclass thread, then invoke start.
What are Java Class Loaders? What is dynamic class loading?
When the JVM is started, three class loaders are used:

1. Bootstrap class loader
2. Extensions class loader
3. System class loader

The bootstrap class loader loads the core Java libraries (/lib directory). This class loader, which is part of the core JVM, is written in native code.

The extensions class loader loads the code in the extensions directories (/lib/ext or any other directory specified by the java.ext.dirs system property). It is implemented by the sun.misc.Launcher$ExtClassLoader class.

The system class loader loads code found on java.class.path, which maps to the system CLASSPATH variable. This is implemented by the sun.misc.Launcher$AppClassLoader class.

User Defined Classloaders - Makes it possible to un or unloaded classes at runtime. also makes it possible to load encrypted java byte code.

Dynamic class loading is using java reflection to load objects:

Class aClass = classLoader.loadClass("com.jenkov.MyClass");
What is JAR hell?
The first case is when a developer or deployer of a Java application has accidentally made two different versions of a library available to the system.

Another version of the problem arises when two libraries (or a library and the application) require different versions of the same third library.
Explain Outer and Inner classes in Java. When do you use an inner class?
Outer classes are top level classes. A top level class does not appear inside another class or interface.

A member class is a class whose declaration is directly enclosed in another class or interface declaration. If the member class must have non static member types to be an inner class.

Inner classes also include local classes, which are named classes declared inside of a block like a method or constructor body, and anonymous classes, which are unnamed classes whose instances are created in expressions and statements.

* It is a way of logically grouping classes that are only used in one place.
* It increases encapsulation.
* Nested classes can lead to more readable and maintainable code.

Explain new features in Java 5 and Java 6.

Java 5
Generics, Enhanced for Loop, Autoboxing/Unboxing, Typesafe Enums, Varargs, Static Import, Metadata (Annotations)

Java 6
Improved Collections Framework
Explain static vs dynamic class loading
In Static class loading, the compiler has access to the class at compile time.
List mylist = new ArrayList();

In dynamic class loading, the compiler has access to the class at runtime.
List myList = (List)class.forName( someString ).newInstance();

Dynamic class loading allows the class to be changed (either through a configuration or by user input) without recompiling the code.
Explain the assertion construct
An assertion is a statement in the JavaTM programming language that enables you to test your assumptions about your program.

The assertion statement has two forms. The first, simpler form is:

assert Expression1 ;

where Expression1 is a boolean expression. When the system runs the assertion, it evaluates Expression1 and if it is false throws an AssertionError with no detail message.

The second form of the assertion statement is:

assert Expression1 : Expression2 ;

where:

* Expression1 is a boolean expression.
* Expression2 is an expression that has a value. (It cannot be an invocation of a method that is declared void.)

Use this version of the assert statement to provide a detail message for the AssertionError. The system passes the value of Expression2 to the appropriate AssertionError constructor, which uses the string representation of the value as the error's detail message.

What are the set interfaces and when would you use each?

java.util.TreeSet
Elements are sorted, not synchronized. null not allowed
java.util.HashSet
Not synchronized. Allows the null elements
java.util.CopyOnWriteArraySet
Thread safe, a fresh copy is created during modification operation. Add, update, delete are expensive.
java.util.EnumSet>
All of the elements in an enum set must come from a single enum type that is specified, explicitly or implicitly, when the set is created. Enum sets are represented internally as bit vectors.
java.util.LinkedHashSet
Same as HashSet, plus defines the iteration ordering, which is the order in which elements were inserted into the set.
Describe the list classes
java.util.Vector
Syncronized, use in multiple thread access, otherwise use ArrayList
java.util.Stack
It extends class Vector with five operations that allow a vector to be treated as a stack. It represents a last-in-first-out (LIFO) stack of objects.
java.util.ArrayList
Non-syncronized, use in single thread environment, otherwise use Vector
java.util.LinkedList
Non-syncronized, update operation is faster than other lists, easy to use for stacks, queues, double-ended queues.
javax.management.AtributeList
Represents a list of values for attributes of an MBean. The methods used for the insertion of Attribute objects in the AttributeList overrides the corresponding methods in the superclass ArrayList. This is needed in order to insure that the objects contained in the AttributeList are only Attribute objects.
javax.management.relation.RoleList
A RoleList represents a list of roles (Role objects). It is used as parameter when creating a relation, and when trying to set several roles in a relation (via 'setRoles()' method). It is returned as part of a RoleResult, to provide roles successfully retrieved.
javax.management.relation.RoleUnresolvedList
A RoleUnresolvedList represents a list of RoleUnresolved objects, representing roles not retrieved from a relation due to a problem encountered when trying to access (read or write to roles).
Describe the queue classes
java.util.PriorityQueue
orders elements according to an order/priority specified at construction time, null element is not allowed.
java.util.concorrent.ArrayBlockingQueue
orders elements FIFO; syncronized, thread safe.
java.util.concorrent.SyncronousQueue
each put must wait for a take, and vice versa, does not have any internal capacity, not even a capacity of one, an element is only present when you try to take it; you cannot add an element (using any method) unless another thread is trying to remove it
What are the map implementations?
java.util.TreeMap
guarantees that the map will be in ascending key order, sorted according to the natural order for the key's class, not-syncronized.
java.util.HashMap
is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls
java.util.concurrent.ConcurrentHashMap
same Hashtable, plus retrieval operations (including get) generally do not block, so may overlap with update operations (including put and remove).
java.util.Hashtable
Syncronized, null can not be used as key
java.util.WeakHashMap
entry in a WeakHashMap will automatically be removed when its key is no longer in ordinary use. Nonsyncronized.
java.util.LinkHashMap
This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order). Note that insertion order is not affected if a key is re-inserted into the map.
java.util.IdentityHashMap
This class implements the Map interface with a hash table, using reference-equality in place of object-equality when comparing keys (and values). In other words, in an IdentityHashMap, two keys k1 and k2 are considered equal if and only if (k1==k2). (In normal Map implementations (like HashMap) two keys k1 and k2 are considered equal if and only if (k1==null ? k2==null : k1.equals(k2)).) Not-syncronized.
java.util.EnumMap
All of the keys in an enum map must come from a single enum type that is specified, explicitly or implicitly, when the map is created. Enum maps are represented internally as arrays. This representation is extremely compact and efficient. Not-syncronized.
Explain the Java I/O streaming concept and the use of the decorator design pattern in Java I/O
The use of layered objects to dynamically and transparently add responsibilities to individual objects is referred to as the decorator pattern.

Decorators are often used when subclassing requires a large number of subclasses to support every possible combination needed – so many that subclassing becomes impractical.

FileInputStream fis = new FileInputStream(file);

BufferedInputStream bis = new BufferedInputStream(fis)