Narendra Dhami

My Site

Archive for the ‘Java’ Category

New to Java programming

Posted by Narendra Dhami on November 11, 2009

New to Java programming? This page provides an overview of Java™ technology basics and explains how the technology fits into the context of contemporary software development. Links to relevant introductory developerWorks content, other educational resources, as well as IBM downloads and products give you a rich starting point for further investigation. More …

Posted in Java | Leave a Comment »

A-Z 52+ Java Core API Packages You Must Know

Posted by Narendra Dhami on September 17, 2009

This tutorial provides more than 52 Core API Packages defined by Java. These all the 52 Core API Packages are listed in alphabetical order.Beside Core API Packages, there are also some other Java Packages described in this tutorial.


1. java.applet

java.applet package provides the classes necessary to create an applet and the classes an applet uses to communicate with its applet context. The applet framework involves two entities: the applet and the applet context. An applet is an embeddable window with a few extra methods that the applet context can use to initialize, start, and stop the applet. The applet context is an application that is responsible for loading and running applets. For example, the applet context could be a Web browser or an applet development environment.

2. java.awt

java.awt package is the main package of the AWT, or Abstract Windowing Toolkit. It contains classes for graphics, including the Java 2D graphics capabilities introduced in the Java 2 platform, and also defines the basic graphical user interface (GUI) framework for Java. java.awt also includes a number of heavyweight GUI objects, many of which have been superseded by the javax.swing package.

3. java.awt.color

java.awt.color package supports color spaces and profiles. It contains an implementation of a color space based on the International Color Consortium (ICC) Profile Format Specification, Version 3.4, August 15, 1997. It also contains color profiles based on the ICC Profile Format Specification.

4. java.awt.datatransfer

java.awt.datatransfer package provides classes to support transfer of data to and from the system clipboard. Only string data is supported, and only cut, copy, and paste. Transferable interface is implemented by classes that represent data to be transferred. It includes methods to determine the possible data flavors of the object and to retrieve the data itself.

5. java.awt.dnd

java.awt.dnd package supports drag and drop operations.This package defines the classes and interfaces necessary to perform Drag and Drop operations in Java. It defines classes for the drag-source and the drop-target, as well as events for transferring the data being dragged. This package also provides a means for giving visual feedback to the user throughout the duration of the Drag and Drop operation.

6. java.awt.event

java.awt.event package provides interfaces and classes for dealing with different types of events fired by AWT components.

7. java.awt.font

java.awt.font package provides classes and interface relating to fonts.

8. java.awt.geom

java.awt.geom package provides classes for defining and performing operations on objects related to two-dimensional geometry.

9. package provides classes that allow input of Japenese, Chinese and Korean characters to text editing components.

10. package provides interfaces that enable the development of input methods that can be used with any Java runtime environment. Input methods are software components that let the user enter text in ways other than simple typing on a keyboard. They are commonly used to enter Japanese, Chinese, or Korean – languages using thousands of different characters – on keyboards with far fewer keys. However, this package also allows the development of input methods for other languages and the use of entirely different input mechanisms, such as handwriting recognition.

11. java.awt.image

java.awt.image package provides classes and interfaces for processing images.

12. java.awt.image.renderable

java.awt.image.renderable package provides classes and interfaces for producing rendering-independent images.

13. java.awt.print

java.awt.print package contains classes and interfaces that support printing. It has been introduced in Java 1.2 and supersedes the PrintJob class of the java.awt package. The most important class in this package is PrinterJob; it coordinates the printing process. The Printable and Pageable interfaces represent printable objects or documents that can be printed with a PrinterJob.


14. java.beans

java.beans package contains classes related to developing beans – components based on the JavaBeansTM architecture. A few of the classes are used by beans while they run in an application. For example, the event classes are used by beans that fire property and vetoable change events. However, most of the classes in this package are meant to be used by a bean editor. In particular, these classes help the bean editor
create a user interface that the user can use to customize the bean.

15. java.beans.beancontext

java.beans.beancontext package provides classes and interfaces relating to bean context. A bean context is a container for beans and defines the execution environment for the beans it contains. There can be several beans in a single bean context, and a bean context can be nested within another bean context. This package also contains events and listener interface for beans being added and removed from a bean context.


16. package provides for system input and output through data streams, serialization and the file system. Unless otherwise noted, passing a null argument to a constructor or method in any class or interface in this package will cause a NullPointerException to be thrown.


17. java.lang

java.lang package provides classes that are fundamental to the design of the Java programming language. The most important classes are Object, which is the root of the class hierarchy, and Class, instances of which represent classes at run time.

18. java.lang.annotation

java.lang.annotation package provides library support for the Java programming language annotation facility.

19. java.lang.instrument

java.lang.instrument package provides services that allow Java programming language agents to instrument programs running on the JVM. The mechanism for instrumentation is modification of the byte-codes of methods.

20. package provides the management interface for monitoring and management of the Java virtual machine as well as the operating system on which the Java virtual machine is running. It allows both local and remote monitoring and management of the running Java virtual machine.

21. java.lang.ref

java.lang.ref package provides reference-object classes, which support a limited degree of interaction with the garbage collector. A program may use a reference object to maintain a reference to some other object in such a way that the latter object may still be reclaimed by the collector. A program may also arrange to be notified some time after the collector has determined that the reachability of a given object has changed.

22. java.lang.reflect

java.lang.reflect package provides classes and interfaces for obtaining reflective information about classes and objects. Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions.


23. java.math

java.math package provides classes for performing arbitrary-precision integer arithmetic (BigInteger) and arbitrary-precision decimal arithmetic (BigDecimal). BigInteger is analogous to Java’s primitive integer types except that it provides arbitrary precision, hence operations on BigIntegers do not overflow or lose precision. In addition to standard arithmetic operations, BigInteger provides modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations. BigDecimal provides arbitrary-precision signed decimal numbers suitable for currency calculations and the like. BigDecimal gives the user complete control over rounding behavior, allowing the user to choose from a comprehensive set of eight rounding modes.


24. package provides the classes for implementing networking applications. Using the socket classes, you can communicate with any server on the Internet or implement your own Internet server. A number of classes are provided to make it convenient to use Universal Resource Locators (URLs) to retrieve data on the Internet.

25. java.nio

java.nio package defines buffers, which are containers for data, and provides an overview of the other NIO packages.

26. java.nio.channels

java.nio.channels package 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.

27. java.nio.channels.spi

java.nio.channels.spi package provides Service-provider classes for the java.nio.channels package.

28. java.nio.charset

java.nio.charset package defines charsets, decoders, and encoders, for translating between bytes and Unicode characters.

29. java.nio.charset.spi

java.nio.charset.spi package provides Service-provider classes for the java.nio.charset package.


30. java.rmi

java.rmi package provides classes for remote method invocation.

31. java.rmi.activation

java.rmi.activation package provides classes for activation of persistent objects.

32. java.rmi.dgc

java.rmi.dgc package provides classes and interface for RMI distributed garbage-collection (DGC).

33. java.rmi.registry

java.rmi.registry package provides a class and two interfaces for the RMI registry. A registry is a remote object that maps names to remote objects. A server registers its remote objects with the registry so that they can be looked up. When an object wants to invoke a method on a remote object, it must first lookup the remote object using its name. The registry returns to the calling object a reference to the remote object, using which a remote method can be invoked.

34. java.rmi.server

java.rmi.server package provides classes and interfaces for supporting the server side of RMI. A group of classes are used by the stubs and skeletons generated by the rmic stub compiler. Another group of classes implements the RMI Transport protocol and HTTP tunneling.


35. package contains the classes and interfaces that implement the Java security architecture. These classes can be divided into two broad categories. First, there are classes that implement access control and prevent untrusted code from performing sensitive operations. Second, there are authentication classes that implement message digests and digital signatures and can authenticate Java classes and other objects.

36. package defines, but does not implement, an incomplete framework for working with access control lists (ACLs). This package was added in Java 1.1, but has been superseded in Java 1.2 by the access-control mechanisms of the package.

37. package provides classes and interfaces for parsing and managing certificates, certificate revocation lists (CRLs), and certification paths. It contains support for X.509 v3 certificates and X.509 v2 CRLs.

38. package 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.

39. package provides classes and interfaces for key pecifications and algorithm parameter specifications.A key specification is a transparent representation of the key material that constitutes a key. A key may be specified in an algorithm-specific way, or in an algorithm-independent encoding format (such as ASN.1). This package contains key specifications for DSA public and private keys, RSA public and private keys, PKCS #8 private keys in DER-encoded format, and X.509 public and private keys in DER-encoded format. An algorithm parameter specification is a transparent representation of the sets of parameters used with an algorithm. This package contains an algorithm parameter specification for parameters used with the DSA algorithm.

40. java.sql

java.sql package provides the API for accessing and processing data stored in a data source (usually a relational database) using the JavaTM programming language. This API includes a framework whereby different drivers can be installed dynamically to access different data sources. Although the JDBC API is mainly geared to passing SQL statements to a database, it provides for reading and writing data from any data source with a tabular format. The reader/writer facility, available through the javax.sql.RowSet group of interfaces, can be customized to use and update data from a spread sheet, flat file, or any other tabular data source.


41. java.text

java.text package consists of classes and interfaces that are useful for writing internationalized programs that handle local customs, such as date and time formatting and string alphabetization, correctly.

42. java.text.spi

java.text.spi package provides Service provider classes for the classes in the java.text package.


43. java.util

java.util package 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).

44. java.util.concurrent

java.util.concurrent package contains Utility classes commonly useful in concurrent programming. This package includes a few small standardized extensible frameworks, as well as some classes that provide useful functionality and are otherwise tedious or difficult to implement.

45. java.util.concurrent.atomic

java.util.concurrent.atomic package provides a small toolkit of classes that support lock-free thread-safe programming on single variables.

46. java.util.concurrent.locks

java.util.concurrent.locks package provides Interfaces and classes which provide a framework for locking and waiting for conditions that is distinct from built-in synchronization and monitors. The framework permits much greater flexibility in the use of locks and conditions, at the expense of more awkward syntax.

47. java.util.jar

java.util.jar package 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. The manifest stores meta-information about the JAR file contents and is also used for signing JAR files.

48. java.util.logging

java.util.logging package provides the classes and interfaces of the JavaTM 2 platform’s core logging facilities. The central goal of the logging APIs is to support maintaining and servicing software at customer sites.

49. java.util.prefs

java.util.prefs package allows applications to store and retrieve user and system preference and configuration data. This data is stored persistently in an implementation-dependent backing store. There are two separate trees of preference nodes, one for user preferences and one for system preferences.

50. java.util.regex

java.util.regex package provides classes for matching character sequences against patterns specified by regular expressions.

51. java.util.spi

java.util.spi package provides Service provider classes for the classes in the java.util package.

52. package provides classes for reading and writing the standard ZIP and GZIP file formats. Also includes classes for compressing and decompressing data using the DEFLATE compression algorithm, which is used by the ZIP and GZIP file formats. Additionally, there are utility classes for computing the CRC-32 and Adler-32 checksums of arbitrary input streams.

Some other Java Packages

1. javax.accessibility.*
2. javax.activation.*
3. javax.bluetooth.*
4. javax.crypto.*
5. javax.ejb.*
6. javax.enterprise.*
7. javax.faces.*
8. javax.ide.*
9. javax.imageio.*
10. javax.jms.*
11. javax.mail.*
13. javax.microedition.*
14. javax.naming.*
16. javax.print.*
17. javax.resource.*
18. javax.rmi.*
20. javax.servlet.*
21. javax.sound.*
22. javax.sql.*
23. javax.swing.*
24. javax.transaction.*
25. javax.xml.*

sources: , ,

Posted in Java | 3 Comments »

AMF – Problems When Serializing Between Java and ActionScript

Posted by Narendra Dhami on July 31, 2008

Below are some tips and tricks when dealing with serialization between Java and ActionScript. I’ve spent some time and encountered some frustrations (especially when I was too tired) trying to understand why the value is not properly sent over the wire so I decided to document all of my mistakes. Over the time I will edit this post to add new insights

  • if something seems wrong turn on debugging in services-config.xml
  • a property must have a public getter and setter in order to be serialized. I know that is strange (why should I have a setter when it’s not needed?) but that’s it. I do not like it all because sometimes it breaks encapsulation
  • you should take care to map the ActionScript class with the corresponding Java class using the metadata. For example [RemoteClass(alias="")]
  • verify that the ActionScript object is included in the SWF file. If your project does not have a reference to the AS file then it will not be included in the resulting SWF so the Java class will be serialized to a generic object
  • you cannot serialize maps that have integers as keys See this bug
  • when serializing Hibernate entities be sure that all of them are initialized or use some kind of Open Session in View pattern – or better build a value object to contain only the data you really need.
  • a NULL number in Java is converted to 0 in ActionScript
  • a Long number from Java cannot be properly converted to Number in ActionScript – you will lose precision, so you should send it packed in a different way


Posted in Java | Leave a Comment »

iBATIS, Hibernate, and JPA: Which is right?

Posted by Narendra Dhami on July 28, 2008

Object-relational mapping in Java is a tricky business, and solutions like JDBC and entity beans have met with less than overwhelming
enthusiasm. But a new generation of ORM solutions has since emerged. These tools allow for easier programming and a closer
adherence to the ideals of object-oriented programming and multi-tiered architectural development. Learn how Hibernate, iBATIS,
and the Java Persistence API compare based on factors such as query-language support, performance, and portability across
different relational databases.

In this article we introduce and compare two of the most popular open source persistence frameworks, iBATIS and Hibernate. We also discuss the Java Persistence API (JPA). We introduce each solution and discuss its defining qualities, as well as its individual strengths and weaknesses
in broad application scenarios. We then compare iBATIS, Hibernate, and JPA based on factors such as performance, portability,
complexity, and adaptability to data model changes.

If you are a beginning Java programmer new to persistence concepts, reading this article will serve as a primer to the topic
and to the most popular open source persistence solutions. If you are familiar with all three solutions and simply want a
straightforward comparison, you will find it in the section “Comparing persistence technologies.”

Understanding persistence

Persistence is an attribute of data that ensures that it is available even beyond the lifetime of an application. For an object-oriented
language like Java, persistence ensures that the state of an object is accessible even after the application that created
it has stopped executing.

More …

Posted in Java | Leave a Comment »

Open-source Web applications, PHP vs. Java (Part 2 of 2)

Posted by Narendra Dhami on July 23, 2008

The first part of this article reviewed some elevant open-source Web applications in both the PHP and Java worlds. The conclusion was that there are massively popular PHP projects and somewhat popular if not obscure Java counterparts. I’m a Java fan and it pains me to discover this reality. The user comments also underlined this feeling.

Is it the technical merits of PHP?

In my experience, the technical merits
of PHP are below those of Java as a language and as a runtime environment (standard API, virtual machine).

Compared to Java, the code quality of PHP projects has a faster decreasing rate as the codebase size grows. The root cause is that PHP was created to solve small size problems and
this makes it difficult to manage larger projects.

PHP 3 and 4 had basic object-oriented
features, while PHP 5 improved them considerably, both at the language and the runtime level. There are several PHP MVC frameworks to ease the structuring of larger projects, but these are most effective when running on PHP 5. Most popular open-source PHP projects still run on PHP 4 and tend not to use MVC frameworks at all.

Looking at the staggering number of plugins available for the popular PHP open-source projects, one could conclude that their code is easily understandable and that PHP has well-rounded application extension mechanisms. Well, not exactly true.

The typical PHP extension mechanism is procedural and works like this:

  • list the subdirectories of the extensions directory,
  • analyze the predefined directory structure for each extension,
  • execute some predefined PHP files that should auto-register their resources and actions.

More …

Posted in Java, PHP | Leave a Comment »

Open-source Web applications, PHP vs. Java (Part 1 of 2)

Posted by Narendra Dhami on July 23, 2008

It is common knowledge that PHP does well in the open-source Web applications space. PHP has numerous representatives for most application categories, and for some it provides a clear leader, like WordPress. On the other hand, most Java counterparts have apparently failed to reach the same popularity.

Below is an overview of the existing open-source PHP and Java implementations for the following categories of applications: forum, blog, wiki and content management systems (CMS). These are among the most commonly used types of on-line software. More…

Posted in Java, PHP | Leave a Comment »