Java Flashcards
Java What is the difference between an interface and an Abstract class?
Interface can only declare constants and methods. However, interface can have default behavior.
Java Describe synchronization in respect to multithreading.
With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for the one thread to modify a shared variable while another thread is in the process if using or updating same share variable. This usually leads to significant errors.
Java Thread usage.
The thread could be implemented by using runnable interface or by inheriting from the thread class. The former is more advance advantageous, ‘cuase when you are going for multiple inheritance..the only interface can help.
Java What is a constructor.
A member method using to create the object. It has the same name as the class. invoked using the new operator.
What is an Iterator?
Allows to iterate through objects, collections of objects. Use Java.util.Iterator. It is best not to modify anything. Just read it only.
What is a public variable?
Public class is visible in
What is Java?
A high-level programming language developed by Sun Microsystems. Java was originally called OAK, and was designed for handheld devices and set-top boxes. Oak was unsuccessful so in 1995 Sun changed the name to Java and modified the language to take advantage of the burgeoning World Wide Web.`
What are the main features of java?
The main features of java are ■Compiled and Interpreted ■Object oriented ■Robust and secure ■Type safe ■High Performance.
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 Java Virtual Machine (JVM)?
The Java Virtual Machine is software that can be ported onto various hardware-based platforms.
Java What is variables and then types?
Variables is an identifier that denotes a storage location used to store a data values.unlike constants that remain unchanged during the execution of a program, a variable may takes different values at different times during the execution of the program. ■Instance variables ■Class variables ■Local variable ■Parameters
Java What is dot operator?
The dot operator(.) is used to access the instance variables and methods of class objects.It is also used to access classes and sub-packages from a package. Examples : Person1.age ———> Reference to the variable age
Java Define strings?
Strings represent a sequence of characters.The easiest way to represent a sequence of characters in java is by using a character array.
Java What is serialization?
Serialization is the process of converting a objects into a stream of bytes.
Java What are different types of access modifiers?
Access specifiers are keywords that determine the type of access to the member a class. ■Public ■Protected ■Private ■Default
Java What is the Collection interface?
The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates.
Java What must a class do to implement an interface?
The class must provide all of the methods in the interface and identify the interface in its implements clause.
Java What is the Collections API?
The Collections API is a set of classes and interfaces that support operations on collections of objects.
Java What is an array?
Array is a group of related data items that share a common name.For instance, we can define an array name salary to represent a set of salaries of a group of employees. Examples : salary[10]
java What is list iterator?
The List and Set collections provide iterators, which are objects that allow going over all the elements of a collection in sequence. The java.util.Iterator interface provides for one-way traversal and java.util.ListIterator is an iterator for lists that allows the programmer to traverse the list in either direction (i.e. forward and or backward) and modify the list during iteration.
Java What is the main difference between a String and a StringBuffer class?
String is immutable : you can’t modify a string object but can replace it by creating a new instance. Creating a new instance is rather expensive. StringBuffer is mutable : use StringBuffer or StringBuilder when you want to modify the contents. StringBuilder was added in Java 5 and it is identical in all respects to StringBuffer except that it is not synchronized,which makes it slightly faster at the cost of not being thread-safe.
Java When to use serialization?
A common use of serialization is to use it to send an object over the network or if the state of an object needs to be persisted to a flat file or a database.
Java What is the main difference between shallow cloning and deep cloning of objects?
Java supports shallow cloning of objects by default when a class implements the java.lang.Cloneable interface. Deep cloning through serialization is faster to develop and easier to maintain but carries a performance overhead.
Java What are wrapper classes?
primitive data types may be converted into object types by using the wrapper classes contained in the java.lang package. Exampes : int, float, long, char, double
Java What is the difference between an instance variable and a static variable?
variable per JVM per class loader.When a class is loaded the class variables are initialized. Instance variables are non-static and there is one occurrence of an instance variable in each class instance.Also known as a member variable or a field.
Java Where and how can you use a private constructor?
Private constructor is used if you do not want other classes to instantiate the object and to prevent subclassing.The instantiation is done by a public static method (i.e. a static factory method) within the same class.
Java What is type casting?
Type casting means treating a variable of one type as though it is another type. Examples : int m = 5; byte n =i;
Java What is a user defined exception?
User defined exceptions may be implemented by defining a new exception class by extending the Exception class.
Java What is an instanceof operator?
Instanceof is an object reference operator and returns true if the object on the left-hand side is an instance of the glass given to the right hand side.This operator allows to determine whether the object belongs to a particular class or not.
Java What are runtime exceptions?
Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc. These are not checked by the compiler at compile time.
Java What is the difference between an interface and an abstract class?
An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.
Java What is a package?
A package is a namespace that organizes a set of related classes and interfaces.The classes contained in the packages of other programs can be easily reused.Packages, classes can be unique compared with classes in other packages.That is, two classes in two different packages can have the same name.
Java Why do threads block on I/O?
Threads block on i/o (that is enters the waiting state) so that other threads may execute while the i/o Operation is performed.
Java What is the List interface?
The List interface provides support for ordered collections of objects.
Java What is the Vector class?
The Vector class provides the capability to implement a growable array of objects.
Java What is the base class of all classes?
java.lang.Object