Showing posts with label java Versions. Show all posts
Showing posts with label java Versions. Show all posts

Thursday, April 4, 2013

Thinking In Java


1)       Main class (filename) cannot be private/protected/static.
2)       Main class has to be public/abstract/final.
3)       Method cannot be Abstract and final at the same time.
4)       Abstract class need not have a single abstract method.
5)       Methods cannot be overridden to be more private.
6)       Final method should not be overridden.
7)       Final object reference variable cannot be changed.
8)       Any number of null elements can be added to Vector/Linked List.
9)       A variable cannot be volatile and final at the same time.???
10)   Methods in an interface cannot be final as they need to be overridden by class implementing the interface. They are public by default.
11)   This’ keyword cannot be used with respect to static methods and variables.
12)   Static methods cannot be overridden to be non-static.
13)   Static variables and static initializer blocks are loaded before main.
14)   Top level classes and methods can never be private and abstract at the same time.
15)   Inner class variables cannot be ‘Static’ unless the class itself is declared as ‘Static’.
16)   Inner class can be a subclass of an outer class and can implement interfaces.
17)   Any component size changes from platform to platform.
18)   It is not necessary that if finalize() method is invoked the object will be garbage collected, also it is not absolutely necessary for it to perform clean-up operations
19)   String Buffer class does not override equals method of the Object class, hence it performs a shallow compare on Object references.
20)   Variables cannot be declared STATIC within any method. This is because lifetime and scope of local
21)   variables is restricted to that of the method in which they are declared whereas static variables are
22)   class variables and they are loaded when the class is loaded, and exist in memory till the class is unloaded.
23)   Anonymous classes cannot have any constructors.
24)   Garbage collector thread is the least priority thread, and it does “NOT” ensure that the program will not run out of memory.
25)   Variable Assignment is allowed during creation of an array. e.g. :
int I = 4;
       int a[] [] [] = new int [I] [I=3][I] ;
is perfectly legal. 
26)   Non – static methods can call static members of a class.
27)   Writer classes (PrintWriter , FileWriter etc.) are more oriented towards Unicode characters
28)   Finalize() method can be overloaded and made public
29)   Equals () method of Object class by default compares only references to objects.
30)   All method binding in Java uses late binding unless method unless the method is declared FINAL.
31)   An Interface can have a static inner class in its namespace
32)   Inner classes cannot be overridden like methods.
33)   In the derived class constructor one should only call private/final methods of base class.
34)   Comments cannot be nested in Java.
35)   Positive and negative zeroes are EQUAL.
36)   Floating-point operations never throw exceptions.
37)   All arrays in Java are objects. Each is associated with a class, which can be retrieved by getClass() method.
38)   An interface cannot have the same name as any of its enclosing class/interface.
Class Myclass {
interface Myclass // Compiler error
{ ….. }
}
39)   Methods in interfaces should NOT be declared static.
40)   Methods in an interface must NOT be declared native/strictfp/synchronized/final, but class
41)   implementing the interface can declare the method as native/synchronized/strictfp/final.
42)   Local variables cannot be referenced by ‘this’.
43)   Static inner class is also referred to as “Top-level nested class
44)   Static method CANNOT have a static inner class.
Public static method() {
static class Myclass //compile error
{
}
}
45)   Non-static inner class cannot have static variables unless they are declared FINAL.
46)   Map and Set cannot have duplicate elements.
47)   ToString () method is NEVER called on a NULL.
e.g. : Object o = null;
System.out.println(o);
will not throw NullPointerException.
48)   Division by 0 on float will NEVER throw ArithmeticException.
49)   Hashcode() method of Object class is Native method and can be overridden.
50)   Fields in an Interface can never be Transient.
51)   An instance of object class can be assigned to any valid class file.
E.g. : Object o = String.class is perfectly valid.
52)   Static block cannot make a forward reference to static variables defined after its definition.
53)   A.equals(B) will return true if and only if the 2 objects A and B are of the same class.
54)   Null literal does not have any type, hence it cannot be cast to any other type.
55)   Blank final variables have to be initialized. If they are class members, they can be initialized only in initializer blocks/constructors.
E.g.:
Class A
{
final int var;
{
var = 10;
} // Initializer block
}
56)   Initializer blocks are loaded only when object is created.
57)   Keywords like this/super CANNOT be used in initializer expressions of class Variables.
e.g. :
class A
{
int a = 10;
}
class B extends A
{
static int a = super.a; // COMPILE ERROR
}
58)   Abstract method CANNOT be synchronized.
59)   Method declaring a non-void return type in its header may not provide a return statement in its body
if it declares to throw an Exception.
e.g :
int method ()
{
throw new RuntimeException();
}
OR
Int method () throws Exception
{
throw new Exception();
}
are valid.
60)   Lock acquired on the object by a synchronized method is released if the method throws an Exception
61)   If an instance initializer block throws a checked Exception during its execution, which it does not catch, then the Exception must be declared in the throws clause of every constructor of the class.
e.g. :
class Test
{
{
if(true) throw new Exception();
}
Test () throws Exception
{ }
Test (int a) throws Exception
{ }
There can be no statement in a method body after a throw statement.
e.g. :
class NewClass
{
private void method () throws Exception
{
throw new Exception();
return; // COMPILE error Statement not reachable
}
}
62)   Constructors can have classes defined in their scope.
e.g. :
class Myclass
{
Myclass ()
{
class Constclass ()
{}
}
}
63)   Calling a private superclass constructor in the derived class is not allowed.
64)   A thread can be called daemon if and only if the creating thread is daemon.
65)   PrintStream class methods never throw IOException.
66)   Constructors can have empty return statements.
e.g. :
class A
{
A ()
{
return;
}
67)   Local class is implicitly STATIC if it is defined in static method/ static initializer.
e.g. :
private static void method ()
{
class Innclass
{}
}
is legal and Innclass is implicitly static.But it should NOT be explicitly prefixed with static keyword.
private static void method ()
{
static class Innclass //COMPILE ERROR
{}
}
68)   Static local class can only access ‘STATIC’ members of enclosing class
69)   An object is eligible for Garbage collection if the only references to the object are from other which are also eligible for GC.
70)   GridBagLayout honours preferred width of a component if Component fill is either NONE or VERTICAL.
71)   Null values cannot be added to a Hashtable.
72)   Thread object set to Null will not stop the thread from execution.
73)   If a method declares to throw a checked Exception, it must be caught by the catch block of the Exception or a superclass of the Exception. Peer class of Exception in the catch block does not satisfy the requirement and will flag a compiler error.
74)   In GridLayout constructor, both rows and columns cannot be simultaneously zero, else RuntimeException is thrown.
75)   GridLayout g = new GridLayout(0,0) will throw RuntimeException.
76)   Casting an NAN to an int or long will result in value zero.
77)   Following code will throw an ArraystoreException.
Point [] p = new Point [10];
P[0] = new Point ();
78)   Calling yield () in synchronized method or block does NOT relinquish the lock.???
79)   When argument to Math.abs method is of Integer.MIN_VALUE or Long.MIN_VALUE, the value remains the same.
80)   Accessing elements of an uninitialized array will cause NullPointerException to be thrown.
e.g. :
int a[] = new int[10];
System.out.println (a[0]); //NullPointerException.
81)   Final static variables can be initialized only in static initializer blocks or during assignment.
82)   Local variables are always thread-safe.
83)   Anonymous class is implicitly final.
84)   Abstract method in superclass cannot be accessed in the subclass using super.
e.g. :
abstract class A
{
abstract void method () ;
}
class B extends A
{
public void method()
{
super.method(); // COMPILER ERROR
}
}
85)   Local variables which are final CAN remain uninitialized.
Void method()
{
final int var;
}
is perfectly legal

LIST OF JAVA PACKAGES WITH THEIR UTILITY

java.applet Provides the classes necessary to create an applet and the classes an applet uses to communicate with its applet context.
java.awt Contains all of the classes for creating user interfaces and for painting graphics and images.
java.awt.color Provides classes for color spaces.
java.awt.datatransfer Provides interfaces and classes for transferring data between and within  applications.
java.awt.dnd Drag and Drop is a direct manipulation gesture found in many Graphical User Interface systems that provides a mechanism to transfer information between two entities logically associated with presentation elements in the GUI.
java.awt.event Provides interfaces and classes for dealing with different types of events fired by AWT
components.
java.awt.font Provides classes and interface relating to fonts.
java.awt.geom Provides the Java 2D classes for defining and performing operations on objects related to two-dimensional geometry.
java.awt.im Provides classes and interfaces for the input method framework.
java.awt.im.spi Provides interfaces that enable the development of input methods that can be used with any Java runtime environment.
java.awt.image Provides classes for creating and modifying images.
java.awt.image.renderable Provides classes and interfaces for producing rendering-independent images.
java.awt.print Provides classes and interfaces for a general printing API.
java.beans Contains classes related to developing beans -- components based on the JavaBeansTM architecture
java.beans.beancontext Provides classes and interfaces relating to bean context.
java.io Provides for system input and output through data streams, serialization and the file system.
java.lang Provides classes that are fundamental to the design of the Java programming language.
java.lang.ref Provides reference-object classes, which support a limited degree of interaction with the garbage collector.
java.lang.reflect Provides classes and interfaces for obtaining reflective information about classes and objects.
java.math Provides classes for performing arbitrary-precision integer arithmetic (BigInteger) and arbitraryprecision decimal arithmetic (BigDecimal).
java.net Provides the classes for implementing networking applications.
java.nio Defines buffers, which are containers for data, and provides an overview of the other NIO packages.
java.nio.channels Defines channels, which represent connections to entities that are capable of performing I/O operations, such as files and sockets; defines selectors, for multiplexed, non-blocking I/O
operations.
java.nio.channels.spi Service-provider classes for the java.nio.channels package.
java.nio.charset Defines charsets, decoders, and encoders, for translating between bytes and Unicode characters.
java.nio.charset.spi Service-provider classes for the java.nio.charset package.
java.rmi Provides the RMI package.
java.rmi.activation Provides support for RMI Object Activation.
java.rmi.dgc Provides classes and interface for RMI distributed garbage-collection (DGC).
java.rmi.registry Provides a class and two interfaces for the RMI registry.
java.rmi.server Provides classes and interfaces for supporting the server side of RMI.
java.security Provides the classes and interfaces for the security framework.
java.security.acl The classes and interfaces in this package have been superseded by classes in the java.security package.
java.security.cert Provides classes and interfaces for parsing and managing certificates, certificate  revocation lists (CRLs), and certification paths.
java.security.interfaces Provides interfaces for generating RSA (Rivest, Shamir and Adleman   AsymmetricCipher algorithm) keys as defined in the RSA Laboratory Technical Note PKCS#1, and DSA (Digital Signature Algorithm) keys as defined in NIST's FIPS-186.
java.security.spec Provides classes and interfaces for key specifications and algorithm parameter
specifications.
java.sql Provides the API for accessing and processing data stored in a data source (usually a relational
database) using the JavaTM programming language.
java.text Provides classes and interfaces for handling text,dates, numbers, and messages in a manner
independent of natural languages.
java.util Contains the collections framework, legacy collection classes, event model, date and time
facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number
generator, and a bit array).
java.util.jar Provides classes for reading and writing the JAR (Java ARchive) file format, which is based on the standard ZIP file format with an optional manifest file.
java.util.logging Provides the classes and interfaces of the JavaTM 2 platform's core logging facilities.
java.util.prefs This package allows applications to store and retrieve user and system preference and
configuration data.
java.util.regex Classes for matching character sequences against patterns specified by regular expressions.
java.util.zip Provides classes for reading and writing the standard ZIP and GZIP file formats.
javax.accessibility Defines a contract between user-interface components and an assistive technology that provides access to those components.
javax.crypto Provides the classes and interfaces for cryptographic operations.
javax.crypto.interfaces Provides interfaces for Diffie-Hellman keys as defined in RSA Laboratories' PKCS#3.
javax.crypto.spec Provides classes and interfaces for key specifications and algorithm parameter
specifications.
javax.imageio The main package of the Java Image I/O API.
javax.imageio.event A package of the Java Image I/O API dealing with synchronous notification of events during the reading and writing of images.
javax.imageio.metadata A package of the Java Image I/O API dealing with reading and writing metadata.
javax.imageio.plugins.jpeg Classes supporting the built -in JPEG plug-in.
javax.imageio.spi A package of the Java Image I/O API containing the plug-in interfaces for readers, writers, transcoders, and streams, and a runtime registry.
javax.imageio.stream A package of the Java Image I/O API dealing with low-level I/O from files and streams.
javax.naming Provides the classes and interfaces for accessing naming services.
javax.naming.directory Extends the javax.naming package to provide functionality for accessing directory services.
javax.naming.event Provides support for event notification when accessing naming and directory services.
javax.naming.ldap Provides support for LDAPv3 extended operations and controls.
javax.naming.spi Provides the means for dynamically plugging in support for accessing naming and directory services through the javax.naming and related packages.
javax.net Provides classes for networking applications.
javax.net.ssl Provides classes for the secure socket package.
javax.print Provides the principal classes and interfaces for the JavaTM Print Service API.
javax.print.attribute Provides classes and interfaces that describe the types of JavaTM Print Service attributes and how they can be collected into attribute sets.
javax.print.attribute.standard Package javax.print.attribute.standard contains classes for specific printing attributes.
javax.print.event Package javax.print.event contains event classes and listener interfaces.
javax.rmi Contains user APIs for RMI-IIOP.
javax.rmi.CORBA Contains portability APIs for RMI-IIOP.
javax.security.auth This package provides a framework for authentication and authorization.
javax.security.auth.callback This package provides the classes necessary for services to interact with applications in order to retrieve information (authentication data including usernames or passwords, for example) or to display information (error and warning messages, for example).
javax.security.auth.kerberos This package contains utility classes related to the Kerberos network authentication protocol.
javax.security.auth.login This package provides a pluggable authentication framework.
javax.security.auth.spi This package provides the interface to be used for implementing pluggable authentication modules.
javax.security.auth.x500 This package contains the classes that should be used to store X500 Principal and X500 Private Crendentials in a Subject.
javax.security.cert Provides classes for public key certificates.
javax.sound.midi Provides interfaces and classes for I/O, sequencing, and synthesis of MIDI (Musical Instrument Digital Interface) data.
javax.sound.midi.spi Supplies inte rfaces for service providers to implement when offering new MIDI devices, MIDI file readers and writers, or sound bank readers.
javax.sound.sampled Provides interfaces and classes for capture, processing, and playback of sampled audio data.
javax.sound.sampled.spi Supplies abstract classes for service providers to
subclass when offering new audio devices, sound file readers and writers, or audio format converters.
javax.sql Provides the API for server side data source access and processing from the JavaTM programming language.
javax.swing Provides a set of "lightweight" (all-Java language) components that, to the maximum degree possible, work the same on all platforms.
javax.swing.border Provides classes and interface for drawing specialized borders around a Swing component.
javax.swing.colorchooser Contains classes and interfaces used by the JColorChooser component.
javax.swing.event Provides for events fired by Swing components.
javax.swing.filechooser Contains classes and interfaces used by the JFileChooser component.
javax.swing.plaf Provides one interface and many abstract classes that Swing uses to provide its pluggable look-andfeel capabilities.
javax.swing.plaf.basic Provides user interface objects built according to the Basic look and feel.
javax.swing.plaf.metal Provides user interface objects built according to the Java look and feel (once codenamed Metal),which is the default look and feel.
javax.swing.plaf.multi Provides user interface objects that combine two ormore look and feels.
javax.swing.table Provides classes and interfaces for dealing with
javax.swing.JTable.
javax.swing.text Provides classes and interfaces that deal with editable and noneditable text components.
javax.swing.text.html Provides the class HTMLEditorKit and supporting classes for creating HTML text editors.
javax.swing.text.html.parser Provides the default HTML parser, along with support classes.
javax.swing.text.rtf Provides a class (RTFEditorKit) for creating Rich-Text-Format text editors.
javax.swing.tree Provides classes and interfaces for dealing withjavax.swing.JTree.
javax.swing.undo Allows developers to provide support for undo/redo in applications such as text editors.
javax.transaction Contains three exceptions thrown by the ORB machinery during unmarshalling.
javax.transaction.xa Provides the API that defines the contract between the transaction manager and the resource manager, which allows the transaction manager to enlist and delist resource objects (supplied by the resource manager driver) in JTA transactions.
javax.xml.parsers Provides classes allowing the processing of XML documents.
javax.xml.transform This package defines the generic APIs for processing transformation instructions, and performing a transformation from source to result.
javax.xml.transform.dom This package implements DOM-specific transformation APIs.
javax.xml.transform.sax This package implements SAX2-specific transformation APIs.
javax.xml.transform.stream This package implements stream- and URIspecific transformation APIs.