Menu
Java Tutorial in PDF - Learn Java in simple and easy steps starting from basic to advanced concepts with examples including Java Syntax Object Oriented Language, Methods, Overriding, Inheritance, Polymorphism, Interfaces, Packages, Collections, Networking, Multithreading, Generics, Multimedia, Serialization, GUI. The cookie settings on this website are set to 'allow cookies' to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click 'Accept' below then you are consenting to this.
Not to be confused with. Java: , (now owned by ) First appeared May 23, 1995; 23 years ago ( 1995-05-23),.java, Website Major Compilers: (javac, sjavac), (GCJ), Eclipse Compiler for Java (ECJ) Virtual machines: OpenJDK JRE, Gluon VM, JIT compilers:, Influenced by, Influenced,. at Wikibooks Java is a general-purpose that is, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers ' (WORA), meaning that Java code can run on all platforms that support Java without the need for recompilation. Java applications are typically compiled to that can run on any (JVM) regardless of. As of 2016, Java is one of the most, particularly for client-server web applications, with a reported 9 million developers. Java was originally developed by at (which has since been ) and released in 1995 as a core component of Sun Microsystems'.
The language derives much of its original features from, with a similar to and, but it has fewer facilities than either of them. The original and Java, virtual machines, and were originally released by Sun under proprietary licenses. As of May 2007, in compliance with the specifications of the, Sun most of its Java technologies under the. Others have also developed alternative implementations of these Sun technologies, such as the (bytecode compiler), (standard libraries), and -Web (browser plugin for applets). The latest version is, released on September 25, 2018, which follows after only six months, being in line with the new release schedule. Java 8 is still supported but there will be no more security updates for Java 9.
Versions earlier than Java 8 are supported by companies on a commercial basis; e.g. By Oracle back to Java 6 as of October 2017 (while they still 'highly recommend that you uninstall' pre-Java 8 from at least Windows computers). The graph from 2002 to 2018.
Over the course of a decade, Java (blue) and C (black) competed for the top position., Mike Sheridan, and 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 after an tree that stood outside Gosling's office.
Later the project went by the name Green and was finally renamed Java, from. Gosling designed Java with a C/C-style syntax that system and application programmers would find familiar. Released the first public implementation as Java 1.0 in 1996. It promised 'Write Once, Run Anywhere' (WORA), providing no-cost run-times on popular. Fairly secure and featuring configurable security, it allowed network- and file-access restrictions. Major soon incorporated the ability to run within web pages, and Java quickly became popular.
The Java 1.0 compiler was re-written by to comply strictly with the Java 1.0 language specification. 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. J2EE included technologies and APIs for enterprise applications typically run in server environments, while J2ME featured APIs optimized for mobile applications. The desktop version was renamed J2SE.
In 2006, for marketing purposes, Sun renamed new J2 versions as, and, respectively. In 1997, Sun Microsystems approached the standards body and later the to formalize Java, but it soon withdrew from the process. Java remains a, controlled through the.
At one time, Sun made most of its Java implementations available without charge, despite their status. Sun generated revenue from Java through the selling of licenses for specialized products such as the Java Enterprise System. On November 13, 2006, Sun released much of its Java virtual machine (JVM) as, (FOSS), under the terms of the (GPL). On May 8, 2007, Sun finished the process, making all of its JVM's core code available under /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 regard to Java was as an 'evangelist'. Following 's acquisition of Sun Micro-systems in 2009–10, 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 prevent Oracle from filing a lawsuit against Google shortly after that for using Java inside the Android SDK (see Google section below). Java software runs on everything from laptops to, to scientific. On April 2, 2010, James Gosling resigned from Oracle. In January 2016, Oracle announced that Java run-time environments based on JDK 9 will discontinue the browser plugin. Principles There were five primary goals in the creation of the Java language:.
It must be 'simple, object-oriented, and familiar'. It must be 'robust and secure'.
It must be 'architecture-neutral and portable'. It must execute with 'high performance'. It must be 'interpreted, threaded, and dynamic'.
Versions. Main article: As of 20 March 2018, both Java 8 and 11 are officially supported. Major release versions of Java, along with their release dates:. JDK 1.0 (January 23, 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). Java SE 9 (September 21, 2017). Java SE 10 (March 20, 2018). Java SE 11 (September 25, 2018) Editions. Sun has defined and supports four editions of Java targeting different application environments and segmented many of its so that they belong to one of the platforms.
The platforms are:. for smart-cards. (Java ME) – targeting environments with limited resources. (Java SE) – targeting workstation environments. (Java EE) – targeting large distributed enterprise or Internet environments.
The in the Java APIs are organized into separate groups called. Each package contains a set of related, classes,. Refer to the separate platforms for a description of the packages available. – Sun also provided an edition called that has been superseded by later, standards-based Java ME configuration-profile pairings. Execution System Java JVM and Bytecode. Main articles: and One design goal of Java is portability, which means that programs written for the Java platform must run similarly on any combination of hardware and operating system with adequate run time support.
This is achieved by compiling the Java language code to an intermediate representation called, instead of directly to architecture-specific. Java bytecode instructions are analogous to machine code, but they are intended to be executed by a (VM) written specifically for the host hardware. Commonly use a (JRE) installed on their own machine for standalone Java applications, or in a web browser for Java. Standard libraries provide a generic way to access host-specific features such as graphics,. The use of universal bytecode makes porting simple. However, the overhead of interpreting bytecode into machine instructions made interpreted programs almost always run more slowly than native.
(JIT) compilers that compile byte-codes to machine code during runtime were introduced from an early stage. Java itself is platform-independent and is adapted to the particular platform it is to run on by a for it, which translates the into the platform's machine language. Performance. Main article: Programs written in Java have a reputation for being slower and requiring more memory than those written in C. However, Java programs' execution speed improved significantly with the introduction of in 1997/1998 for, the addition of language features supporting better code analysis (such as inner classes, the StringBuilder class, optional assertions, etc.), and optimizations in the Java virtual machine, such as becoming the default for Sun's JVM in 2000.
With Java 1.5, the performance was improved with the addition of the java.util.concurrent package, including implementations of the and other multi-core collections, and it was improved further with Java 1.6. Non-JVM Some platforms offer direct hardware support for Java; there are micro controllers that can run Java bytecode in hardware instead of a software Java virtual machine, and some based processors could have hardware support for executing Java bytecode through their option, though support has mostly been dropped in current implementations of ARM. Automatic memory management Java uses an to manage memory in the. The programmer determines when objects are created, and the Java runtime 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 deallocated from the. In the latter case, the responsibility of managing memory resides with the programmer. If the program does not deallocate an object, a occurs.
If the program attempts to access or deallocate memory that has already been deallocated, the result is undefined and difficult to predict, and the program is likely to become unstable 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, i.e., 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/C style, where object addresses can be arithmetically manipulated (e.g. By adding or substracting an offset). This allows the garbage collector to relocate referenced objects and ensures type safety and security. As in C and some other object-oriented languages, variables of Java's are either stored directly in fields (for objects) or on the (for methods) rather than on the heap, as is commonly true for non-primitive data types (but see ).
This was a conscious decision by Java's designers for performance reasons. Java contains multiple types of garbage collectors. By default, HotSpot uses the.
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 (G1). Having solved the memory management problem does not relieve the programmer of the burden of handling properly other kind of ressources, like network or database connections, file handles, etc., especially in the presence of exceptions. Paradoxically, the presence of a garbage collector has faded the necessity of having an explicit destructor method in the classes, thus rendering the management of these other ressources more difficult! Dependency graph of the Java Core classes (created with jdeps and ). The syntax of Java is largely influenced.
Unlike C, which combines the syntax for structured, generic, and object-oriented programming, Java was built almost exclusively as an object-oriented language. All code is written inside classes, and every data item is an object, with the exception of the primitive data types, ( i.e. Integers, floating-point numbers, and characters), which are not objects for performance reasons. Java reuses some popular aspects of C (such as the printf method). Unlike C, Java does not support or for classes, though multiple inheritance is supported for.
Java uses comments similar to those of C. There are three different styles of comments: a single line style marked with two slashes ( //), a multiple line style opened with /.
and closed with./, and the commenting style opened with /. and closed with./. The Javadoc style of commenting allows the user to run the Javadoc executable to create documentation for the program and can be read by some (IDEs) such as to allow developers to access documentation within the IDE. 'Hello world' example The traditional can be written in Java as. Main article: technology provides Web developers with a simple, consistent mechanism for extending the functionality of a Web server and for accessing existing business systems. Servlets are Java EE components that generate responses (typically pages) to requests (typically requests) from. The Java servlet API has to some extent been superseded by two standard Java technologies for web services:.
the (JAX-RS 2.0) useful for AJAX, JSON and REST services, and. the (JAX-WS) useful for. JavaServer Pages. Main article: In 2004, were added to the Java language, as part of J2SE 5.0. Prior to the introduction of generics, each variable declaration had to be of a specific type. For container classes, for example, this is a problem because there is no easy way to create a container that accepts only specific types of objects. Either the container operates on all subtypes of a class or interface, usually Object, or a different container class has to be created for each contained class.
Generics allow compile-time type checking without having to create many container classes, each containing almost identical code. In addition to enabling more efficient code, certain runtime exceptions are prevented from occurring, by issuing compile-time errors. If Java prevented all runtime type errors ( ClassCastException's) from occurring, it would be. In 2016, the type system of Java was proven. Criticism.
Main article: The is the, developed to support application development in Java. It is controlled by in cooperation with others through the program. Companies or individuals participating in this process can influence the design and development of the APIs. This process has been a subject of controversy. The class library contains features such as:.
The core libraries, which include:. IO/NIO. Networking. Scripting/Compiler. (Lambda, Streaming). that implement such as, and, or.
Processing (Parsing, Transforming, Validating) libraries. libraries. The integration libraries, which allow the application writer to communicate with external systems. See also: is the current owner of the official implementation of the Java SE platform, following their acquisition of on January 27, 2010.
This implementation is based on the original implementation of Java by Sun. The Oracle implementation is available for (still works for XP, while only later versions are currently officially supported),. Because Java lacks any formal standardization recognized by, ISO/IEC, ANSI, or other third-party standards organization, the Oracle implementation is the. The Oracle implementation is packaged into two different distributions: The Java Runtime Environment (JRE) which contains the parts of the Java SE platform required to run Java programs and is intended for end users, and the (JDK), which is intended for software developers and includes development tools such as the, and a. Is another notable Java SE implementation that is licensed under the GNU GPL. The implementation started when Sun began releasing the Java source code under the GPL.
As of Java SE 7, OpenJDK is the official Java reference implementation. The goal of Java is to make all implementations of Java compatible.
Historically, Sun's trademark license for usage of the Java brand insists that all implementations be 'compatible'. This resulted in a legal dispute with after Sun claimed that the Microsoft implementation did not support or and had added platform-specific features of their own. Sun sued in 1997, and, in 2001, won a settlement of US$20 million, as well as a court order enforcing the terms of the license from Sun.
As a result, Microsoft no longer ships Java with. Platform-independent Java is essential to, and an even more rigorous validation is required to certify an implementation. This environment enables portable server-side applications. Use outside the Java platform The Java programming language requires the presence of a software platform in order for compiled programs to be executed. Oracle supplies the for use with Java. The is an alternative software platform, used primarily for developing with its own GUI system. The IDE platform supports Java, but provides its own GUI system Android.
The operating system makes extensive use of Java-related technology. The Java language is a key pillar in, an. Although Android, built on the, is written largely in C, the uses the Java language as the basis for Android applications.
The bytecode language supported by the Android SDK is incompatible with Java bytecode and runs on its own virtual machine, optimized for low-memory devices such as. Depending on the Android version, the bytecode is either interpreted by the or compiled into native code by the. Android does not provide the full Java SE standard library, although the Android SDK does include an independent implementation of a large subset of it. It supports Java 6 and some Java 7 features, offering an implementation compatible with the standard library. Controversy.
See also: The use of Java-related technology in Android led to a legal dispute between Oracle and Google. On May 7, 2012, a San Francisco jury found that if APIs could be copyrighted, then Google had infringed Oracle's copyrights by the use of Java in Android devices. District Judge ruled on May 31, 2012, that APIs cannot be copyrighted, but this was reversed by the United States Court of Appeals for the Federal Circuit in May 2014. On May 26, 2016, the district court decided in favor of Google, ruling the copyright infringement of the Java API in Android constitutes fair use. See also.
Job Search Java Persistence API is a collection of classes and methods to persistently store the vast amounts of data into a database. This tutorial provides you the basic understanding of Persistence (storing the copy of database object into temporary memory), and we will learn the understanding of JAVA Persistence API (JPA).
Audience This tutorial is designed for the readers pursuing Java programming with Database, using Persistence API and for all the enthusiastic readers. Prerequisites This tutorial is designed for absolute beginners. Assuming you are aware of Java programming with JDK1.6 or later version and JDBC concepts in java.