Subscribe to Java/SCJP        RSS Feed

SCJP Notes - Part 6

Icon Leave Comment
1. The elements of Java are
a) Java Compiler b Byte Code Verifier c) Class Loader d) Java Interpreter or JIT e) Runtime
A java interpreter takes up each line of byte code and looks up the meaning and then executes. A JIT speeds up the process by interpreting whole class file before executing it.
2. The JVM can invoke the main method in a top level/non nested class not defined as public.
3. An interface can contain a class as its member and can be instantiated outside of the interface.
interface I  {
	 class C2   {
I.C2 ob1=new I.C2();

4. Expressions can also be evaluated in the System.out.println() method.
5. When an array of primitives is declared then it contains the primitives in the array and an array of objects contains the object references that reference to the objects.
6. Length is a final field of any array which gives compiler error if a statement tries to assign a value to it and the length doesnít resolve to a java element.
7. Anonymous array can be created as new int[] {7,7,8,2,5}. These are also known as Just in Time arrays.
8. The array elements can be a narrower type than declared (primitives as well as objects). The narrower array references can be assigned to wider references for objects and not for primitives.
9. If array is initialized (given memory), all the elements are initialized to default value regardless of the location of declaration of the array.
10. A method named g() can declare a variable named g and this is also true from main.
11. The protected member inherited by a subclass in different package become private in that class so that other classes in the subclassís package canít see it. Moreover, the protected members can only be accessed by inheritance and not by making a reference and this is true for classes sub classing the class having protected member.
class I {
 protected class C2 {
I i = null;
C2 C2();

13. The implementation of an abstract method in subclass should not reduce the visibility of the method. The interface methods are in effect overridden in the concrete class that implements the interface. This means that the concrete class canít reduce the visibility of the implemented/overridden method which is always public in the interface.
14. There is nothing as local object, there are only local variables/reference variables.
15. First the explicit imports are resolved, then the classes from current package are imported and at last the implicit imports are done.
16. The signature of run() in runnable interface is public void run()
17. 5.0 == 5L returns true.
18. For getting the narrower value when a wider value is assigned, ignore the left portion of the bits that the narrower type canít accommodate.
19. int t= 1<<(char)2; and int t=1<<2L are valid.
20. Arguments to a case in switch block can be a literal or a final variable.
21. The rule to remember is default works just like any other case for fall-through!
22. There can be only one test expression in a for loop.
23. The increment expression in a for loop can be any valid expression of java.
24. Labeled continue and break statements should be inside the same loop which uses the label as defined in the labeled continue and break statement, otherwise compiler flashes error.
25. When an exception occurs, the clean up code can be placed in the catch block but then the same code may have to be written in each catch block which results in the need of finally block.
26. Even if there is a return statement in the try block which gets executed, the finally block is still executed in that case.
27. There canít be any code between try and catch or try and finally or catch and finally.
28. If subclass exception handlers are not declared before superclass handlers, compiler flashed error.
29. If a class handles a checked exception and also declares it then the calling method also has to call handle or declare it.
30. While rethrowing a checked exception, its handle and declare than handle or declare.
31. Once the program throws a RuntimeException (in the throwit() method) that
is not caught, the finally block will be executed and the program will be terminated. If a
method does not handle an exception, the finally block is executed before the exception
is propagated.
32.Only java expressions that return a value can be used alter : of a assert statement.
33.Finally is never bypassed, not even in case of assertions
34. Which method to call is decided at compile time in case of overloading and at run time in case of overriding.
35. While explicitly invoking the super constructor, only static variables and static methods can be referenced.
36. Interfaces donít have constructors, abstract classes have.
37. For a public class the default constructor will be public and for non-public, the constructor wonít have any access modifier.
38. new String[] {"Fluffy", "Fido",
"Rover", "Spike",
39. If a constructor has a call to this() then a call to super() isnít placed because both have to be the first line.
40. A regular inner class may be declared both abstract and private but not abstract
and final.
41. Field variables and methods can share the same name as that of the enclosing
42..StringBuffer should be used when a lot of modifications are to be done in Strings. E.g. handling I/O data streams
43. StringBuffer methods are synchronized but StringBuilder methods are not.
44. Whenever an object is serialized, all the parts of the object are also serialized. Static fields are not serialized.
45. To control serialization process, one should implement Externalizable interface and then must provide implementation for writeExternal(ObjectOuput out) and readExternal(ObjectInput in) methods.
46. The valid main method can be public static final
47. The size of a collection is the number items present in that collection and capacity is the maximum number of items that can be present in that collection.
48. Donít use transient variables in hashCode method as it causes the deserialized object to be different from serialized object.
49. A sorted collection canít be unordered.
50. Strongly reachable objects will not be collected. Softly reachable objects (images) will be collected when memory goes low. Weakly reachable objects will be collected at next garbage collection cycle. Phantom objects have their finalize() called but have not been collected.
51. ObjectInputStream and ObjectOutputStream are responsible for reading and writing objects. The corresponding methods are readObject and writeObject.
52. A copy of an object (with its state being persisted) can be made using clone() of cloneable interface.

0 Comments On This Entry


January 2015

25262728 29 3031

Recent Entries

Recent Comments

Search My Blog

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)