0% found this document useful (0 votes)
44 views

What Is Pass by Value, Pass by Reference?: Hashtable

Pass by value means passing the value of a parameter to a method. Pass by reference means passing the reference or address of a parameter. The legacy classes in Java are Dictionary, Hashtable, Properties, Vector, and Stack. These classes provide functionality for storing and manipulating key-value pairs and lists but have largely been replaced by newer collection classes like HashMap and ArrayList.

Uploaded by

kumar554
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

What Is Pass by Value, Pass by Reference?: Hashtable

Pass by value means passing the value of a parameter to a method. Pass by reference means passing the reference or address of a parameter. The legacy classes in Java are Dictionary, Hashtable, Properties, Vector, and Stack. These classes provide functionality for storing and manipulating key-value pairs and lists but have largely been replaced by newer collection classes like HashMap and ArrayList.

Uploaded by

kumar554
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

what is pass by value, pass by reference?

Passing parameters as variables is called pass by value


passing parameters as address is called pass by refence

What are the legacy classes in java


The Legacy Classes which are defined by Java.utilare discussed below :
1. Dicitionary
2. Hashtable
3. Properties
4. Vector
5. Stack
The brief explanation about each of these five classes are taken as under:
Dictionary : It is an abstract class that denotes a key or a value storage space very much like the Map.Here we
can store the value in the dictionary instead of the Map if we have the key and the value of it. And we can
anytime retrieve this value with the help pf this unique key.

Hashtable : It is very much similar to hashMap if compared as it also stores the key/value pairs in the
table. While Using this we can mention an object that is used as a key, and the value that we want
linked to that key. The key is then hashed, and the resulting hash code is used as the index at which the
value is stored within the table.

Properties: It is a subclass of Hashtable. It is used to maintain lists of values in which the key is a String and
the value is also a String. It defines the following instance Variable: Properties defaults; It holds a default
property list which is related with a Properties Object.
Properties defines these two constructors:

Java Vectors. It implemnts a dynamic array very much similar to the ArrayList.It has few differences as it is
synchronized and conatins many legacy methods. It basically extends the AbstractList Class and implemnts
the List Interface. }
Stack: It is a sub class of Vector which implements a standard last-in, first-out stack.It defines only a default
constructor which creates an empty Stack and it includes all the methods defined by vector. We can call pop (
) method to remove and return the top. An EmptyStackException is thrown if you call pop( ) when the
invoking stack is empty. We can use peek( ) to return, but not remove, the top object.

Explain about enum?


An enum type is a type whose fields consist of a fixed set of constants the names of an enum type's fields are
in uppercase letters.
Ex:public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
}
Java programming language enum types are much more powerful than their counterparts in other
languages. The enum declaration defines a class (called an enum type). The enum class body can include
methods and other fields. The compiler automatically adds some special methods when it creates an enum.

What is collection and what are the collections that you have used ?
A collection — sometimes called a container — is simply an object that groups multiple elements into a single
unit. Collections are used to store, retrieve, manipulate, and communicate aggregate data
A collections framework is a unified architecture for representing and manipulating collections. All
collections frameworks contain the following:
 Interfaces: These are abstract data types that represent collections. Interfaces allow collections to be
manipulated independently of the details of their representation. In object-oriented languages,
interfaces generally form a hierarchy.
 Implementations: These are the concrete implementations of the collection interfaces. In essence, they
are reusable data structures.
 Algorithms: These are the methods that perform useful computations, such as searching and sorting,
on objects that implement collection interfaces. The algorithms are said to be polymorphic: that is, the
same method can be used on many different implementations of the appropriate collection interface.
In essence, algorithms are reusable functionality.

What is the hashmap and write a simple program that?


The HashMap class uses a hash table to implement the Map interface. This allows the execution time of basic
operations, such as get() and put(), to remain constant even for large sets.
: import java.util.*;
class HashMapDemo {
public static void main(String args[]) {
// Create a hash map
HashMap hm = new HashMap();
// Put elements to the map
hm.put("John Doe", new Double(3434.34));
hm.put("Tom Smith", new Double(123.22));
hm.put("Jane Baker", new Double(1378.00));
hm.put("Todd Hall", new Double(99.22));
hm.put("Ralph Smith", new Double(-19.08));
// Get a set of the entries
Set set = hm.entrySet();
// Get an iterator
Iterator i = set.iterator();
// Display elements
while(i.hasNext()) {
Map.Entry me = (Map.Entry)i.next();
System.out.print(me.getKey() + ": ");
System.out.println(me.getValue());
}
System.out.println();
// Deposit 1000 into John Doe's account
double balance = ((Double)hm.get("John Doe")).doubleValue();
hm.put("John Doe", new Double(balance + 1000));
System.out.println("John Doe's new balance: " +
hm.get("John Doe"));
}
}

Difference between ArrayList and Array?


An array is collection of similar data types, which stores primitive data types
An array list is a collection of objects, array list stores class object references .

What is annotation? Type of annotation? What is the use of annotation?

What is polymorphism?
Polymorphism is one name in many forms ,we can use same name with different parameters for methods .
example is method overloading and method overriding
Polymorphism is briefly described as "one interface, many implementations."
There are two types of polymorphism one is Compile time polymorphism and the other is run time
polymorphism. Compile time polymorphism is method overloading. Runtime time polymorphism is done
using inheritance and interface.
Note: From a practical programming viewpoint, polymorphism manifests itself in three distinct forms in Java:
Method overloading
Method overriding through inheritance
Method overriding through the Java interface

What is exception ?Different type of Exception?


An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of
the program's instructions. When an error occurs within a method, the method creates an object and
hands it off to the runtime system. The object, called an exception object, contains information about the
error, including its type and the state of the program when the error occurred. Creating an exception
object and handing it to the runtime system is called throwing an exception.
Exceptions in java are any abnormal, unexpected events or extraordinary conditions that may occur at
runtime. They could be file not found exception, unable to get connection exception and so on. On such
conditions java throws an exception object. Java Exceptions are basically Java objects. No Project can never
escape a java error exception. Mainly runtime errors are called exceptions,There are mainly two types of
exceptions
Checked Exceptions: JVM forced to handle the exceptions , those are called checked exceptions,
Checked exceptions are subclass’s of Exception excluding class RuntimeException and its subclasses. Checked
Exceptions forces programmers to deal with the exception that may be thrown. Example: Arithmetic
exception. When a checked exception occurs in a method, the method must either catch the exception and
take the appropriate action, or pass the exception on to its caller
Unchecked Exceptions: JVM does not forced to handle exceptions ,those are called unchecked exceptions
Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also
are unchecked. Unchecked exceptions , however, the compiler doesn’t force the programmers to either
catch the exception or declare it in a throws clause. In fact, the programmers may not even know that
the exception could be thrown. Example: ArrayIndexOutOfBounds Exception. They are either
irrecoverable (Errors) and the program should not attempt to deal with them, or they are logical
programming errors. (Runtime Exceptions). Checked exceptions must be caught at compile time. Runtime
exceptions do not need to be. Errors often cannot be.

Difference between static class and final class?Is Static class inheritable?
Static classes are inheritable.Simply put the keyword static in the declaration of the methods in the class. The
declaration of the class itself requires no special decoration. The class can contain static and non-static
methods and properties simultaneously.
final classes are not inheritable we can declare class as final by using final key word

What is array bound exception and when it occurs?


Whenever array size is not enough to store values then it gives array index bound exception. It occurs
dynamically at runt time

Can I inherit final class?


No
what is garbage collection?
The garbage collector attempts to reclaim the memory used by objects that will never be accessed again by the
application.
Vector v = null; v.add("a"); what will be the output?
Null pointer Exception

What is thread?
A thread is an independent path of execution within a program
Every thread in Java is created and controlled by the java.lang.Thread class. A Java program can have many
threads, and these threads can run concurrently, either asynchronously or synchronously.

what is synchronization? use of synchronization?


synchronization is the capability to control the access of multiple threads to shared resources. Without
synchonization, it is possible for one thread to modify a shared variable while another thread is in the process
of using or updating same shared variable. This usually leads to significant errors. 

What is multi threading?


Multithreading allows two parts of the same program to run concurrently.
multithreading is a form of multitasking. There are two distinct types of multitasking: process-based and
thread-based .In a thread-based multitasking environment, the thread is the smallest unit of dispatchable code.
Because a program can contain more than one thread, a single program can use multiple threads to perform
two or more tasks at once.

package com;
import java.util.Vector;
public class MethodOverLoad {
void display(String msg){
System.out.println("String parameter method::"+msg);
}
void display(Vector vmsg){
System.out.println("vector method call::"+vmsg);
}
public static void main(String args[]){
MethodOverLoad mol =new MethodOverLoad();
mol.display(null);
}}
What will be the output of above programme ?
Compilation error
The method display(String) is ambiguous for the type MethodOverLoad
Which will handle the ioexception if a catch block contain Exception followed by IOException? where
would control go if it also have a finally block.
It goes to finally block

How would you access superclass method from a subclass?


By using super key word;

Consider a super class object as A and subclass object as B then A=B is correct or not?
No

Write a code for userdefind exception?


NegativeAgeException.java
public class NegativeAgeException extends Exception {
private int age;
public NegativeAgeException(int age){
this.age = age;
}

public String toString(){


return "Age cannot be negative" + " " +age ;
}
}
CustomExceptionTest.java
public class CustomExceptionTest {

public static void main(String[] args) throws Exception{

int age = getAge();

if (age < 0){


throw new NegativeAgeException(age);
}else{
System.out.println("Age entered is " + age);
}
}

static int getAge(){


return -10;
}
}
In the CustomExceptionTest class, the age is expected to be a positive number. It would throw the user defined
exception NegativeAgeException if the age is assigned a negative number.
At runtime, we get the following exception since the age is a negative number.
Exception in thread "main" Age cannot be negative -10
at tips.basics.exception.CustomExceptionTest.main(CustomExceptionTest.java:10)

How to read xml file in java apllication(code) ?


OM parser is used to handle with XML in java. DOM is Document Object Model which handle whole
document and easy to use in application. DOM read the whole XML as document and keep in memory. Node
can be accessed by Elements through getNodeValue() method.

Difference between treemap,hashtable.


TreeMap actually implements the SortedMap interface which extends the Map interface. In a TreeMap the
data will be sorted in ascending order of keys according to the natural order for the key's class, or by the
comparator provided at creation time. TreeMap is based on the Red-Black tree data structure
A hash table is a contiguous region of memory, similar to an array, in which objects are hashed (a numerical
value is computed for the object) into an index in that memory
Inserting an object into a hash table is a constant time operation
 Retrieving an object from a hash table is a constant time operation

What is Reflection?
Reflection is a feature in the Java programming language. It allows an executing Java program to examine or
"introspect" upon itself, and manipulate internal properties of the program. For example, it's possible for a Java
class to obtain the names of all its members and display them.

can you able to serialize static variables in java?


Yes

How will you handle client side validation in java?


By using javascript

What is static?
Static is key word , jvm will executes static blocks whit out creating object. We can access static variables and
methods by using class name.

How to create thread explain it? And which one is good?


Our class should extends thread class or implements runnable interface
and in the class call start() method. But better to use always implement your class with runnable interface
.What are the methods in Thread class.
Void run()
void start()
thread()
yield()
sleep()
wait()
interrupted()
stop()

Can an interface extends another interface.


yes

Can we overload the main() method in a class?


Yes

Whether null is keyword.?


No

Can we access public variable which is in particular method to entire class?


No

How can make a class non-instantiable?


Declare class as abstract

What is the purpose of the Externalizable interface in java?


Externalizable interface for custom Serialization
the Application cannot have a finer control over the Serialization process. Because, by default all the instance
variables, except static and transient variables will undergo Serialization process.
to take full control over the Serialization process by depending on the Externalizable interface. This interface
has two methods called writeExternal() and readExternal() that needs to be overridden for making up the
Serialization process.

What types of access modifiers are eligible for variables declared inside a method?
Public,private,protected,final

You might also like