p

Java Packages And Programs

Java Packages And Programs 
  
Packages are used in Java in order to prevent naming conflictsto control accessto make searching/locating and usage of classesinterfacesenumerations and annotations easieretc. 
Package can be defined as a grouping of related types(classesinterfacesenumerations and annotations ) providing access protection and name space management. 
Some of the existing packages in Java are: 
• java.lang - bundles the fundamental classes 
• java.io - classes for inputoutput functions are bundled in this package 
Programmers can define their own packages to bundle group of classes/interfacesetcIt is a good practice to group related classes implemented by you so that a programmer can easily determine that the classesinterfacesenumerationsannotations are related. 
Since the package creates a new namespace there won't be any name conflicts with names in other packagesUsing packagesit is easier to provide access control and it is also easier to locate the related classes. 
Creating a package: 
When creating a packageyou should choose a name for the package and put a package statement with that name at the top of every source file that contains the classesinterfacesenumerationsand annotation types that you want to include in the package. 
The package statement should be the first line in the source fileThere can be only one package statement in each source fileand it applies to all types in the file. 
If a package statement is not used then the classinterfacesenumerationsand annotation types will be put into an unnamed package. 
Types of Java programs: 
Applications and Applets 
Applications - Java programs that run directly on your machine. 
I). Applications must have a main(). 
II). Java applications are compiled using the javac command and run using the java command. 
Applets - Java programs that can run over the InternetThe standard client/server model is used when the Applet is executedThe server stores the Java Appletwhich is sent to the client machine running the browserwhere the Applet is then run. 
I). Applets do not require a main(), but in general will have a paint(). 
II). An Applet also requires an HTML file before it can be executed. 
III). Java Applets are also compiled using the javac commandbut are are run either with a browser or with the appletviewer command. 
Important Features of Java 
Java is a "platform-independent language". 
Java program can be compiled once into a Java Bytecode programThe compiled program can then be run on any computer that has an interpreter for the Java virtual machineOther languages have to be re-compiled for each platform on which they are going to runThe point about Java is that it can be executed on many different types of computers without being recompiled. 
Java is an object-oriented programming language. 
An object consists of some data together with a set of subroutines that manipulate that data. (An object is a kind of "module," or self-contained entity that communicates with the rest of the world through a well-defined interfaceAn object should represent some coherent concept or real-world object.) 
The Java platform is designed from the ground up to support concurrent programmingwith basic concurrency support in the Java programming language and the Java class libraries. 
  Article Source: http://EzineArticles.com/8937584 
Previous
Next Post »