Introduction to Java

An Overview of Java
What is Java
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" (WORA), meaning that code that runs on one platform does not need to be recompiled to run on another. Java applications are typically compiled to bytecode (class file) that can run on any Java virtual machine (JVM) regardless of computer architecture. Java is, as of 2014, one of the most popular programming languages in use, particularly for client-server web applications, with a reported 9 million developers.
The major characteristics of Java are:
* The programs you create are portable in a network. Your source program is compiled into what Java calls bytecode, which can be run anywhere in a network on a server or client that has a Java virtual machine. The Java virtual machine interprets the bytecode 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 robust, 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 can not 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 object can take advantage of being part of a class 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 method can be thought of as one of the object's capabilities or behaviors.
* In addition to being executed at the client rather than the server, a Java applet has other characteristics designed to make it run fast.
History:
James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. Java was originally designed for interactive television, but it was too advanced for the digital cable television industry at the time. The language was initially called Oak after an oak tree that stood outside Gosling's office; it went by the name Green later, and was later renamed Java, from Java coffee, said to be consumed in large quantities by the language's creators.[citation needed] Gosling aimed to implement a virtual machine and a language that had a familiar C/C++ style of notation.
Sun Microsystems released the first public implementation as Java 1.0 in 1995. It promised "Write Once, Run Anywhere" (WORA), providing no-cost run-times on popular platforms. Fairly secure and featuring configurable security, it allowed network- and file-access restrictions. Major web browsers soon incorporated the ability to run Java applets within web pages, and Java quickly became popular. With the advent of Java 2 (released initially as J2SE 1.2 in December 1998 – 1999), new versions had multiple configurations built for different types of platforms. For example, J2EE targeted enterprise applications and the greatly stripped-down version J2ME for mobile applications (Mobile Java). J2SE designated the Standard Edition. In 2006, for marketing purposes, Sun renamed new J2 versions as Java EE, Java ME, and Java SE, respectively.
In 1997, Sun Microsystems approached the ISO/IEC JTC1 standards body and later the Ecma International to formalize Java, but it soon withdrew from the process. Java remains a de facto standard, controlled through the Java Community Process. At one time, Sun made most of its Java implementations available without charge, despite their proprietary software status. Sun generated revenue from Java through the selling of licenses for specialized products such as the Java Enterprise System. Sun distinguishes between its Software Development Kit (SDK) and Runtime Environment (JRE) (a subset of the SDK); the primary distinction involves the JRE's lack of the compiler, utility programs, and header files.
On November 13, 2006, Sun released much of Java as free and open source software, (FOSS), under the terms of the GNU General Public License (GPL). On May 8, 2007, Sun finished the process, making all of Java's core code available under free software/open-source distribution terms, aside from a small portion of code to which Sun did not hold the copyright.
Sun's vice-president Rich Green said that Sun's ideal role with regards to Java was as an "evangelist." Following Oracle Corporation's acquisition of Sun Microsystems in 2009–2010, Oracle has described itself as the "steward of Java technology with a relentless commitment to fostering a community of participation and transparency". This did not hold Oracle, however, from filing a lawsuit against Google shortly after that for using Java inside the Android SDK . Java software runs on everything from laptops to data centers, game consoles to scientific supercomputers. There are 930 million Java Runtime Environment downloads each year and 3 billion mobile phones run Java. On April 2, 2010, James Gosling resigned from Oracle.
Versions
Major release versions of Java, along with their release dates: -
* JDK 1.0 (January 21, 1996)
* JDK 1.1 (February 19, 1997)
* J2SE 1.2 (December 8, 1998)
* J2SE 1.3 (May 8, 2000)
* J2SE 1.4 (February 6, 2002)
* J2SE 5.0 (September 30, 2004)
* Java SE 6 (December 11, 2006)
* Java SE 7 (July 28, 2011)
* Java SE 8 (March 18, 2014)
There were five primary goals in the creation of the Java language: -
1. It should use the object-oriented programming methodology.
2. It should allow the same program to be executed on multiple operating systems.
3. It should contain built-in support for using computer networks.
4. It should be designed to execute code from remote sources securely.
5. It should be easy to use by selecting what was considered the good parts of other object-oriented languages.
To achieve the goals of networking support and remote code execution, Java programmers sometimes find it necessary to use extensions such as CORBA, Internet Communications Engine, or OSGi.
Object orientation
The first characteristic, Object-oriented programming (OOP) is a programming language model organized around objects rather than "actions" and data rather than logic. Historically, a program has been viewed as a logical procedure that takes input data, processes it, and produces output data.
The first step in OOP is to identify all the objects the programmer wants to manipulate and how they relate to each other, an exercise often known as data modeling. Once an object has been identified, it is generalized as a class of objects which defines the kind of data it contains and any logic sequences that can manipulate it. Each distinct logic sequence is known as a method. Objects communicate with well-defined interfaces called messages.
The concepts and rules used in object-oriented programming provide these important benefits: -
1. The concept of a data class makes it possible to define subclasses of data objects that share some or all of the main class characteristics. Called inheritance, this property of OOP forces a more thorough data analysis, reduces development time, and ensures more accurate coding.
2. Since a class defines only the data it needs to be concerned with, when an instance of that class (an object) is run, the code will not be able to accidentally access other program data. This characteristic of data hiding provides greater system security and avoids unintended data corruption.
3. The definition of a class is reuseable not only by the program for which it is initially created but also by other object-oriented programs (and, for this reason, can be more easily distributed for use in networks).
4. The concept of data classes allows a programmer to create any new data type that is not already defined in the language itself.
The Java programming language is designed especially for use in distributed applications on corporate networks and the Internet.
Platform independence
The second characteristic, platform independence, means that programs written in the Java language must run similarly on diverse hardware. One should be able to write a program once and run it anywhere.
This is achieved by most Java compilers by compiling the Java language code "halfway" to bytecode (specifically Java bytecode)—simplified machine instructions specific to the Java platform. The code is then run on a virtual machine (VM), a program written in native code on the host hardware that interprets and executes generic Java bytecode. Further, standardized libraries are provided to allow access to features of the host machines (such as graphics, threading and networking) in unified ways. Note that, although there's an explicit compiling stage, at some point, the Java bytecode is interpreted or converted to native machine instructions by the JIT compiler.
Portability is a technically difficult goal to achieve, and Java's success at that goal has been mixed. Although it is indeed possible to write programs for the Java platform that behave consistently across many host platforms, the large number of available platforms with small errors or inconsistencies led some to parody Sun's "Write once, run anywhere" slogan as "Write once, debug everywhere".
Platform-independent Java is however very successful with server-side applications, such as Web services, servlets, and Enterprise JavaBeans, as well as with Embedded systems based on OSGi, using Embedded Java environments.
Automatic garbage collection
One idea behind Java's automatic memory management model is that programmers should be spared the burden of having to perform manual memory management. In some languages the programmer allocates memory to create any object stored on the heap and is responsible for later manually deallocating that memory to delete any such objects. If a programmer forgets to deallocate memory or writes code that fails to do so in a timely fashion, a memory leak can occur: the program will consume a potentially arbitrarily large amount of memory. In addition, if a region of memory is deallocated twice, the program can become unstable and may crash. Finally, in non garbage collected environments, there is a certain degree of overhead and complexity of user-code to track and finalize allocations.
In Java, this potential problem is avoided by automatic garbage collection. The programmer determines when objects are created, and the Java runtime is responsible for managing the object's lifecycle. The program or other objects can reference an object by holding a reference to it (which, from a low-level point of view, is its address on the heap). When no references to an object remain, the Java garbage collector automatically deletes the unreachable object, freeing memory and preventing a memory leak. Memory leaks may still occur if a programmer's code holds a reference to an object that is no longer needed—in other words, they can still occur but at higher conceptual levels.
The Internet and the Java's place in it
Technology continues to get smaller and faster, and we increasingly find new ways to integrate it into our lives. We've reached a point where intelligent devices and sensor networks can be put in place transparently to collect data without people even knowing it. As a result, a host of new benefits can be offered to consumers in terms of improved efficiency, convenience, and value. This level of integration and ubiquity of computing devices is called the Internet of Things (IoT). The flip side is an increased risk of loss in terms of privacy and security.
Java as a platform is a good starting point for the IoT in terms of its ubiquity (it runs on servers, desktops, laptops, and embedded devices of varying sizes), as well as its built-in security and encryption technology. Given that it makes it easier to do embedded development (you don't need to worry about porting your otherwise native code across platforms), Java allows you to focus on key application features. Two of these ought to be increased security and data privacy, especially as technology becomes more connected in our homes, cars, and ultimately, our lives.
JavaOne 2013 gave Java developers a non-stop exercise replete with education and entertainment, strategy, technical, and community keynotes book-ending the conference, technical sessions, hands-on labs, panel discussions, tutorials, demos, a rock concert, widespread networking, code challenges, and much more.
Java is the premier development platform in the world, here are some reminders:: -
* There are 9 million Java developers worldwide.
* It's the #1 choice for developers.
* It's the #1 development platform.
* 3 billion mobile phones run Java.
* 100 percent of Blu-ray disc players ship with Java.
* 97 percent of enterprise desktops run Java.
* 5 billion Java Cards are in use.
* 7 billion Java Cards have been sold.
* 89 percent of desktops run Java.
* 125 million TV devices run Java.
* Five of the top-five OEMs ship Java.
JavaOne 2013's content curriculum was organized along eight tracks, with a new track on Java security added to this year's offerings.
* Client and Embedded Development with JavaFX
* Core Java Platform
* Edge Computing with Java in Embedded, Smart Card, and IoT Applications
* Emerging Languages on the Java Virtual Machine
* Securing Java
* Java Development Tools and Techniques
* Java EE Web Profile and Platform Technologies
* Java Web Services and the Cloud

Applications and Applets
Applications are stand-alone programs that do not require the use of a browser. Java applications run by starting the Java interpreter from the command line and by specifying the file that contains the compiled application. Applications usually reside on the system on which they are deployed. Applications access resources on the system, and are restricted by the Java security model.
Running a program as a Java standalone application makes use of the Java runtime environment and the Java loader, which is usually called java on Unix or either java or wjava under Microsoft Windows. The Java loader loads the main .class file and all related classes from the .jar archive(s), which must be either in the same directory, in one of the directories listed in the CLASSPATH environment variable, or you must specify the path on the command line.
* Applications must have a main().
* Java applications are compiled using the javac command and run using the java command.
Applets
A Java applet is a small application written in Java and delivered to users in the form of bytecode. The user launches the Java applet from a web page and it is then executed within a Java Virtual Machine (JVM) in a process separate from the web browser itself. A Java applet can appear in a frame of the web page, a new application window, Sun's AppletViewer or a stand-alone tool for testing applets. Java applets were introduced in the first version of the Java language in 1995.Java applets can be written in any programming language that compiles to Java bytecode.
Java applets run at very fast speeds comparable to, but generally slower than, other compiled languages such as C++.
Applets are used to provide interactive features to web applications that cannot be provided by HTML alone. They can capture mouse input and also have controls like buttons or check boxes. In response to the user action an applet can change the provided graphic content. This makes applets well suitable for demonstration, visualization and teaching.
* Applets do not require a main(), but in general will have a paint().
* An Applet also requires an HTML file before it can be executed.
* Java Applets are also compiled using the javac command, but are are run either with a browser or with the appletviewer command.
An applet can be run either by loading the HTML page into your Java enabled web browser (e.g. Microsoft Internet Explorer, Netscape Navigator, Opera, etc.) or by using the AppletViewer program provided for several platforms by Sun Microsystems. Running as an applet in your browser is probably the easiest way to use the Java Programs
A disadvantage may be, that you cannot save, print or copy data to the clipboard, as long as you use the standard Java security settings of your browser. If you lower these restrictions for all Java programs, you should reset them before surfing into the unknowns of the web in order to avoid that someone malicious can read or write files on your computer system.
Byte Code - Not an executable code
Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode opcode is one byte in length, although some require parameters, resulting in some multi-byte instructions. Not all of the possible 256 opcodes are used. 51 are reserved for future use. Beyond that, Sun Microsystems, the original developer of the Java platform, had set aside three values to be permanently unimplemented.
Bytecode is the code generated after the Java programs are compiled. This is the intermediate representations of Java programs. Bytecode is NOT executable code like “.exe” but this is java propriety intermediate code. Bytecode is NOT machine understandable language.
Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time system (interpreter) which is called the Java Virtual Machine (JVM). This provides greater level of flexibility for the developers to implement the logic specific to JVM rather to any platform or device.
Bytecode generated after compiling in Mac, Windows, Linux or Unix will be same which makes Bytecode platform independent. So, Bytecode compiled in one platform can be executed into another platform.
Programming code that, once compiled, is run through a virtual machine instead of the computers processor. By using this approach, source code can be run on any platform once it has been compiled and run through the virtual machine.
Bytecode is the compiled format for Java programs. Once a Java program has been converted to bytecode, it can be transferred across a network and executed by Java Virtual Machine (JVM). Bytecode files generally have a .class extension.


Free Web Hosting