Shared Flashcard Set

Details

Week1
Core Java
28
Software
Undergraduate 4
04/22/2013

Additional Software Flashcards

 


 

Cards

Term
What is the difference between and interface and abstract classes?
Definition
Abstract class can have abstract and concrete methods. An interface must contain only abstract methods. (a marker interface has no methods)
Term
Can you instantiate an abstract class? Can you instantiate an interface?
Definition
NO Abstract classes are extended and interfaces are implemented.
Term
What is the difference between a Vector and an ArrayList?
Definition
Vector is synchronized (Thread safe).
Array list is not.
Term
What is the difference between a HashSet and a TreeSet?
Definition
They are two general implementations of Set. HashSet does not make any guarantees about ordering. The tradeoff is Hashset is faster that TreeSet.
Term
What type of collection will not allow duplication?
Definition
Set
Term
What is the difference between a HashTable and a HashMap?
Definition
a) HashTable is synchronized. Hashmap is not.
b) HashMap allows null values and a null key.
Term
How do you serialize or persist an object in Java?
Definition
Step 1) Mark the object a Serializable by implementing the java.io.Serializable interface. This signifies that the object is to be flattened into bytes and inflated in the future.

Step 2) Persist the oject. This is accomplished using the java.io.ObjectOutputStream class. This class is a filter stream that is wrapped around a low level byte stream (node stream) to handle the the serialization process for us. Node streams can be used to write to files systems or across sockets. This provides easy transfer of of flattened objects across the network. It will have be rebuilt on the other side.

Step 3) To restore the object, we use the java.io.ObjectInputStream.readObject() method call. The method call reads the raw bytes that we previously persisted and creates a live object that is an exact copy of the original object. Because the readObject() method can read any serializable object, a cast to the correct object type is required. With that in mind, the class file must be accessible from the system in which the restoration occurs. The class file and methods are not saved but the state is.
Term
What is a store procedure in Java? How would you call it?
Definition
A stored procedure is written in Java instead of PL/SQL. It is retained on a database. Stored procedures are executed by the JVM. The stored procedure is called by the Java class using a callable statement. When the procedure is called, its name and any relevant parameters are sent over the JDBC connection to the DBMS where the procedure is executed and applicable results are returned.
Term
What is the difference between a prepared statement and a statement?
Definition
prepared statements are pre-compiled. The database does not have to compile the statement each time it is executed.
Term
Can you force garbage collection?
Definition
No. It can be requested through System.gc();
Term
What is final, finalize() and finally?
Definition
final is a java keyword. Final variables cannot be changed from its initialized state. A final method cannot be overridden. A final class cannot be extended.

finalize() is a method used prior to an object being destroyed and just before garbage collection.

finally is used in exception handling. It creates a block of code that is ran regardless of whether or not an exception has been thrown. A classic case of its use is file closing.
Term
What is a marker interface?
Definition
An interface with no methods. A marker interface ins used to describe behavior(s) of a class. Serializable, Remote and Cloneable are examples.
Term
How would you clone an object?
Definition
First, tag the class withe the Clonable interface. Then invoke the clone() method. It is part of the Language API. Once the clone method is declared, a shallow copy is created.
Term
Why are strings immutable?
Definition
The String class in final.
Term
What are the differences between StringBuilder and StringBuffer?
Definition
StringBuffer is synchronous (thread safe). String builder are not. They both are mutable meaning they can be changed after creation.
Term
What is the difference between static and final variables?
Definition
Static variables are shared globally and can be changed (there is only a single copy). A final variable is constant. It cannot be changed from its initialized state.
Term
What are the implicit modifiers required for interface variables?
Definition
public static final
Term
What are transient variables?
Definition
Variables that cannot be serialized.
Term
What are access modifiers?
Definition
public- can be accessed from any package.
private- can only be accessed in the same class.
protected- can be accessed by classes in the package and sub-classes globally.

default - no access by classes or sub-classes outside of the package.
Term
What is a wrapper class?
Definition
Wrapper classes are designed to wrap around a primitive datatype. The the class representation of the primitive type. Once they are created they cannot be altered (immutable). Wrapper classes are often used in cases where primitive datatypes are not accepted. There are also methods that can be used by the wrapper classes. parsInt is a prime example
Term
What is the Reflection API?
Definition
The primary function of the reflection API is to fetch information about the class. This particular mechanism is built into the class (named Class). It describes meta-data for objects withing the Java system.

forName, getName , getConstructor, getMethod, getField, getSuperClass, getInterfaces, getDeclaredClass
Term
Is Java pass-by value or pass by reference?
Definition
Java is a strictly pass by value.
Term
What is encapsulation
Definition
This is known as data hiding. It is essentially a barrier that prevents code and data from being accesses randomly from outside the class. Access is tightly controlled by an interface.
Term
What is the difference between == and .equals()?
Definition
== compare two variables in the same instance. .equals() compares two objects that do not necessarily have to be in the same instance.
Term
What is polymorphism?
Definition
Subclasses of a class can have unique behaviors and attributes while inheriting the superclass' attributes and behaviors.
Term
What is inheritance?
Definition
A class that is derived from another class is called a subclass(child class). The class from which the child class is derrived is called the parent class. The child class can inherit some or all of the parent classes attributes and behaviors. Polymorphism is where a child class maintains unique attributes and behaviors while inheriting those of the parent class.
Term
What is the difference between method overriding and overloading?
Definition
Method overloading involves methods of same name differentiated by the arguments it test (parameters).


Method overriding is where an inherited method of the super class is overridden
Term
In what ways can you create a thread
Definition
Implementing Runnable interface or extending the Thread class
Supporting users have an ad free experience!