Vous êtes sur la page 1sur 4

Difference between C and Java: 1. C is a structure oriented program. 2. Java does not support explicit pointer type. 3.

Java requires that the functions with number arguments must be declared empty paranthesis and not with the void keyword in C. 4. Java does not define the type modifiers keywords auto,extern,register,signed & unsigned. Difference between C++ and Java: 1. C++ is object oriented program. 2. Java is a purely object oriented program 3. Java does not support Global variables 4. Java does not use the pointers 5. Java does not support operator overloading 6. Java does not template classes as in C++. 7. Java has replaced the destructor function with a finalize function. 8. Java does not support multiple Inheritance. Java and Internet Java is an object oriented language and a very simple language. Because it has no space for complexities. At the initial stages of its development it was called as OAK. OAK was designed for handling set up boxes and devices. But later new features were added to it and it was renamed as Java. Java became a general purpose language that had many features to support it as the internet language. Few of the features that favors it to be an internet language are: Cross Platform Compatibility: The java source files (java files with .java extension) after compilation generates the bytecode (the files with .class extension) which is further converted into the machine code by the interpreter. The byte code once generated can execute on any machine having a JVM. Every operating system has it's unique Java Virtual Machine (JVM) and the Java Runtime Environment (JRE). Support to Internet Protocols: Java has a rich variety of classes that abstracts the Internet protocols like HTTP , FTP, IP, TCP-IP, SMTP, DNS etc . Support to HTML: Most of the programming languages that are used for web application uses the html pages as a view to interact with the user. Java programming language provide it's support to html. For

example. Recently the extension package jipxhtml is developed in java to parse and create the html 4.0 documents. Support to XML parsing: Java has JAXP-APIs to read the xml data and create the xml document using different xml parsers like DOM and SAX. These APIs provides mechanism to share data among different applications over the internet. Support to Web Services : Java has a rich variety of APIs to use xml technology in diverse applications that supports N-Tiered Enterprise applications over the internet. Features like JAXB , JAXM, JAX-RPC , JAXR etc enables to implement web services in java applications. It makes java a most suited internet language. Java Packages Java is a object oriented programming language which uses classes and methods. A java class consists of methods and variables. Methods holds function of the class.

Class example:

Class addition { int a, b, c; }

Method Example:

public static void main (String[] args) { // This Java program prints "Hello World!" System.out.println{"Hello World!"); }

Package: A Java package is a set of classes which are grouped together. Every class is part of some package.

All classes in a file are part of the same package.

You can specify the package using a package declaration: package name ; as the first (non-comment) line in the file.

Multiple files can specify the same package name.

If no package is specified, the classes in the file go into a special unnamed package (the same unnamed package for all files).

If package name is specified, the file must be in a subdirectory called name (i.e., the directory name must match the package name).

You can access public classes in another (named) package using: package-name.class-name You can access the public fields and methods of such classes using: package-name.class-name.field-or-metho You can avoid having to include the package-name using: import package-name.*;

Examples of java packages:

java.applet java.awt java.awt.color java.awt.datatransfer java.awt.dnd java.awt.event java.awt.font java.awt.geom java.awt.im java.awt.im.spi java.awt.image java.awt.image.renderable java.awt.print

java.beans java.beans.beancontext java.io java.lang java.lang.ref java.lang.reflect java.math java.net java.nio java.nio.channels java.nio.channels.spi java.nio.charset java.nio.charset.spi

A package is a collection of related Java entities (such as classes, interfaces, exceptions, errors and enums). Packages are used for: 1. Resolving naming conflict of classes by prefixing the class name with a package name. For example, com.zzz.Circle and com.yyy.Circle are two distinct classes. Although they share the same class name Circle, but they belong to two different packages: com.zzz and com.yyy. These two classes can be used in the same program and distinguished using the fully-qualified class name - package name plus class name. This mechanism is called Namespace Management. 2. Access Control: Besides public and private, Java has two access control modifiers protected and default that are related to package. A protected entity is accessible by classes in the same package and its subclasses. An entity without access control modifier (i.e., default) is accessible by classes in the same package only. 3. For distributing a collection of reusable classes, usually in a format known as Java Archive (JAR) file.