Wednesday 26 December 2012

Naming Conventions


Java Naming Conventions

Packages: 

Names should be in lowercase. With small projects that only have a few packages it's okay to just give them simple (but meaningful!) names:
     package mycalculator 

Classes: 
Names should be in CamelCase. Try to use nouns because a class is normally representing something in the real world:
   class Customer
   class Account 
Interfaces:
 Names should be in CamelCase. They tend to have a name that describes an operation that a class can do:
   interface Comparable
   interface Enumerable 
Note that some programmers like to distinguish interfaces by beginning the name with an "I":
   interface IComparable
   interface IEnumerable 
Methods: 
Names should be in mixed case. Use verbs to describe what the method does:
   void calculateTax()
    string getSurname() 
Variables: 
Names should be in mixed case. The names should represent what the value of the variable represents:
   string firstName
   int orderNumber 
Constants: Names should be in uppercase.
   static final int DEFAULT_WIDTH
   static final int MAX_HEIGHT 
Private:
Camel Case and prefix private variable with a “_”

Java Packages


Java Packages


JAVA API PACKAGES

         The Java API is the set of classes included with the Java Development Environment. These classes are written using the Java language and run on the JVM. The Java API includes everything from collection classes to GUI classes
         Java interfaces and classes are grouped into packages. The following are the java packages, from which you can access interfaces and classes, and then fields, constructors, and methods.
Java API packages
java.lang
Package that contains essential Java classes, including numerics, strings, objects, compiler, runtime, security, and threads. This is the only package that is automatically imported into every Java program.
java.io
Package that provides classes to manage input and output streams to read data from and write data to files, strings, and other sources.
java.util
Package that contains miscellaneous utility classes, including generic data structures, bit sets, time, date, string manipulation, random number generation, system properties, notification, and enumeration of data structures.
java.net
Package that provides classes for network support, including URLs, TCP sockets, UDP sockets, IP addresses, and a binary-to-text converter.
java.awt
Package that provides an integrated set of classes to manage user interface components such as windows, dialog boxes, buttons, checkboxes, lists, menus, scrollbars, and text fields. (AWT = Abstract Window Toolkit)
java.awt.image
Package that provides classes for managing image data, including color models, cropping, color filtering, setting pixel values, and grabbing snapshots.
java.awt.peer
Package that connects AWT components to their platform-specific implementations (such as Motif widgets or Microsoft Windows controls).
java.applet
Package that enables the creation of applets through the Applet class. It also provides several interfaces that connect an applet to its document and to resources for playing audio.

Friday 21 December 2012

Error Solving


JDBC - java.lang.ClassNotFoundException: com.mysql.jdbc.Driver Solution


  Error:

    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)


   Solution:



    Download  mysql-connector jar file from here:http://dev.mysql.com/downloads/connector/j/
       Extract that file get mysql-connector-java-5.1.22-bin.jar 

      i) Paste that file in:/usr/lib/jvm/java-6-openjdk/jre/lib
                         and :/usr/lib/jvm/java-6-openjdk/jre/lib/ext    
                                           (or)         
      ii)Paste that file in:/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib
                         and :/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/ext



Warning


when compile my java coding i got below warning:
            Note: PurchaseDetails.java uses unchecked or unsafe operations.
           Note: Recompile with -Xlint:unchecked for details.

Solution:
   This comes up in Java 5 and later if you're using collections without type specifiers (e.g., Arraylist()instead of ArrayList<String>()). It means that the compiler can't check that you're using the collection in a type-safe way, using generics.To get rid of the warning, just be specific about what type of objects you're storing in the collection. So, instead of

List myList = new ArrayList();
use

List<String> myList = new ArrayList<String>();