Java Classes

  Home  Java Programing  Java Classes


“Java Classes frequently Asked Questions in various Java Classes related job Interviews by interviewer. Get preparation of Java Classes job interview questions”



76 Java Classes Questions And Answers

22⟩ In interfaces the methods just defined without implementation then what is the purpose of defining the methods?

As By giving the Methods(Declaring) in Interface , We are telling to must follow exactly the same Signature for the given Methods. This wil be used when we are writing RMI Applications . Because in this case we just give the Interface to the User, so that user will come to know the Signature of the Method and later he/she will call it.

 213 views

24⟩ Explain can a abstract class have a constructor? When would the constructor in the abstract class be called?

constructor can not be created in an abstract class.even though we write the constructor, when the constructor will be called..?only if the object is created. but we cannot create an object of abstract class.even though we create object using indirect way, there also, we cannot call the constructor of the abstract class.finally, constructor for the abstract class cannot be called.

 198 views

25⟩ Can you explain try-catch-finally?What is the exact use?

try - catch and finally are used for avoiding situations when a program may get terminated due to the occurance of unwanted error during the exection of the program.

The following points are important....

1)There is only one try for a block......any number of catch statements for a block and only one finally for a block of statments

2)finally is optional.

3) catch is also optional but ,if the catch statement is missing then finally must appear.

4) All catches corresponding to the child exceptions must be appearing before a catch for a parent exception..

5) Irrespective of the occurance of the exception ,the statements present in the finally block are executed always with one exclusion.

i.e. IF a System.out.exit() statement is encountered then the program terminates imediately,,,hence finally can not be executed in such cases.

Note: even there is an return statement appears in try block ...then also the code in finally is executed.

e.g. Guess what happens.....if ur try has return 1; and finally has return 2; ...? 2 is returned

 168 views

27⟩ What are static methods?

Static methods dont need class objects to call them where as nonstatic methods needs class objects to call them

 169 views

29⟩ Tell me how to implement hibernate?

following things needed

1. put hibernate3.jar in project lib

2. write hibernate configuration file (ie) hibernate.cfg

3. write hibernate mapping file (say) student.hbm.xml

4. get hibernate session and begin transaction

5 end

 166 views

31⟩ How to run doc file in Java?

There are two kinds of Javadoc comments: class-level comments, and member-level comments. Class-level comments provide the description of the classes, and member-level comments describe the purposes of the members. Both types of comments start with /** and end with */.

@author: Describes the author of the document. Used in class-level comments

@param: Describes a parameter of a method or constructor.

@return: Describes the return type of a method.

@throws: Describes an exception a method may throw.

@exception: Describes an exception.

 193 views

32⟩ What is the use of system class?

Well it depends upon you for what purpose do use system class.

Say, System.in >> belongs to inputstream interface helps in inputting from the console.

whereas, System.out and System.err is used to print something on the console. when out is used with System class then you generally call print() and println() methods to print the stuff you want to. whereas when you use err with System class then you generally try to print error message.

 190 views

36⟩ What is Pre-emptive scheduling?

Preemptive scheduling entails some extra scheduling overhead compared to non-preemptive.

Preemptive scheduling gives all processes a chance to run every so often, which improves.

As described in class, strict alternation causes one thread to block indefinitely while waiting to enter the critical section if the other thread never takes its turn. This violates one of the requirements for a correct implementation of critical sections.

An effective way to prevent deadlock is for the OS to require every process to request all of the resources (locks, files, etc.) when it begins to execute, and then release them all when it completes. prevention that eliminates one of the necessary.

 182 views

37⟩ What is the output of the following? // A simple example of recursion.class Factorial { // this is a recursive method int fact(int n) { int result; if(n==1) return 1; result = fact(n-1) * n; return result; }} class Recursion { public static void main(String args[]) { Factorial f = new Factorial(); System.out.println("Factorial of 3 is " + f.fact(3)); }}A) Factorial of 3 is 3B) Factorial of 3 is 6C) Factorial of 3 is 9D) None of the above

D) None of the above

Exception in thread "main" java.lang.NoSuchMethodError: main

 183 views

38⟩ How to convert .class file to .exe file?

This is a very common question asked in the comp.lang.java newsgroup. Its often useful to have an executable application when deploying your applications to a specific platform, but remember to make your .class files available for users running Unix/Macintosh/other platforms.

 177 views

39⟩ Explain java classes in detail?

The Java class file is a precisely defined format for compiled Java. Java source code is compiled into class files that can be loaded and executed by any JVM. The class files may travel across a network before being loaded by the JVM.

The Java class file contains everything a JVM needs to know about one Java class or interface. In their order of appearance in the class file, the major components are: magic, version, constant pool, access flags, this class, super class, interfaces, fields, methods, and attributes.

 164 views