Social Icons

Friday, January 11, 2013

JAVA JDBC Questions with Answers For Freshers Paper -2



1.What are the steps involved in establishing a JDBC connection?
Ans:  This action involves two steps: loading the JDBC driver and making the connection.

2. How can you load the drivers?
Ans:  Loading the driver or drivers you want to use is very simple and involves just one line of code. If, for example, you want to use the JDBC-ODBC Bridge driver, the following code will load it:
Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”);
Your driver documentation will give you the class name to use. For instance, if the class name is jdbc.DriverXYZ, you would load the driver with the following line of code:
Class.forName(”jdbc.DriverXYZ”);

3.What will Class.forName do while loading drivers?
Ans:   It is used to create an instance of a driver and register it with the
DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS.

4.How can you make the connection?
Ans:   To establish a connection you need to have the appropriate driver connect to the DBMS.
The following line of code illustrates the general idea:
String url = “jdbc:odbc:Fred”;
Connection con = DriverManager.getConnection(url, “Fernanda”, “J8?);

5.How can you create JDBC statements and what are they?
Ans:  A Statement object is what sends your SQL statement to the DBMS. You simply create a Statement object and then execute it, supplying the appropriate execute method with the SQL statement you want to send. For a SELECT statement, the method to use is executeQuery. For statements that create or modify tables, the method to use is executeUpdate. It takes an instance of an active connection to create a Statement object. In the following example, we use our Connection object con to create the Statement object
Statement stmt = con.createStatement();

6.How can you retrieve data from the ResultSet?
Ans:  JDBC returns results in a ResultSet object, so we need to declare an instance of the class ResultSet to hold our results. The following code demonstrates declaring the ResultSet object rs.
ResultSet rs = stmt.executeQuery(”SELECT COF_NAME, PRICE FROM COFFEES”);
String s = rs.getString(”COF_NAME”);
The method getString is invoked on the ResultSet object rs, so getString() will retrieve (get) the value stored in the column COF_NAME in the current row of rs.

7.What are the different types of Statements?
Ans:  Regular statement (use createStatement method), prepared statement (use prepareStatement method) and callable statement (use prepareCall)

8.How can you use PreparedStatement? 
Ans:  This special type of statement is derived from class Statement.If you need a
Statement object to execute many times, it will normally make sense to use a PreparedStatement object instead. The advantage to this is that in most cases, this SQL statement will be sent to the DBMS right away, where it will be compiled. As a result, the PreparedStatement object contains not just an SQL statement, but an SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement’s SQL statement without having to compile it first.

9.PreparedStatement updateSales =con.prepareStatement("UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ?");

11.What does setAutoCommit do?
Ans:  When a connection is created, it is in auto-commit mode. This means that each individual SQL statement is treated as a transaction and will be automatically committed right after it is executed. The way to allow two or more statements to be grouped into a transaction is to disable auto-commit mode:
con.setAutoCommit(false);
Once auto-commit mode is disabled, no SQL statements will be committed until you call the method commit explicitly.
con.setAutoCommit(false);
PreparedStatement updateSales =
            con.prepareStatement( "UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ?");
updateSales.setInt(1, 50); updateSales.setString(2, "Colombian");
updateSales.executeUpdate();
PreparedStatement updateTotal =
            con.prepareStatement("UPDATE COFFEES SET TOTAL = TOTAL + ? WHERE COF_NAME LIKE ?");
updateTotal.setInt(1, 50);
updateTotal.setString(2, "Colombian");
updateTotal.executeUpdate();
con.commit();
con.setAutoCommit(true);

12.How do you call a stored procedure from JDBC?
Ans:  The first step is to create a CallableStatement object. As with Statement an and PreparedStatement objects, this is done with an open
Connection object. A CallableStatement object contains a call to a stored procedure.

13.CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");

14.ResultSet rs = cs.executeQuery();

15.How do I retrieve warnings?
Ans:  SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an
application, as exceptions do; they simply alert the user that something did not happen as planned. A warning can be reported on a
Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object. Each of these
classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object:

16. SQLWarning warning = stmt.getWarnings();
if (warning != null)
{
System.out.println("n---Warning---n");
                   while (warning != null)
                 {
                         System.out.println("Message: " + warning.getMessage());
                          System.out.println("SQLState: " + warning.getSQLState());
                          System.out.print("Vendor error code: ");
                         System.out.println(warning.getErrorCode());
                         System.out.println("");
                           warning = warning.getNextWarning();
             }
    }

17 How can you move the cursor in scrollable result sets?
Ans:  One of the new features in the JDBC 2.0 API is the ability to move a result set’s cursor backward as well as forward. There are also methods that let you move the cursor to a particular row and check the position of the cursor.
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet srs = stmt.executeQuery(”SELECT COF_NAME, PRICE FROM COFFEES”);

The first argument is one of three constants added to the ResultSet API to indicate the type of a ResultSet object: TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE , and TYPE_SCROLL_SENSITIVE. 

The second argument is one of two ResultSet constants for specifying whether a result set is read-only or updatable: CONCUR_READ_ONLY and CONCUR_UPDATABLE.

 The point to remember here is that if you specify a type, you must also specify whether it is read-only or updatable. Also, you must specify the type first, and because both parameters are of type int , the compiler will not complain if you switch the order. 

Specifying the constant TYPE_FORWARD_ONLY creates a nonscrollable result set, that is, one in which the cursor moves only forward. If you do not specify any constants for the type and updatability of a ResultSet object, you will automatically get one that is TYPE_FORWARD_ONLY and CONCUR_READ_ONLY.

18. What’s the difference between TYPE_SCROLL_INSENSITIVE , and TYPE_SCROLL_SENSITIVE?
Ans:  You will get a scrollable ResultSet object if you specify one of these ResultSet constants.The difference between the two has to do with whether a result set reflects changes that are made to it while it is open and whether certain methods can be called to detect these changes. Generally speaking, a result set that is TYPE_SCROLL_INSENSITIVE does not reflect changes made while it is still open and one that is TYPE_SCROLL_SENSITIVE does. 

All three types of result sets will make changes visible if they are closed and then reopened:
32.       Statement stmt =
33.                   con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
34.       ResultSet srs =
35.                   stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES");
36.       srs.afterLast();
37.       while (srs.previous())
38.       {
39.                   String name = srs.getString("COF_NAME");
40.                   float price = srs.getFloat("PRICE");
41.                   System.out.println(name + " " + price);
42.       }

43.       How to Make Updates to Updatable Result Sets?
Ans:  Another new feature in the JDBC 2.0 API is the ability to update rows in a result set using methods in the Java programming language rather than having to send an SQL command. But before you can take advantage of this capability, you need to create a ResultSet object that is updatable. In order to do this, you supply the ResultSet constant CONCUR_UPDATABLE to the createStatement method.

44.       Connection con =
45.                   DriverManager.getConnection("jdbc:mySubprotocol:mySubName");
46.       Statement stmt =
47.                   con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
48.       ResultSet uprs =
            stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES");


Java Interview Questions With Answers For Freshers Paper-3



1. What is transient variable?
 Ans: Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can't be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null.
   
2.  Name the container which uses Border Layout as their default layout?
 Ans:  Containers which uses Border Layout as their default are: window, Frame and Dialog classes.
    
3. What do you understand by Synchronization?
 Ans:  Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption.
E.g. Synchronizing a function:
public synchronized void Method1 () {
     // Appropriate method-related code.
}
E.g. Synchronizing a block of code inside a function:
public myFunction (){
    synchronized (this) {
            // Synchronized code here.
         }
}
  
4. What is Collection API?
 Ans: The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces.
Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.
Example of interfaces: Collection, Set, List and Map.
   
5.What is similarities/difference between an Abstract class and Interface?
 Ans: Differences are as follows:
•           Interfaces provide a form of multiple inheritance. A class can extend only one other class.
•           Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc.
•           A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class.
•           Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast.
Similarities:
•           Neither Abstract classes nor Interface can be instantiated.
 
6.  How to define an Abstract class?
 Ans: A class containing abstract method is called Abstract class. An Abstract class can't be instantiated.
Example of Abstract class:
abstract class testAbstractClass {
    protected String myString;
    public String getMyString() {
        return myString;
        }
    public abstract string anyAbstractFunction();
}
     
7. How to define an Interface?
 Ans: In Java Interface defines the methods but does not implement them. Interface can include constants. A class that implements the interfaces is bound to implement all the methods defined in Interface.
Emaple of Interface:

public interface sampleInterface {
    public void functionOne();

    public long CONSTANT_ONE = 1000;
}
   
8. Explain the user defined Exceptions?
 Ans: User defined Exceptions are the separate Exception classes defined by the user for specific purposed. An user defined can created by simply sub-classing it to the Exception class. This allows custom exceptions to be generated (using throw) and caught in the same way as normal exceptions.
Example:
class myCustomException extends Exception {
     // The class simply has to exist to be an exception
}
  
9. Explain the new Features of JDBC 2.0 Core API?
 Ans: The JDBC 2.0 API includes the complete JDBC API, which includes both core and Optional Package API, and provides inductrial-strength database computing capabilities.
New Features in JDBC 2.0 Core API:
•           Scrollable result sets- using new methods in the ResultSet interface allows programmatically move the to particular row or to a position relative to its current position
•           JDBC 2.0 Core API provides the Batch Updates functionality to the java applications.
•           Java applications can now use the ResultSet.updateXXX methods.
•           New data types - interfaces mapping the SQL3 data types
•           Custom  mapping of user-defined types (UTDs)
•           Miscellaneous features, including performance hints, the use of character streams, full precision for java.math.BigDecimal values, additional security, and support for time zones in date, time, and timestamp values.
    
10. Explain garbage collection?
 Ans:  Garbage collection is one of the most important features of Java. Garbage collection is also called automatic memory management as JVM automatically removes the unused variables/objects (value is null) from the memory. User program can’t directly free the object from memory; instead it is the job of the garbage collector to automatically free the objects that are no longer referenced by a program. Every class inherits finalize() method from java.lang.Object, the finalize() method is called by garbage collector when it determines no more references to the object exists. In Java, it is good idea to explicitly assign null into a variable when no more in use. I Java on calling System.gc() and Runtime.gc(), JVM tries to recycle the unused objects, but there is no guarantee when all the objects will garbage collected.
   
11. How you can force the garbage collection?
 Ans:  Garbage collection automatic process and can't be forced. 
 
12. What is OOPS?
Answer: OOP is the common abbreviation for Object-Oriented Programming. 
 
13. Describe the principles of OOPS.
 Ans: There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation. 
 
14.  Explain the Encapsulation principle.
 Ans:  Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper. 
 
15. Explain the Inheritance principle.
 Ans: Inheritance is the process by which one object acquires the properties of another object. 
 
16. Explain the Polymorphism principle.
Answer: The meaning of Polymorphism is something like one name many forms. Polymorphism enables one entity to be used as as general category for different types of actions. The specific action is determined by the exact nature of the situation. The concept of polymorphism can be explained as "one interface, multiple methods". 
 
17.  Explain the different forms of Polymorphism.
 Ans: From a practical programming viewpoint, polymorphism exists in three distinct forms in Java:
•           Method overloading
•           Method overriding through inheritance
•           Method overriding through the Java interface

18. What are Access Specifiers available in Java?
 Ans: Access Specifiers are keywords that determine the type of access to the member of a class. These are:
•           Public
•           Protected
•           Private
•           Defaults
 
19.  Describe the wrapper classes in Java.
 Ans: Wrapper class is wrapper around a primitive data type. An instance of a wrapper class contains, or wraps, a primitive value of the corresponding type.
Following table lists the primitive types and the corresponding wrapper classes:

Primitive  Wrapper
boolean    java.lang.Boolean
byte         java.lang.Byte
char         java.lang.Character
double     java.lang.Double
float         java.lang.Float
int            java.lang.Integer
long         java.lang.Long
short        java.lang.Short
void         java.lang.Void
 
20.  Read the following program:
public class test {
public static void main(String [] args) {
    int x = 3;
    int y = 1;
   if (x = y)
     System.out.println("Not equal");
  else
    System.out.println("Equal");
 }
}

21. What is the result?
   A. The output is “Equal”
   B. The output in “Not Equal”
   C. An error at " if (x = y)" causes compilation to fall.
   D. The program executes but no output is show on console.
 Ans: C

22. what is the class variables?
 Ans: When we create a number of objects of the same class, then each object will share a common copy of variables. That means that there is only one copy per class, no matter how many objects are created from it. Class variables or static variables are declared with the static keyword in a class, but mind it that it should be declared outside outside a class. These variables are stored in static memory. Class variables are mostly used for constants, variable that never change its initial value. Static variables are always called by the class name. This variable is created when the program starts i.e. it is created before the instance is created of class by using new operator and gets destroyed when the programs stops. The scope of the class variable is same a instance variable. The class variable can be defined anywhere at class level with the keyword static. It initial value is same as instance variable. When the class variable is defined as int then it's initial value is by default zero, when declared boolean its default value is false and null for object references. Class variables are associated with the class, rather than with any object. 

23.  What is the difference between the instanceof and getclass, these two are same or not ?
 Ans:  instanceof is a operator, not a function while getClass is a method of java.lang.Object class. Consider a condition where we use
if(o.getClass().getName().equals("java.lang.Math")){ }
This method only checks if the classname we have passed is equal to java.lang.Math. The class java.lang.Math is loaded by the bootstrap ClassLoader. This class is an abstract class. This class loader is responsible for loading classes. Every Class object contains a reference to the ClassLoader that defines. getClass () method returns the runtime class of an object. It fetches the java instance of the given fully qualified type name. The code we have written is not necessary, because we should not compare getClass.getName (). The reason behind it is that if the two different class loaders load the same class but for the JVM, it will consider both classes as different classes so, we can't compare their names. It can only gives the implementing class but can't compare a interface, but instanceof operator can.
The instanceof operator compares an object to a specified type. We can use it to test if an object is an instance of a class, an instance of a subclass, or an instance of a class that implements a particular interface. We should try to use instanceof operator in place of getClass() method. Remember instanceof operator and getClass are not same. Try this example; it will help you to better understand the difference between the two.
Interface one{
}

Class Two implements one {
}
Class Three implements one {
}

public class Test {
public static void main(String args[]) {
one test1 = new Two();
one test2 = new Three();
System.out.println(test1 instanceof one); //true
System.out.println(test2 instanceof one); //true
System.out.println(Test.getClass().equals(test2.getClass())); //false
}
}

24. Is Iterator a Class or Interface? What is its use?
 Ans:  Iterator is an interface which is used to step through the elements of a Collection.
Question : When you declare a method as abstract method ?
Answer : When i want child class to implement the behavior of the method.        
Question : Can I call a abstract method from a non abstract method ?
Answer : Yes, We can call a abstract method from a Non abstract method in a Java abstract class        
Question : What is the difference between an Abstract class and Interface in Java ? or can you explain when you use Abstract classes ?
Answer : Abstract classes let you define some behaviors; they force your subclasses to provide others. These abstract classes will provide the basic funcationality of your applicatoin, child class which inherited this class will provide the funtionality of the abstract methods in abstract class. When base class calls this method, Java calls the method defined by the child class.
•           An Interface can only declare constants and instance methods, but cannot implement default behavior.
•           Interfaces provide a form of multiple inheritance. A class can extend only one other class.
•           Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc.
•           A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class.
•           Interfaces are slow as it requires extra indirection to find corresponding method in the actual class. Abstract classes are fast

Java Interview Questions With Answers For Freshers Paper-2



1.What is garbage collection? What is the process that is responsible for doing that in java? 
Ans:  Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process

2.What kind of thread is the Garbage collector thread? 
Ans:  It is a daemon thread.

3.What is a daemon thread? 
Ans:  These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly.

4.How will you invoke any external process in Java? 
Ans: Runtime.getRuntime().exec(….)

5.What is the finalize method do? 
Ans: Before the invalid objects get garbage collected, the JVM give the user a chance to clean up some resources before it got garbage collected.

6.What is mutable object and immutable object?
Ans:  If a object value is changeable then we can call it as Mutable object. (Ex., StringBuffer, …) If you are not allowed to change the value of an object, it is immutable object. (Ex., String, Integer, Float, …)

7.What is the basic difference between string and stringbuffer object? 
Ans: String is an immutable object. StringBuffer is a mutable object.

8. What is the purpose of Void class?
Ans: The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void.

9.What is reflection?
Ans:  Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions.

10.What is the base class for Error and Exception? 
Ans:  Throwable

11.What is the byte range?
Ans: 128 to 127

12.What is the implementation of destroy method in java.. is it native or java code? 
Ans: This method is not implemented.

13.What is a package? 
Ans: To group set of classes into a single unit is known as packaging. Packages provides wide namespace ability.

14.What are the approaches that you will follow for making a program very efficient?
Ans: By avoiding too much of static methods avoiding the excessive and unnecessary use of synchronized methods Selection of related classes based on the application (meaning synchronized classes for multiuser and non-synchronized classes for single user) Usage of appropriate design patterns Using cache methodologies for remote invocations Avoiding creation of variables within a loop and lot more.

15.What is a DatabaseMetaData? 
Ans: Comprehensive information about the database as a whole.

16.What is Locale? 
Ans: A Locale object represents a specific geographical, political, or cultural region

17.How will you load a specific locale?
Ans: Using ResourceBundle.getBundle(…);

18.What is JIT and its use?
Ans: Really, just a very fast compiler… In this incarnation, pretty much a one-pass compiler — no offline computations. So you can’t look at the whole method, rank the expressions according to which ones are re-used the most, and then generate code. In theory terms, it’s an on-line problem.

19.Is JVM a compiler or an interpreter? 
Ans: Interpreter
20. When you think about optimization, what is the best way to findout the time/memory consuming process? – Using profiler

21.What is the purpose of assert keyword used in JDK1.4.x? 
Ans: In order to validate certain expressions. It effectively replaces the if block and automatically throws the AssertionError on failure. This keyword should be used for the critical arguments. Meaning, without that the method does nothing.

22.How will you get the platform dependent values like line separator, path separator, etc., ? 
Ans: Using Sytem.getProperty(…) (line.separator, path.separator, …)

23.What is skeleton and stub? what is the purpose of those? 
Ans: Stub is a client side representation of the server, which takes care of communicating with the remote server. Skeleton is the server side representation. But that is no more in use… it is deprecated long before in JDK.

24.What is the final keyword denotes? 
Ans: final keyword denotes that it is the final implementation for that method or variable or class. You can’t override that method/variable/class any more.

25.What is the significance of ListIterator? 
Ans: You can iterate back and forth.

26.What is the major difference between LinkedList and ArrayList? 
Ans: LinkedList are meant for sequential accessing. ArrayList are meant for random accessing.

27.What is nested class? 
Ans: If all the methods of a inner class is static then it is a nested class.

28.What is inner class? 
Ans: If the methods of the inner class can only be accessed via the instance of the inner class, then it is called inner class.

29.What is composition? 
Ans: Holding the reference of the other class within some other class is known as composition.

30. What is aggregation? 
Ans: It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite method through its reference, then it is called aggregation.

31. What are the methods in Object? 
Ans: clone, equals, wait, finalize, getClass, hashCode, notify, notifyAll, toString

32.Can you instantiate the Math class? 
Ans: You can’t instantiate the math class. All the methods in this class are static. And the constructor is not public.

33.What is singleton? 
Ans: It is one of the design pattern. This falls in the creational pattern of the design pattern. 
There will be only one instance for that entire JVM. You can achieve this by having the private constructor in the class. For eg., public class Singleton { private static final Singleton s = new Singleton(); private Singleton() { } public static Singleton getInstance() { return s; } // all non static methods … }

34.What is DriverManager?
Ans: The basic service to manage set of JDBC drivers.

35. What is Class.forName() does and how it is useful? 
Ans: It loads the class into the ClassLoader. It returns the Class. Using that you can get the instance ( “class-instance”.newInstance() ).

Java Interview Questions With Answers For Freshers Paper-1



1)What is OOPs?
Ans: Object oriented programming organizes a program around its data,i.e.,objects and a set of well defined interfaces to that data.An object-oriented program can be characterized as data controlling access to code.

2)what is the difference between Procedural and OOPs?
Ans: a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOPs program, unit of program is object, which is nothing but combination of data and code.
b) In procedural program,data is exposed to the whole program whereas in OOPs program,it is accessible with in the object and which in turn assures the security of the code.

3)What are Encapsulation, Inheritance and Polymorphism?
Ans: 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 classactions.

4)What is the difference between Assignment and Initialization?
Ans: Assignment can be done as many times as desired whereas initialization can be done only once.

5)What are Class, Constructor and Primitive data types?
Ans: Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created.
Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char

6)What is an Object and how do you allocate memory to it?
Ans: Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.

7)What is the difference between constructor and method?
Ans: Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.

8)What are methods and how are they defined?
Ans: Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes.Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method. A method’s signature is a combination of the first three parts mentioned above.

9)What is the use of bin and lib in JDK?
Ans: Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.

10)What is casting?
Ans: Casting is used to convert the value of one type to another.

11)How many ways can an argument be passed to a subroutine and explain them?
Ans: An argument can be passed in two ways. They are passing by value and passing by reference.Passing by value: This method copies the value of an argument into the formal parameter of the subroutine.Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.

12)What is the difference between an argument and a parameter?
Ans: While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.

13)What are different types of access modifiers?
Ans: public: Any thing declared as public can be accessed from anywhere.
private: Any thing declared as private can’t be seen outside of its class.
protected: Any thing declared as protected can be accessed by classes in the samepackage and subclasses in the other packages.
default modifier : Can be accessed only to classes in the same package.

14)What is final, finalize() and finally?
Ans: 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 overriddenA 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 collecollection 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.

15)What is UNICODE?
Ans: Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other.

16)What is Garbage Collection and how to call it explicitly?
Ans: 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.

17)What is finalize() method ?
Ans: finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.

18)What are Transient and Volatile Modifiers?
Ans: 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.

19)What is method overloading and method overriding?
Ans: Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading.
Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.

20)What is difference between overloading and overriding?
Ans: 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.

21) What is meant by Inheritance and what are its advantages?
Ans: 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.

22)What is the difference between this() and super()?
Ans: this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.

23)What is the difference between superclass and subclass?
Ans: A super class is a class that is inherited whereas sub class is a classthat does the inheriting.

24) What modifiers may be used with top-level class?
Ans: public, abstract and final can be used for top-level class.

25)What are inner class and anonymous class?
Ans: 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.