Está en la página 1de 7

http://www.whizlabs.com/scjp/tips.html 1. 2.

An identifier in java must begin with a letter , a dollar sign($), or an underscore (-); subsequent characters may be letters, dollar signs, underscores, or digits. There are three top-level elements that may appear in a file. None of these elements is required. If they are present, then they must appear in the following order: -package declaration -import statements -class definitions A static method can't be overridden to non-static and vice versa. The variables in java can have the same name as method or class. All the static variables are initialized when the class is loaded. An interface can extend more than one interface, while a class can extend only one class. The variables in an interface are implicitly final and static.If the interface , itself, is declared as public the methods and variables are implicitly public. A final class cannot have abstract methods. All methods of a final class are automatically final. While casting one class to another subclass to superclass is allowed without any type casting. e.g.. A extends B , B b = new A(); is valid but not the reverse. The String class in java is immutable. Once an instance is created, the string it contains cannot be changed. e.g. String s1 = new String("test"); s1.concat("test1"); Even after calling concat() method on s1, the value of s1 will remain to be "test". What actually happens is a new instance is created. But the StringBuffer class is mutable. The short circuit logical operators && and || provide logical AND and OR operations on boolean types and unlike & and | , these are not applicable to integral types. The valuable additional feature provided by these operators is the right operand is not evaluated if the result of the operation can be determined after evaluating only the left operand. The difference between x = ++y; and x = y++; In the first case y will be incremented first and then assigned to x. In second case first y will be assigned to x then it will be incremented. The initialization values for different data types in java is as follows byte = 0, int = 0, short = 0, char = '\u0000', long = 0L, float = 0.0f, double = 0.0d, boolean = false, object referenece(of any object) = null. An overriding method may not throw a checked exception unless the overridden method also throws that exception or a superclass of that exception. Interface methods can't be native, static, synchronized, final, private, protected or abstract. The String class is a final class, it can't be subclassed. The Math class has a private constructor, it can't be instantiated. The two kinds of exceptions in java are : Compile time (Checked ) and Run time (Unchecked) exceptions. All subclasses of Exception except the RunTimeException and its subclasses are checked exceptions. Examples of Checked exception : IOException, ClassNotFoundException. Examples of Runtime exception :ArrayIndexOutOfBoundsException,NullPointerException, ClassCastException, ArithmeticException, NumberFormatException. The various methods of Java.lang.Object are clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString and wait. Garbage collection in java cannot be forced. The methods used to call garbage collection thread are System.gc() and Runtime.gc() Inner class may be private, protected, final, abstract or static. To refer to a field or method in the outer class instance from within the inner class, use Outer.this.fieldname . Inner classes may not declare static initializers or static members unless they are compile time constants i.e. static final var = value; A nested class cannot have the same name as any of its enclosing classes.

3. 4. 5. 6. 7. 8. 9. 10. 11.

12. 13. 14. 15. 16. 17. 18. 19.

20. 21. 22. 23. 24. 25.

26. An example of creation of instance of an inner class from some other class: class Outer { public class Inner{} } class Another { public void amethod() {

27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46.

Outer.Inner i = new Outer().new Inner(); } } The range of Thread priority in java is 1-10. The minimum priority is 1 and the maximum is 10. The default priority of any thread in java is 5. Using the synchronized keyword in the method declaration, requires a thread obtain the lock for this object before it can execute the method. A synchronized method can be overridden to be not synchronized and vice versa. There are two ways to mark code as synchronized: a.) Synchronize an entire method by putting the synchronized modifier in the method's declaration. b.) Synchronize a subset of a method by surrounding the desired lines of code with curly brackets ({}). The notify() mthod moves one thread, that is waiting on this object's monitor, into the Ready state. This could be any of the waiting threads. The notifyAll() method moves all threads, waiting on this object's monitor into the Ready state. The argument to switch can be either byte, short , char or int. Breaking to a label (using break <labelname>;) means that the loop at the label will be terminated and any outer loop will keep iterating. While a continue to a label (using continue <lablename>;) continues execution with the next iteration of the labeled loop. To ensure that assertions don't become performance liability, you can disable them when your program is started. Also by default, assertions are disabled. An assertion is a statement in the Java language that enables you to test your assumptions about your program. Some of the advantages of writing assertions while programming are: a.) Detect and correct bugs b.) Enhance maintainability as writing assertions helps you document the inner workings of your code In order for the javac compiler to accept code containing assertions, you must use the -source 1.4 command-line option as in the below example: javac -source 1.4 TestClass.java The setClassAssertionStatus returns a boolean instead of throwing an exception if it is invoked when it's too late to set the assertion status (i.e., if the named class has already been initialized) A static method can only call static variables or other static methods, without using the instance of the class. e.g. main() method can't directly access any non static method or variable, but using the instance of the class it can. The if() statement in java takes only boolean as an argument. Please note that if (a=true){}, provided a is of type boolean is a valid statement and the code inside the if block will be executed. The (-0.0 == 0.0) will return true, while (5.0==-5.0) will return false. An abstract class may not have even a single abstract method but if a class has an abstract method it has to be declared as abstract. The valueOf() method converts data from its internal format into a human-readable form. It is a static method that is overloaded within String class for all of Java's built-in types, so that each type can be converted properly into a string. The main difference between Vector and ArrayList is that Vector is synchronized while the ArrayList is not. The statement float f = 5.0; will give compilation error as default type for floating values is double and double can't be directly assigned to float without casting.

47. The equals() method in String class compares the values of two Strings while == compares the memory address of the objects being compared. e.g. String s = new String("test"); String s1 = new String("test"); s.equals(s1) will return true while s==s1 will return false. 48. The example of array declaration along with initialization - int k[] = new int[]{1,2,3,4,9}; 49. The octal number in java is preceded by 0 while the hexadecimal by 0x (x may be in small case or upper case) e.g. octal :022 hexadecimal :0x12 50. A constructor cannot be native, abstract, static, synchronized or final. http://www.geocities.com/artgladart/ 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. What is meant by Java ? What is meant by a class ? What is meant by a method ? What are the OOPS concepts in Java ? What is meant by encapsulation ? Explain with an example What is meant by inheritance ? Explain with an example What is meant by polymorphism ? Explain with an example Is multiple inheritance allowed in Java ? Why ? What is meant by Java interpreter ? What is meant by JVM ? What is a compilation unit ? What is meant by identifiers ? What are the different types of modifiers ? What are the access modifiers in Java ? What are the primitive data types in Java ? What is meant by a wrapper class ?

17. What is meant by static variable and static method ? 18. What is meant by Garbage collection ? 19. What is meant by abstract class 20. What is meant by final class, methods and variables ? 21. What is meant by interface ? 22. What is meant by a resource leak ? 23. What is the difference between interface and abstract class ? 24. What is the difference between public private, protected and static 25. What is meant by method overloading ? 26. What is meant by method overriding ? 27. What is singleton class ? 28. What is the difference between an array and a vector ? 29. What is meant by constructor ? 30. What is meant by casting ? 31. What is the difference between final, finally and finalize ? 32. What is meant by packages ? 33. What are all the packages ? 34. Name 2 calsses you have used ? 35. Name 2 classes that can store arbitrary number of objects ? 36. What is the difference between java.applet.* and java.applet.Applet ? 37. What is a default package ? 38. What is meant by a super class and how can you call a super class ? 39. What is anonymous class ? 40. Name interfaces without a method ? 41. What is the use of an interface ? 42. What is a serializable interface ? 43. How to prevent field from serialization ? 44. What is meant by exception ? 45. How can you avoid the runtime exception ? 46. What is the difference between throw and throws ? 47. What is the use of finally ? 48. Can multiple catch statements be used in exceptions ? 49. Is it possible to write a try within a try statement ? 50.What is the method to find if the object exited or not ? 51.What is meant by a Thread ? 52.What is meant by multi-threading ? 52.What is the 2 way of creating a thread ? Which is the best way and why ? 53.What is the method to find if a thread is active or not ? 54.What are the thread-to-thread communcation ? 55.What is the difference between sleep and suspend ? 56.Can thread become a member of another thread ? 57.What is meant by deadlock ? 58.How can you avoid a deadlock ? 59.What are the three typs of priority ? 59.What is the use of synchronizations ? 60.Garbage collector thread belongs to which priority ? 61.What is meant by time-slicing ? 62.What is the use of this ? 63.How can you find the length and capacity of a string buffer ? 64.How to compare two strings ? 65.What are the interfaces defined by Java.lang ? 66.What is the purpose of run-time class and system class 67.What is meant by Stream and Types ? 68.What is the method used to clear the buffer ? 69.What is meant by Stream Tokenizer ? 70.What is serialization and de-serialisation ? What is meant by Applet ? 71.How to find the host from which the Applet has originated ? 72.What is the life cycle of an Applet ? 73.How do you load an HTML page from an Applet ? 74.What is meant by Applet Stub Interface ? 75.What is meant by getCodeBase and getDocumentBase method ? 76.How can you call an applet from a HTML file ? 77.What is meant by Applet Flickering ? 78.What are the different types of Layouts ? What is meant by CardLayout ? What is the difference between GridLayout and GridBagLayout What is the difference between menuitem and checkboxmenu item. What is meant by vector class,dictionary class,hash table,and property class ?

Which class has no duplicate elements ? What is resource bundle ? What is an enumeration class ? What is meant by Swing ? What is the difference between AWT and Swing ? What is the difference between an applet and a Japplet What are all the components used in Swing ? What is meant by tab pans ? What is the use of JTree ? How can you add and remove nodes in Jtree. What is the method to expand and collapse nodes in a Jtree ? What is the use of JTable ? What is meant by JFC ? What is the class in Swing to change the appearance of the Frame in Runtime. How to reduce flicking in animation ? What is JDBC ? How do you connect to the database ? What are the steps ? What are the drivers available in JDBC ? Explain How can you load the driver ? What are the different types of statement s ? How can you created JDBC statements ? How will you perform transactions using JDBC ? What are the two drivers for web apllication? What are the different types of 2 tier and 3 tier architecture ? How can you retrieve warning in JDBC ? What is the exception thrown by JDBC ? What is meants by PreparedStatement ? What is difference between PreparedStatement and Statement ? How can you call the stored procedures ? What is meant by a ResultSet ? What is the difference between ExecuteUpdate and ExecuteQuery ? How do you know which driver is connected to a database ? What is DSN and System DSN and differentiate these two ? What is meant by TCP, IP, UDP ? What is the difference between TCP and UDP ? What is a proxy server ? What is meant by URL What is the use of parameter tag ? What is audio clip Interface and what are all the methods in it ? What is the difference between getAppletInfo and getParameterInfo ? How to communicate between applet and an applet ? What is meant by event handling ? 1. What are all the listeners in java and explain ? 2. What is meant by an adapter class ? 3. What are the types of mouse event listeners ? 4. What are the types of methods in mouse listeners ? 5. What is the difference between panel and frame ? 6. What is the default layout of the panel and frame ? 7. What is meant by controls and types ? 8. What is the difference between a scroll bar and a scroll panel. 9. What is the difference between list and choice ? 10. How to place a component on Windows ? 11. What is a socket and server sockets ? 12. When MalformedURLException and UnknownHost Exception throws ? 13. What is InetAddress ? 14. What is datagram and datagram packets and datagram sockets ?

15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64.

Write the range of multicast socket IP address ? What is meant by a servlet ? What are the types of servlets ? Explain What is the different between a Servlet and a CGI. What is the difference between 2 types of Servlets ? What is the type of method for sending request from HTTP server ? What are the exceptions thrown by Servlets ? Why ? What is the life cycle of a servlet ? What is meant by cookies ? What is HTTP Session ? What is the difference between GET and POST methods ? How can you run a Servlet Program ? How to commuincate between an applet and a servlet ? What is a Servlet-to-Servlet communcation ? What is Session Tracking ? What are the security issues in Servlets ? What is HTTP Tunneling ? How do you load an image in a Servlet ? What is Servlet Chaining ? What is URL Rewriting ? What is context switching ? What is meant by RMI ? Explain RMI Architecture ? What is meant by a stub ? What is meant by a skelotn ? What is meant by serialisation and deserialisation ? What is meant by RRL ? What is the use of TL ? What is RMI Registry ? What is rmic ? How will you pass parameter in RMI ? What exceptions are thrown by RMI ? What are the steps involved in RMI ? What is meant by bind(), rebind(), unbind() and lookup() methods What are the advanatages of RMI ? What is JNI ? What is Remote Interface ? What class is used to create Server side object ? What class is used to bind the server object with RMI Registry ? What is the use of getWriter method ? What is meant by Javabeans ? What is JAR file ? What is meant by manifest files ? What is Introspection ? What are the steps involved to create a bean ? Say any two properties in Beans ? What is persistence ? What is the use of beaninfo ? What are the interfaces you used in Beans ? What are the classes you used in Beans ?

http://www.vanapamula.com/JavaFaq.html 1. What are the difference between Java and C++? C++ does not have Garbage collector where as Java have Garbage collector & Hence Memory management is easy in Java.Java is Platform independent & hence it is portable among different platforms.There is no multiple inheritance in Java & it can be implemented with interfaces. 2. What is Method Signature? The combination of method name and parameter list is called the method signature. 3. What are Packages? Packages are libraries of related classes and interfaces that are grouped together.

4. What is an Abstract class? Abstract classes are classes from which no object can be initiated. Abstract classes cannot have objects of their own. Abstract class can be subclassed which in turn can instantiate and have objects of their own. 5. What are Interfaces? Interfaces contain a collection of methods that are implemented elsewhere. Methods in an interface class are public and abstract. Therefore interface cannot be instantiated. Provide security for application An interface can extend any number of interfaces A class can implement any number of interfaces An interface can be implemented in a class by using the keyword implements Most often interfaces are used to bring about a relationship between different classes. 6. What is an Encapsulation? Encapsulation is the mechanism that binds together code and the data it manipulates and keeps both safe from outside interface and misuse. 7. What is inheritance? It is the process by which one object acquires the properties of other objects. 8. What is polymorphism? The capability of the method to react differently on different objects is called polymorphism. 9. What are constructors? A constructor instantiates an object immediately upon creation. It has the same name as the class in which it resides. And it is syntactically similar to a method. 10. What is the difference between Methods and constructors? Constructor has the same name as class in which it resides, where as methods can have any name. Constructor will be executed at the time of object instantiation, where as method executes when ever it is called. Constructor will not have any return type. But methods may have return type. If method doesn't have any return type, we have to declare that as 'void'. 11. What is garbage collection in Java? When no reference to an object exists, that object assumed to be no longer needed, and the memory occupied by the object can be reclaimed. Garbage collection only occurs sporadically during the execution of the program. 12. What is the use of Finalize Method? Sometimes an object will need to perform some action when it destroyed. For example, if an object is holding some non-Java resources such as a file handle or then you might want to make sure these resources are freed before an object destroy. To handle such situations, Java provides a mechanism called finalization. By using finalization we can define specific actions that will occur when an object is just about to reclaim by the garbage collector. 13. What for transient keyword is used? Transient keyword is used for security purpose and when we use this keyword for any object that particular object cannot be serializable. 14. What is the difference between overloading of methods and overriding of methods? When we use multiple methods with same name but with different parameters we call it as Overloading of methods (these multiple methods has to be created prior to their usage). And if we just use a predefined method and write our own method then that is called as overriding of methods. 15. What is the difference between String and StringBuffer? String objects are said to be immutable, which means that they cannot be changed. To change the string referenced by string variable we have to throw away the reference to the old string & replace it with a reference to a new one. But StringBuffer object can be altered directly and they are called mutable Strings. 16. Define instanceof operator and equals() method? The instanceof operator returns true or false based on whether the object is an instance of the named class or any of that class's subclasses. It is possible to have two different String objects that contain the same values. If we use == operator to compare these objects, they are considered to be unequal. Although their contents match, they are not the same objects. In order to see whether two String objects have the same values, a method called equals() is used. 17. What is an inner class? If we define a class inside a class, then that is called an inner class. These inner classes can have access to variables and methods within the scope of a top-level class that they would not have as a separate class. Rules governing the scope of an inner class closely match those governing the variables. An inner class's name is not visible outside its scope, except in a fully qualified name, which helps in structuring classes within a package.

18. What is meant by synchronized method? When different threads act upon one common object a problem arises. A thread could be Interrupted when it is attempting to modify an object, and then another thread actually modifies that particular object. Consequently the first thread is made to run again, and this time the object is modified once more, which leads to errors. These type of problems can be avoided by using synchronized method. With this method, one thread can finish execution before another thread as per the priority can act upon the same object. 19. What are the different types of initiating a thread? There are two ways to initiate a thread, they are 1. Create a class that extends the Thread class or 2. Create a class that implements the Runnable interface. 20. What is meant by serializable interface? An object indicates that it can be used with streams by implementing the Serializable interface. The sole purpose of Serializable interface is to indicate that objects of that class can be stored and retrieved in serial form. Serialization enables object persistence because the stored object continues to serve a purpose even when no Java program is running. It contains information that can be restored in a program so that it can resume functioning. 21. What does trycatchfinally block will do? The function of try catch finally block is "try this bit of code that might cause an exception. If it executes okay, go on with the program. If it doesn't, catch the exception deal with it and also execute the code in finally clause either code in the try catch block cause an exception or not." 22. What is difference between throw and throws? If you write method that might throw an exception, then you must declare the possibility, using throws statement. And if you don't handle the exception in some way the method has no way to complete successfully. For this situation we use throw statement. i.e. we throw an exception with a statement that consists of keyword throw, followed by an exception object. This means we can throw our own exception. For this we have to use try catch block. Or we can also create an exception object and throw it in single statement. For example throw new DreadfulProblemException("Terrible difficulties") 23. What are the differences between an interface and an abstract class? Some use a semantic distinction: an abstract superclass models the "is" relationship, while an interface models the "has" relationship. The rule would thus be, if it's a subtype, inherit; otherwise, implement. But where the object boundaries are themselves at stake, it's circular to state this unless there are real-world metaphors to distinguish the objects from their properties and parents. So where there are no real-world metaphors, you have to understand the practical differences in Java (esp. vs. C++). Most differences between interfaces and abstract classes stem from three characteristics: Both define method signatures that a derived class will have. An abstract class can also define a partial implementation. A class can implement many interfaces, but inherit from only one class. 24. What is the difference between Swing and AWT? 1. Swing let you specify which look and feel your progra's GUI uses. AWT components always have the look and feel of the native platform. 2. Swing components are implemented with absolute with no native code. 3. Swing components are in javax.swing package where as AWT components are in java.awt package. 25. what is the difference among Arrays, Vectors and Hash maps? Arrays Can store any one type of data. Can store objects also Cannot be growable Vectors Can store any combination of data (like strings, integers, etc.) Only objects can be stored Vectors are growable. Hash Maps All the properties of this is similar to vectors. This will have key, value pair Retrieve the elements faster.

También podría gustarte