Introduction to Java
Table of Contents
1) History
Java is a programming language created by James Gosling from Sun Microsystems (Sun) in 1991. The first publicly available version of Java (Java 1.0) was released in 1995.
Sun Microsystems was acquired by the Oracle Corporation in 2010.
2) Java Platform Overview
Java technology is used to develop applications for a wide range of environments. In this section, get a high-level view of the Java platform and its components.
Java Language
Java is an object-oriented programming language.
Java is a Platform Independent i.e. Java source code files are compiled into a format called bytecode which can then be executed by a Java interpreter. Compiled Java code can run on most computers because Java interpreters and runtime environments, known as Java Virtual Machines (VMs), exist for most operating systems.
Java Compiler
When you program for the Java platform, you write source code in .java files and then compile them. The compiler checks your code against the language's syntax rules, then writes out bytecodes in .class files. Bytecodes are standard instructions targeted to run on a Java virtual machine (JVM).
JVM
At run time, the JVM reads and interprets .class files and executes the program's instructions on the native hardware platform for which the JVM was written. The JVM interprets the bytecodes just as a CPU would interpret assembly-language instructions. The difference is that the JVM is a piece of software written specifically for a particular platform. The JVM is the heart of the Java language's "write-once, run-anywhere" principle. Your code can run on any chipset for which a suitable JVM implementation is available. JVMs are available for major platforms like Linux and Windows, and subsets of the Java language have been implemented in JVMs for mobile phones and hobbyist chips.
Garbage Collector
Rather than forcing you to keep up with memory allocation (or use a third-party library to do this), the Java platform provides memory management out of the box. When your Java application creates an object instance at run time, the JVM automatically allocates memory space for that object from the heap, which is a pool of memory set aside for your program to use. The Java garbage collector runs in the background, keeping track of which objects the application no longer needs and reclaiming memory from them. This approach to memory handling is called implicit memory management because it doesn't require you to write any memory-handling code. Garbage collection is one of the essential features of Java platform performance.
Java Development Kit
When you download a Java Development Kit (JDK), you get in addition to the compiler and other tools a complete class library of prebuilt utilities that help you accomplish just about any task common to application development.
Java Runtime Environment
The Java Runtime Environment (JRE; also known as the Java runtime) includes the JVM, code libraries, and components that are necessary for running programs written in the Java language. It is available for multiple platforms.
3) Setting up Java Development Environment
In this section, you'll get instructions for downloading and installing JDK 6 and the current release of the Eclipse IDE, and for setting up your Eclipse development environment.
Installing JDK
Follow these steps to download and install JDK 6.
-
Download Java Platform (JDK) from Java SE Downloads.
-
When the download is complete, run the install program. And install JDK in your hard drive.
You now have a Java environment on your machine. Next, you will install the Eclipse IDE.
Install Eclipse
To download and install Eclipse, follow these steps:
-
Browse to Eclipse Download Directory.
-
Download Eclipse IDE for Java Developers.
-
Extract the contents of the .zip file to a location on your hard drive that you'll be able to remember easily.
Setting up Eclipse
The Eclipse IDE sits atop the JDK as a useful abstraction, but it still needs to access the JDK and its various tools. Before you can use Eclipse to write Java code, you have to tell it where the JDK is located.
To set up your Eclipse development environment:
-
Launch Eclipse by double-clicking on eclipse.exe (or the equivalent executable for your platform).
-
The Workspace Launcher will appear, allowing you to select a root folder for your Eclipse projects. Choose a folder you will easily remember, such as C:\home\workspace on Windows or ~/workspace on Linux.
-
Dismiss the Welcome to Eclipse screen.
-
Click Window > Preferences > Java > Installed JREs. Below figure shows the setup screen for the JRE:
-
Eclipse will point to an installed JRE. You need to make sure you use the one you downloaded with JDK 6. If Eclipse does not automatically detect the JDK you installed, click Add... and in the next dialog Standard VM, then click Next.
-
Specify the JDK's home directory (such as C:\home\jdk1.6.0_20 on Windows), then click Finish.
-
Confirm that the JDK you want to use is selected and click OK.
Eclipse is now set up and ready for you to create projects and compile and run Java code. The next section will familiarize you with Eclipse.
No comments:
Post a Comment