Thursday, July 23, 2009

Automatic memory management

Java uses an automatic garbage collector to manage memory in the object lifecycle. 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 unreachable object becomes eligible to be freed automatically by the garbage collector. Something similar to a memory leak 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 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 stack, or explicitly allocated and deallocated from the heap. Either way the responsibility of managing memory resides with the programmer. If the program does not deallocate an object, a memory leak 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 and/or crash. This can be partially remedied by the use of smart pointers, but these add overhead and complexity.

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. Where performance or response time is important, explicit memory management and object pools are often used.
Java does not support C/C++ style pointer arithmetic, 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 C++ and some other object-oriented languages, variables of Java's primitive types are not objects. Values of primitive types are either stored directly in fields (for objects) or on the stack (for methods) rather than on the heap, as commonly true for objects (but see Escape analysis). 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, autoboxing enables programmers to proceed as if primitive types are instances of their wrapper classes

Read More......

Thursday, July 9, 2009

What's New
The Java Tutorials are continuously updated to keep up with changes to the Java Platform and to incorporate feedback from our readers. Some recent updates include:
An entirely reworked File I/O lesson, featuring NIO.2. This functionality is part of JDK7, which is available now through the Open JDK project on java.net.
A new specialized trail covering Sockets Direct Protocol, also new in JDK7.
A new facility for gathering feedback about the tutorial. At the bottom of each tutorial page, under the "Discuss" heading, you can leave a publicly viewable, blog-style comment. Let us know what you think about the inclusion of this JS-Kit mechanism.

Trails Covering the Basics
These trails are available in book form as The Java Tutorial, Fourth Edition. To buy this book, refer to the box to the right.
Getting Started — An introduction to Java technology and lessons on installing Java development software and using it to create a simple program.
Learning the Java Language — Lessons describing the essential concepts and features of the Java Programming Language.
Essential Java Classes — Lessons on exceptions, basic input/output, concurrency, regular expressions, and the platform environment.
Collections — Lessons on using and extending the Java Collections Framework.
Swing — An introduction to the Swing GUI toolkit, with an overview of features and a visual catalog of components. See below for a more comprehensive tutorial on Swing.
Deployment — How to package applications and applets using JAR files, and deploy them using Java Web Start and Java Plug-in.
Preparation for Java Programming Language Certification — List of available training and tutorial resources.
Creating Graphical User Interfaces
This trail is available in book form as The JFC Swing Tutorial. To buy this book, refer to the box to the right.


--------------------------------------------------------------------------------
The Swing examples are bundled to be open and run in NetBeans IDE. (Of course you can import the source files into any IDE that you wish.) For more information, see Running Tutorial Examples in NetBeans IDE. Each Swing lesson has a separate Examples Index — for a sample, check out the Using Swing Components Examples Index.
--------------------------------------------------------------------------------

Creating a GUI with Swing — A comprehensive introduction to GUI creation on the Java platform.
Specialized Trails and Lessons
These trails and lessons are only available as web pages.

Custom Networking — An introduction to the Java platform's powerful networking features.
The Extension Mechanism — How to make custom APIs available to all applications running on the Java platform.
Full-Screen Exclusive Mode API — How to write applications that more fully utilize the user's graphics hardware.
Generics — An enhancement to the type system that supports operations on objects of various types while providing compile-time type safety. Note that this lesson is for advanced users. The Java Language trail contains a Generics lesson that is suitable for beginners.
Internationalization — An introduction to designing software so that it can be easily be adapted (localized) to various languages and regions.
JavaBeans — The Java platform's component technology.
JDBC Database Access — Introduces an API for connectivity between the Java applications and a wide range of databases and a data sources.
JMX— Java Management Extensions provides a standard way of managing resources such as applications, devices, and services.
JNDI— Java Naming and Directory Interface enables accessing the Naming and Directory Service such as DNS and LDAP.
RMI — The Remote Method Invocation API allows an object to invoke methods of an object running on another Java Virtual Machine.
Reflection — An API that represents ("reflects") the classes, interfaces, and objects in the current Java Virtual Machine.
Security — Java platform features that help protect applications from malicious software.
Sound — An API for playing sound data from applications.
2D Graphics — How to display and print 2D graphics in applications.
Sockets Direct Protocol — How to enable the Sockets Direct Protocol to take advantage of InfiniBand.



Read More......