Thursday, February 27, 2014

Java



Java Programming Language

         Java language redirects here for the natural language from the Indonesian island of Java, see Javanese language not to be confused with JavaScript.

        Java is a computer programming language that is concurrent, class-based, object oriented, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers write once, run anywhere, meaning that code that runs on one platform does not need to be recompiled to run on another. Java applications are typically complied with byte code that can run on any java virtual machine regardless of computer architecture. Java is as one of the most popular programming language in use, particularly for client server web applications, with a reported 9 million developers. Java was originally developed by James Gosling at Sun Microsystems and released in component of Sun Microsystems java platform. The language derives much    of its syntax from C and C++, but it has fewer low level facilities than either of them.

         The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1991 and first release in 1995. Sun relicensed most of its Java technologies under the GNU—General Public License. Others have also developed alternative implementation of these sun technologies, such as the GNU compiler for java, GNU class path and lcedtea web browser plugin for applets.

Java Package

In simple, it is a way of categorizing the classes and interfaces. When developing applications in Java, hundreds of classes and interfaces will be written, therefore categorizing these classes is a must as well as makes life much easier.

Java Software

Java is a set of several products and specifications from which has since merged with, that together provide a system for developing and deploying it in a computing environment. Java is used in a wide variety of from on the low end, to on the high end. While less common, are sometimes used to provide improved and secure functions while browsing the on desktop computers.

Writing in the java programming language is the primary way to produce code that will be deployed as java byte code. There are, however byte code complies available for other languages such as ada, java script python, and ruby. Several new languages have been designed to run natively on the, Java virtual machine, such as scala eliminates certain low-level constructs such as and has a very simple memory model where every object is and all variables of object types are, C++ but object-oriented features are modelled after and Memory management is handled through integrated automatic performed by the JVM.

Java Platform

The Java platform is the name for a bundle of related programs from Sun that allow for developing and running programs written in the java programming language. The platform is not specific to any one processor or, but rather an execution engine called a and a compiler with a set of libraries that are implemented for various hardware and operating systems so that Java programs can run identically on all of them.
The Java platform consists of several programs, each of which provides a portion of its overall capabilities. For example, the Java compiler, which converts Java source code into Java byte code an intermediate language for the JVM, is provided as part of the JDK. The JRE, complementing the JVM with a, converts intermediate byte code into native machine code on the fly. An extensive set of libraries are also part of the Java platform.
The essential components in the platform are the Java language compiler, the libraries, and the runtime environment in which Java intermediate byte code executes according to the rules laid out in the virtual machine specification.
One characteristic of Java is portability, which means that computer programs written in the Java language must run similarly on any hardware/operating-system platform. This is achieved by compiling the Java language code to an intermediate representation called, instead of directly to platform-specific. Java byte code instructions are analogous to machine code, but they are intended to be by a   written specifically for the host hardware. Installed on their own machine for standalone Java applications, or in a Web browser for Java.
Standardized libraries provide a generic way to access host-specific features such as graphics, and networking.
A major benefit of using byte code is porting. However, the overhead of interpretation means that interpreted programs almost always run more slowly than programs compiled to native executables would. Just-in-Time compilers were introduced from early stages that compile byte codes to machine code during runtime.
Platform is cross-combination of hardware or software environment in which a program runs. We are already known with the most popular platform like Microsoft Windows, Linux, Solaris OS, and Macintoshes OS. The Java platform differs from other platform, which is only software-only platform which runs on other hardware-based platforms.

Java Virtual Machine

The heart of the Java platform is the concept of a virtual machine that executes programs. This byte code is the same no matter what hardware or operating system the program is running under. There is a JIT Just in Time compiler within the Java Virtual Machine, or JVM. The JIT compiler translates the Java byte code into native processor instructions at run-time and caches the native code in memory during execution.
The use of byte code as an intermediate language permits Java programs to run on any platform that has a virtual machine available. The use of a JIT compiler means that Java applications, after a short delay during loading and once they have warmed up by being all or mostly JIT-compiled, tend to run about as fast as native programs, Since JVM implementation has included a instead of an interpreter.

Although Java programs are or platform independent, the code of the Java Virtual Machines JVM that execute these programs is not. Every supported operating platform has its own JVM.
Java Development Kit
The Java Development Kit is a product aimed at Java developers. Since the introduction of Java, it has been by far the most widely used Java. It contains a Java compiler, a full copy of the, and many other important development tools.
 
Which Java package do need

JDK: Java Development Kit for Java Developers. Includes a complete JRE plus tools for developing, debugging, and monitoring Java applications.

Server JRE: Server Java Run time Environment for deploying Java applications on servers. Includes tools for JVM monitoring and tools commonly required for server applications, but does not include browser integration the Java plug-in, auto-update, nor an installer. 

JRE: Java Run-time Environment covers most end-users needs, Contains everything required to run Java applications on your system.

Memory Management

Java uses an automatic garbage collector to manage memory in the object life cycle. The programmer determines when objects are created, and the Java run time is responsible for recovering the memory once objects are no longer in use. Once no references to an object remain, the becomes eligible to be freed automatically by the garbage collector. Something similar to a  may still occur if a programmer's code holds a reference to an object that is no longer needed, typically when objects that are no longer needed are stored in containers that are still in use. If methods for a nonexistent object are called, a null pointer exception is thrown.

One of the ideas behind Java's automatic memory management model is that programmers can be spared the burden of having to perform manual memory management. In some languages, memory for the creation of objects is implicitly allocated on the, or explicitly allocated and reallocated from the. In the latter case the responsibility of managing memory resides with the programmer. If the program does not reallocate an object, a occurs. If the program attempts to access or reallocate memory that has already been reallocated, the result is undefined and difficult to predict, and the program is likely to become unstable and or crash. This can be partially remedied by the use of, but these add overhead and complexity. Note that garbage collection does not prevent logical memory leaks, those where the memory is still referenced but never used.
Garbage collection may happen at any time. Ideally, it will occur when a program is idle. It is guaranteed to be triggered if there is insufficient free memory on the heap to allocate a new object; this can cause a program to stall momentarily. Explicit memory management is not possible in Java.
Java does not support C and C++ style, where object addresses and unsigned integers usually long integers can be used interchangeably. This allows the garbage collector to relocate referenced objects and ensures type safety and security.

As in and some other object-oriented languages, variables of Java's  are not objects. Values of primitive types are either stored directly in fields for objects or on the for methods rather than on the heap, as is commonly true for objects but see. This was a conscious decision by Java's designers for performance reasons. Because of this, Java was not considered to be a pure object-oriented programming language. However, as of Java 5.0, enables programmers to proceed as if primitive types were instances of their wrapper class.

Java contains multiple types of garbage collectors. By default Hotspot uses the, also known as the CMS garbage collector or CMS. However, there are also several other garbage collectors that can be used to manage the heap. For 90% of applications in Java, the CMS garbage collector is sufficient. Oracle aims to replace CMS with the garbage first collector.

Java Server Pages

Java Server Pages are Java EE components that generate responses, typically pages, to requests from. JSPs embed Java code in an HTML page by using the special <% and %>. A JSP is compiled to a Java servlet, a Java application in its own right, the first time it is accessed. After that, the generated servlet creates the response.

Java Documentation

Java documentation is a comprehensive documentation system, created by, used by many Java developers. It provides developers with an organized system for documenting their code. Comments have an extra asterisk at the beginning, the tags are /** and */, whereas the normal multi-line comments in Java are set off with the tags /* and */.

Java Principles

There were five primary goals in the creation of the Java language,
1.     It should be simple, object-oriented and familiar.
2.     It should be robust and secure.
3.     It should be architecture-neutral and portable.
4.     It should execute with high performance.
5.     It should be interpreted, threaded, and dynamic.

Java Applet

Java applets are programs that are embedded in other applications, typically in a Web page displayed in a web browser.


Import javax.swing.JApplet;
Import java.awt.Graphics;
 
public class Hello extends JApplet
 {
    public void paintComponent(final Graphics g)
 {
        g.drawString("Hello, world!", 65, 95);
    }
}
 
The import statements direct to include the and classes in the compilation. The import statement allows these classes to be referenced in the using the simple class name instead of the “fully qualified class name”. javax.swing.JApplet.
The Hello class extends the JApplet Java Applet class, the JApplet class provides the framework for the host application to display and control the of the applet. The JApplet class is a JComponent Java Graphical Component which provides the applet with the capability to display a and respond to user.
The Hello class the method additionally indicated with the, supported as of JDK 1.5, Override inherited from the to provide the code to display the applet. The paintComponent () method is passed a “Graphics” object that contains the graphic context used to display the applet. The paintComponent () method calls the graphic context method to display the "Hello, world!" string at a offset of (65, 95) from the upper-left corner in the applet's display.
    
An applet is placed in an document using the . The applet tag has three attributes set: code="Hello" specifies the name of the JApplet class and width="200" height="200" sets the pixel width and height of the applet. Applets may also be embedded in HTML using either the object or embed element, although support for these elements by Web browsers is inconsistent. However, the applet tag is deprecated, so the object tag is preferred where supported.
The host application, typically a Web browser, instantiates the Hello applet and creates a for the applet. Once the applet has initialized itself, it is added to the AWT display hierarchy. The paintComponent () method is called by the AWT whenever the display needs the applet to draw itself.
Java Servlet 

      Java servlet technology provides Web developers with a simple, consistent mechanism for extending the functionality of a Web server and for accessing existing business systems. Servlet are Java EE components that generate responses typically pages to requests typically  requests from. A servlet can almost be thought of as an applet that runs on the server side without a face.
 
import java.io.*;
import javax.servlet.*;
 
public class Hello extends GenericServlet 
               {
    public void service(final ServletRequest request, final ServletResponse response)
    throws ServletException, IOException 
               {
        response.setContentType("text/html");
        final PrintWriter pw = response.getWriter();
               try 
               {
            pw.println("Hello, world!");
                 } 
               finally
                {
            pw.close();
                }
    }
}

The import statements direct the Java compiler to include all of the public classes and from the   packages in the compilation. Packages make Java well suited for large scale applications.
The Hello class extends the class, the GenericServlet class provides the interface for the to forward requests to the servlet and control the servlet's lifecycle.
The Hello class overrides the method defined by the to provide the code for the service request handler. The service () method is passed, a object that contains the request from the client and a ject used to create the response returned to the client. The service () method declares that it “throws” the and if a problem prevents it from responding to the request.
 
Java meets the Web

In June and July 1994, after three days of brainstorming with, the Director of Science for Sun, Gosling, Joy, Naught on, , the team re-targeted the platform for the. They felt that with the advent of graphical like, the Internet was on its way to evolving into the same highly interactive medium that they had envisioned for cable TV. As a prototype, Naught on wrote a small browser, Web Runner named after the movie, later renamed.

That year, the language was renamed Java after a search revealed that Oak was used by. Although Java 1.0a was available for download in 1994, the first public release of Java was 1.0a2 with the HotJava browser on May 23, 1995, announced by Gage at the conference. His announcement was accompanied by a surprise announcement by, Executive Vice President of that Netscape browsers would be including Java support. The Java Soft group was formed by Sun Microsystems to develop the technology.

Java Languages

The word Java, alone, usually refers to the Java programming language that was designed for use with the Java platform. Programming languages are typically outside of the scope of the phrase platform, although the Java programming language was listed as a core part of the Java platform before Java 7. The language and runtime were therefore commonly considered a single unit. However, an effort was made with the Java 7 specification to more clearly treat the Java language and the Java virtual machine as separate entities, so that they are no longer considered a single unit.
Third parties have produced many that target the JVM. Some of these are for existing languages, while others are for extensions to the Java language. These include,

A lightweight scripting language for Java.
A dialect of the Lisp programming language.
A dynamic language with features similar to those of Python, Ruby, Perl, and Smalltalk.
A Ruby interpreter.
A Python interpreter.
An industrial programming language for JVM with full interoperability.
A JavaScript interpreter.
A multi-paradigm programming language designed as a better Java.
A general-purpose Java Virtual Machine-based programming language released under the Apache License 2.0.

Java Object and Class

Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts,

Object - Objects have states and behaviours. Example, A dog has states - color, name, breed as well as behaviours -wagging, barking, and eating. An object is an instance of a class. 

Class - A class can be defined as a template/blue print that describes the behaviours states that object of its type support.

Objects in Java

Let us now look deep into what are objects. If we consider the real-world we can find many objects around us, Cars, Dogs, Humans, etc. All these objects have a state and behaviour. If we consider a dog, then its state is - name, breed, color, and the behaviour is - barking, wagging, running
If you compare the software object with a real world object, they have very similar characteristics.
Software objects also have a state and behavior. A software object's state is stored in fields and behaviour is shown via methods.
So in software development, methods operate on the internal state of an object and the object-to-object communication is done via methods.

Classes in Java

A class is a blue print from which individual objects are created. A sample of a class is given below, A class can contain any of the following variable types.
Local variables: Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed.

Instance variables: Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded. Instance variables can be accessed from inside any method, constructor or blocks of that particular class.

Class variables: Class variables are variables declared with in a class, outside any method, with the static keyword.

Creating an Object

As mentioned previously, a class provides the blueprints for objects. So basically an object is created from a class. In Java, the new key word is used to create new objects.
There are three steps when creating an object from a class
Declaration: A variable declaration with a variable name with an object type.

Instantiation: The new key word is used to create the object.

Initialization: The new keyword is followed by a call to a constructor. This call initializes the new object.
Java Operators

·       Arithmetic Operators
·       Relational Operators
·       Bitwise Operators
·       Logical Operators
·       Assignment Operators
·       Misc Operators

Java Definition

         Java is a programming language developed by Sun Microsystems. It implements a strong security model, which prevents compiled Java programs from illicitly accessing resources on the system where they execute or on the network. Popular browsers, as well as some servers and other systems implement interpreters. These are used to display interactive user interfaces, and to script behaviour on these systems.
  •   While implementation problems have opened security vulnerabilities in some Java interpreters Java Virtual Machines or, the design of this language makes it at least theoretically possible to execute program with reasonable assurances about its, and in particular its ability to cause harm.
         New generation, general purpose, versatile programming language that can run on virtually any type of computer is platform and device independent. Developed in 1995 by James Gosling of Sun Microsystems specifically for network heavy environments such as internet and enterprise intranets, it is a major part of the information infrastructure being developed all over the world. like the C++ language java is object oriented meaning its programs are built with modules of code which can be employed in building new programs without rewriting the same code. However unlike C++ it is an interpreted language and therefore has longer execution time than the complied languages, although the gap has considerably narrowed over the last few years.

What is Java

          A high level programming language developed by Sun Microsystems. Java was originally called OAK was unsuccessful so in 1995 Sun changed the name to java and modified the language to take advantage of the burgeoning World Wide Web.

Java is an object oriented language similar to C++, but simplified to eliminate language features that cause common programming errors. Java source codes files are complied into a format called byte code files are which can then be excited by java interpreter. Complied java code can run on most computers because java interpreters and run time environment, known as java virtual machine, exits for most operating system, including UNIX, the machine OS, and windows. 

        Java is a general purpose programming language with a number of futures that make the language well suited for use on the World Wide Web. Small java application are called java applets and can be download from a web server and run on your computer by a java compatible web browser, such as Netscape Navigator or Microsoft Internet Explorer. 

      Java is an object oriented programming language developed by Sun Microsystems that allows compiled applications to be run on many different and otherwise incompatible platforms through the use of a Java compatible engine developed for each specific platform. Java's mantra is Write once, run anywhere, which is largely true. Various levels of device capabilities exist, though, requiring the creation of the MIDP 1 and MIDP 2 Java profiles. MIDP 2 applications, which are more powerful, will not run on a MIDP 1 device. 

Java is a programming language expressly designed for use in the environment of the Internet. It was designed to have the look and feel of the language, but it is simpler to use than C++ and enforces an model. Java can be used to create complete applications that may run on a single computer or be distributed among servers and clients in a network. It can also be used to build a small application module or for use as part of a Web page. Applets make it possible for a Web page user to interact with the page.
          The major characteristics of Java are
                      The programs you create are portable in a network. Your source program is compiled into what Java calls, which can be run anywhere in a network on that has a Java. The Java virtual machine interprets the byte code into code that will run on the real computer hardware. This means that individual computer platform differences such as instruction lengths can be recognized and accommodated locally just as the program is being executed. Platform-specific versions of your program are no longer needed.

       The code is, here meaning that, unlike programs written in C++ and perhaps some other languages, the Java objects can contain no references to data external to themselves or other known objects. This ensures that an instruction cannot contain the address of data storage in another application or in the operating system itself, either of which would cause the program and perhaps the operating system itself to terminate or "crash." The Java virtual machine makes a number of checks on each object to ensure integrity.



·                             Java is object-oriented, which means that, among other characteristics, an can take advantage of being part of a of objects and inherit code that is common to the class. Objects are thought of as nouns that a user might relate to rather than the traditional procedural verbs. A can be thought of as one of the object's capabilities or behaviours.

  •        In addition to being executed at the client rather than the server, a Java applet has other characteristics designed to make it run fast.

  •        Relative to C++, Java is easier to learn.
         Java was introduced by Sun Microsystems in 1995 and instantly created a new sense of the interactive possibilities of the Web. Both of the major Web browsers include a Java virtual machine. Almost all major operating system developers have added Java compilers as part of their product offerings.

Java is a programming language that developers use to create applications on your computer. Chances are you've downloaded a program that required the Java runtime, and so you probably have it installed it on your system. Java also has a web plug-in that allows you to run these apps in your browser.

       Java is not, however, the same as JavaScript. In fact, they besides their names. JavaScript is generally used within HTML documents like web pages rather than as standalone apps that run inside them. This can be a bit confusing since Java also runs in your browser, but they are quite different. A large number of web sites use JavaScript, very few require Java.

With that in mind, we're only going to discuss Java here. That's the really insecure one that's driving everyone crazy. For a better explained on JavaScript, check out. For the answer to your question, read on.

Java is a computer programming language. It enables programmers to write computer instructions using English based commands, instead of having to write in numeric codes. It’s known as a high-level language because it can be read and written easily by humans. Like English, Java has a set of rules that determine how the instructions are written. These rules are known as its syntax. Once a program has been written, the high-level instructions are translated into numeric codes that computers can understand and execute.

Who Created Java:

In the early nineties, Java was created by a team led by James Gosling for Sun Microsystems. It was originally designed for use on digital mobile devices, such as cell phones. However, when Java 1.0 was released to the public in 1996, its main focus had shifted to use on the Internet. It provided more interactivity with users by giving developers a way to produce animated WebPages . Over the years it has evolved as a successful language for use both on and off the Internet. A decade later, it’s still an extremely popular language with over 6.5million developers worldwide.

Java Use

Java technology is a high-level programming and a platform independent language. Java is designed to work in the distributed environment on the Internet. Java has a GUI features that provides you better look and feel over the C++ language, moreover it is easier to use than C++ and works on the concept of object-oriented programming model. Java enables us to play online games, video, audio, chat with people around the world, Banking Application, view 3D image and Shopping Cart. Java find its extensive use in the intranet applications and other e-business solutions that are the grassroots of corporate computing. Java, regarded as the most well described and planned language to develop applications for the Web.

Java is a well known technology which allows you for software designed and written  only once for an  virtual machine to run on a different  computers, supports various Operating System like Windows PCs, Macintoshes, and Unix computers. On the web aspect, Java is popular on web servers, used by many of the largest interactive websites. Java is used to create standalone applications which may run on a single computer or in distributed network. It is also be used to create a small application program based on applet, which is further used for Web page. Applets make easy and possible to interact with the Web page.


Java Preferred Over Other Languages
             
The Java is a high-level programming language that can be supported by all of the following features,

Simple
Architecture neutral
Object oriented
Portable
Distributed
High performance
Multithreaded
Robust
Dynamic
Secure

Java has advantages over other languages and environments that make it suitable for just about any programming task. 

Java’s back, baby. Of course, lots of us never stopped using Java in the first place, or perhaps we weren’t allowed to. But where platform selection was elective, especially among startups and web developers, alternative platforms have offered more agility and expressiveness over the last 10 years. The likes of PHP and Ruby on Rails enable developers to do a whole lot more with less.

You can actually hire engineers

Not to be sniffed at when your Node.js Ninjas and Rails Rock stars get headhunted into the latest impossibly well-funded startup.

 IDEs take the pain away

Eclipse and NetBeans are astonishingly powerful tools, and can mask some of the admitted horror that is Java API soup. Bend like a reed, admit you can’t know everything, and float downstream on the good ship auto complete.

Language support

You don’t have to write Java to use Java. You can get all the benefits of the portable JVM run time but scribble away in the familiar environs of Ruby or Python. It and that’s not to mention the newer languages aimed at modern programming such as Scala, Groovy or Cloture.

 Android

Who can resist the little green robot  made a sensible choice when they chose the Java language to power what’s becoming the world’s dominant mobile phone platform. So, maybe Oracle has a  with this, but programmers  new and seasoned alike  are picking up Java as mobile becomes the future of consumer software.

Everybody else does

      Java’s ecosystem is a goldmine. Pretty much everything you want to do, there’s a library for it. Actually, there’s probably an Apache project for it. Very often the lowest impedance way to speak to the rest of the world is via a Java API.

 It changes slowly

We’re celebrating the release of Java 7 right now. It’s been two years in the making, and frankly, there’s not a whole lot that’s changed for most people. If you can take your finger off the refresh button at  for more than an hour, any software that lives longer than a year becomes a real pain to maintain when the underlying platform keeps changing. Yes, looking at you, Rails.

You will end up using it anyway

At a certain point you’ll need performance, predictability and a ready supply of engineers. Scaling, deploying and programming to the cloud are places where Java excels. Twitter, and will be.

Easy to Use: The fundamentals of Java came from a programming language called C++. Although C++ is a powerful language, it was felt to be too complex in its syntax, and inadequate for all of Java's requirements. Java built on, and improved the ideas of C++, to provide a programming language that was powerful and simple to use. 

Reliability: Java needed to reduce the likelihood of fatal errors from programmer mistakes. With this in mind, was introduced. Once data and its manipulation were packaged together in one place, it increased Java’s robustness. 

Secure: As Java was originally targeting mobile devices that would be exchanging data over networks, it was built to include a high level of security. Java is probably the most secure programming language to date.

Platform Independent: Programs needed to work regardless of the machine they were being executed on. Java was written to be a portable language that doesn't care about the operating system or the hardware of the computer. 

The team at Sun Microsystems were successful in combining these key principles, and Java's popularity can be traced to it being a robust, secure, easy to use, and portable language.

Java Technology Works

        Java is a high-level programming language and powerful software platform. On full implementation of the Java platform gives you the following features,
JDK Tools: The JDK tools provide compiling, Interpreter, running, monitoring, debugging, and documenting your applications.  The main tools used are the Javac compiler, the java launcher, and the javadoc documentation tool. 

Application Programming Interface: The API provides the core functionality of the Java programming language. It gives a wide collection of useful classes, which is further used in your own applications. It provides basic objects and interface to networking and security, to XML generation and database access, and much more.  

Deployment Technologies: The JDK software provides two type of deployment technology such as the Java Web Start software and Java Plug-In software for deploying your applications to end users.  

Graphical User Interface Tool kits: The Swing and Java 2D tool kits provide us the feature of  Graphical User Interfaces 

Integrated Libraries: Integrated with various libraries such as the Java IDL API, JDBC API, Java Naming and Directory Interface TM API, Java RMI, and Java Remote Method Invocation over Internet Inter-ORB Protocol Technology enable database to access and changes of remote objects.

The advantages of Java are as follows:

      


Java is simple, easy to design, easy to write, and therefore easy to compile, debug, and learn than any other programming languages.

Java is object-oriented, that is used to build modular programs and reusable code in other application.

Java is platform-independent and flexible in nature. The most significant feature of Java is to run a program easily from one computer system to another. 

Java works on distributed environment. It is designed to work on distributed computing, any network programs in Java is same as sending and receiving data to and from a file.

Java is secure. The Java language, compiler, interpreter and runtime environment are securable.
Java is robust. Robust means reliability. Java emphases on checking for possible errors, as Java compilers are able to detect many error problems in program during the execution of respective program code.

Java supports multithreaded. Multithreaded is the path of execution for a program to perform several tasks simultaneously within a program. The  java come with the concept of Multithreaded Program. In other languages, operating system-specific procedures have to be called in order to work on multithreading.
       




No comments:

Post a Comment