Monday, 29 July 2013

About Java interview questions

Explain the user defined Exceptions?
User defined Exceptions are custom Exception classes defined by the user for specific purpose. A user defined exception can be created by simply sub-classing an Exception class or a subclass of an Exception class. This allows custom exceptions to be generated (using throw clause) and caught in the same way as normal exceptions.
Example:
class CustomException extends Exception {
}
What classes of exceptions may be caught by a catch clause?
A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types. Errors are generally irrecoverable conditions Core java
What is the difference between exception and error?
Error’s are irrecoverable exceptions. Usually a program terminates when an error is encountered.
What is the difference between throw and throws keywords?
The throw keyword denotes a statement that causes an exception to be initiated. It takes the Exception object to be thrown as an argument. The exception will be caught by an enclosing try-catch block or propagated further up the calling hierarchy. The throws keyword is a modifier of a method that denotes that an exception may be thrown by the method. An exception can be rethrown.
What class of exceptions are generated by the Java run-time system?
The Java runtime system generates Runtime Exceptions and Errors.
What is the base class for Error and Exception?
Throwable
What are Checked and Unchecked Exceptions?



A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Making an exception checked forces client programmers to deal with the exception may be thrown. Checked exceptions must be caught at compile time. Example: IOException.
Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn’t force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. Example: ArrayIndexOutOfBoundsException. Errors are often irrecoverable conditions.
Does the code in finally block get executed if there is an exception and a return statement in a catch block?
Or
What is the purpose of the finally clause of a try-catch-finally statement?
The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught. If an exception occurs and there is a return statement in catch block, the finally block is still executed. The finally block will not be executed when the System.exit(0) statement is executed earlier or on system shut down earlier or the memory is used up earlier before the thread goes to finally block.
try{
//some statements
}
catch{
//statements when exception is caught
}
finally{
//statements executed whether exception occurs or not
}

Sunday, 28 July 2013

java interview questions

What is Collection API ? 

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. 

Is Iterator a Class or Interface? What is its use? 

Answer: Iterator is an interface which is used to step through the elements of a Collection. 

What is similarities/difference between an Abstract class and Interface? 

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 or Interface can be instantiated. 

Java Interview Questions - How to define an Abstract class? 

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(); } 

How to define an Interface in Java ? 

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; } If a class is located in a package, what do you need to change in the OS environment to be able to use it? You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let's say a class Employee belongs to a package com.xyz.hr; and is located in the file c:\dev\com\xyz\hr\Employee.java. In this case, you'd need to add c:\dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows: c:\>java com.xyz.hr.Employee 

How many methods in the Serializable interface? 

There is no method in the Serializable interface. The Serializable interface acts as a marker, telling the object serialization tools that your class is serializable. 

How many methods in the Externalizable interface? 

There are two methods in the Externalizable interface. You have to implement these two methods in order to make your class externalizable. These two methods are readExternal() and writeExternal(). What is the difference between Serializalble and Externalizable interface? When you use Serializable interface, your class is serialized automatically by default. But you can override writeObject() and readObject() two methods to control more complex object serailization process. When you use Externalizable interface, you have a complete control over your class's serialization process. 

What is a transient variable in Java

A transient variable is a variable that may not be serialized. If you don't want some field to be serialized, you can mark that field transient or static. Which containers use a border layout as their default layout? The Window, Frame and Dialog classes use a border layout as their default layout. How are Observer and Observable used? Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated, it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects. 

Java teacher

What restrictions are placed on method overloading?Two methods may not have the same name and argument list but different return types.
What is the difference between String and StringBuffer?
String objects are immutable whereas StringBuffer objects are not. StringBuffer unlike Strings support growable and modifiable strings.
Can a private method of a superclass be declared within a subclass?
Sure. A private field or method or inner class belongs to its declared class and hides from its subclasses.
There is no way for private stuff to have a runtime overloading or overriding (polymorphism) features.
What is the default value of an object reference declared as an instance variable?
null unless we define it explicitly.
What is the difference between a constructor and a method?
A constructor is a member function of a class that is used to create objects of that class, invoked using the new operator. It has the same name as the class and has no return type. They are only called once, whereas member functions can be called many times. A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator. Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.
super.method(); is used to call a super class method from a sub class. To call a constructor of the super class, we use the super(); statement as the first line of the subclass’s constructor.
Can a top-level class be private or protected?
No. A top-level class cannot be private or protected. It can have either “public” or no modifier. If it does not have a modifier it is supposed to have a default access. If a top level class is declared as private/protected the compiler will complain that the “modifier private is not allowed here”.
Why Java does not support multiple inheritance? Core Java
Java does support multiple inheritance via interface implementation.
Where and how can you use a private constructor?
Private constructor can be used if you do not want any other class to instantiate the class. This concept is generally used in Singleton Design Pattern. The instantiation of such classes is done from a static public method.
How are this() and super() used with constructors?
this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.
What is Method Overriding? What restrictions are placed on method overriding?
When a class defines a method using the same name, return type, and argument list as that of a method in its superclass, the method in the subclass is said to override the method present in the Superclass. When the method is invoked for an object of the
class, it is the new definition of the method that is called, and not the method definition from superclass.
Restrictions placed on method overriding
• Overridden methods must have the same name, argument list, and return type.
• The overriding method may not limit the access of the method it overrides. Methods may be overridden to be more public, not more private.
• The overriding method may not throw any exceptions that may not be thrown by the overridden method.
What are the Object and Class classes used for? Which class should you use to obtain design information about an object?
Differentiate between a Class and an Object?
The Object class is the highest-level class in the Java class hierarchy. The Class class is used to represent the classes and interfaces that are loaded by a Javaprogram. The Class class is used to obtain information about an object’s design. A Class is only a definition or prototype of real life object. Whereas an object is an instance or living representation of real life object. Every object belongs to a class and every class contains one or more related objects



Java tutorial

Java interview questions
How could Java classes direct program messages to the system console, but error messages, say to a file?
The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:
Stream st =
new Stream (new
FileOutputStream (“techinterviews_com.txt”));
System.setErr(st);
System.setOut(st);
Java
2. What’s 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.
3. Why would you use a synchronized block vs. synchronized method?
Synchronized blocks place locks for shorter periods than synchronized methods.
4. Explain the usage of the keyword transient?
This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).
5. How can you force garbage collection?
You can’t force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.
6. How do you know if an explicit object casting is needed?
If you assign a superclass object to a variable of a subclass’s data type, you need to do explicit casting. For example:
Object a;Customer b; b = (Customer) a;
When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.
7. What’s the difference between the methods sleep() and wait()
The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.
8. Can you write a Java class that could be used both as an applet as well as an application?
Yes. Add a main() method to the applet.
9. What’s the difference between constructors and other methods?
Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.
10. Can you call one constructor from another if a class has multiple constructors
Yes. Use this() syntax.
11. Explain the usage of Java packages.

Java Tutorial
This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes.
12. If a class is located in a package, what do you need to change in the OS environment to be able to use it?
You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let’s say a class Employee belongs to a package com.xyz.hr; and is located in the file c:/dev/com.xyz.hr.Employee.java. In this case, you’d need to add c:/dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows:
c:>java com.xyz.hr.Employee
13. What’s the difference between J2SDK 1.5 and J2SDK 5.0?
There’s no difference, Sun Microsystems just re-branded this version.
14. What would you use to compare two String variables – the operator == or the method equals()?
I’d use the method equals() to compare the values of the Strings and the = = to check if two variables point at the same instance of a String object.
15. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?
A. Yes, it does. The FileNoFoundException is inherited from the IOException. Exception’s subclasses have to be caught first.
16. Can an inner class declared inside of a method access local variables of this method?
It’s possible if these variables are final.



Java Core 

Tuesday, 9 July 2013

Online Tutorial For Java

Java is a complex object-oriented computer programming language which is a result of some concepts taken from other computer languages such as C and C++. Although there are abound negative feedbacks, Java is generally considered to be the most admired multi-facets computing language that is utilized in today's generation.
There are quite a number of reasons why Java is on the top spot when it comes to computer language. First off is the fact that composite dynamic website processes are achievable in Java programming. With Java being a multithreaded language, its use in superb and fast applications is increasing. An evidence of this is its presence in most gadget applications up to the fastest computers found today. As Java applets are platform-independent, the program can straightforwardly be accessed by a software developer and it can be run in various platforms. One of Java's best features is the truth that even it is a very powerful and vigorous, this programming languages comes out free. It is an open source programming language which has a mechanical garbage collection. With regards to the database, Java can adapt to any database may it be paid or free. And the last but not the least is the reality that Java language is a collection of well planned and APIs which aids Java coders to do improved outputs without any annoyance.
The IT world has a number of platforms nowadays. This gift of numerous choices provides advantage and disadvantages. On one hand it provide more options to the developers or consumers; on the other hand making a software that is working on all platforms is becoming very scarce. To address this concern, there is now Java Platform which is intended for running extremely interactive, lively, and safe applets and computer applications on a set of connections of different computers.
Software developers can make applications on a single platform to deliver to that same platform -- the Java Platform, which is accessible on a wide array of operating systems. This greatly minimizes the developing cost of the software. For support workforce, version management and advancement are much easier for the reason that Java-enabled software application can be found in a central storage area and work from that location for each individual handling.
The bottom line is, if you wish to study Java and become a professional on this field, you will certainly be ahead of the game. To start off, since Java is a popular language, you can turn on to basic Java tutorials found online or find a Java book with positive reviews. Deciding to be in this field is an action you shall never regret.


From the past decade, it has been observed that so many technologies are changing the way of lifestyle. One of them is the internet technology, with this technology; so many people are getting opportunities in different continents. To obtain these opportunities, every one of us needs some fine quality of qualifications, and we need to improve professional skills. However, everyone's life has become busy scheduled and so many people are having no time to add some more qualifications to their skills.
The online tutorials are one of the best ways to learn our desired courses. Every one of us believes that the computers are an ocean subject to learn. With these tutorials, everyone can become professional towards computers. And learning through online tutorials will give you more fun and enjoyment. In these recession days, adding some qualifications to you skills will boost up your opportunities. Most of these online tutorials are available at free of cost, some of them are charging a few dollars to provide some additional features. In these technology days, the computer courses like Photoshop, HTML, PHP, Java Script and adobe Photoshop are providing numerous job opportunities. Here we will discuss some of these online courses.
If you are interested to learn Photoshop, the online Photoshop tutorial is the best place to learn. Obviously, this online Photoshop software is used to creating and manipulating graphics and photographs. The tools and advancements provided in this software are very much helpful to learn this software easily. There are so many well experienced tutorials are available in internet. With this online learning Photoshop tutorial, definitely you will get a very good opportunity. The web development in these days would be the best business, designing and hosting web sites and e-commerce websites and many more. To become a professional web designer, you should have to learn the HTML basics. With these online html tutorials, definitely you will become professional to design your own web sites. And also it is mandatory to learn PHP programming to become an experienced web developer. However, learning these PHP tutorials could be the expensive one. To resolve this issue, online learning PHP tutorial is the best one for you.
If you are very much an interest to become a developer for e-commerce web sites, it is a best idea to learn java tutorials. The online java script tutorials add some additional functionality to your web designing skills. Finally, learning this software would definitely increase your chances to get more income. And now a question rose in your mind that was to find these online tutorials. There are some well established and experienced web sites are offering these online tutorials to their valuable customers. For more information, please visit their web site.