Introduction

Hello world program line by line | Java tutorials for students and beginners
JAVA -> INTRODUCTION


What is java ?

Java is a programming language originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core 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. Java applications are typically compiled to bytecode (class file) that can run on any Java virtual machine (JVM) regardless of computer architecture. Java is a general-purpose, concurrent, class-based, object-oriented language that is 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 is as of 2012 one of the most popular programming languages in use, particularly for client-server web applications, with a reported 10 million users. The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1991 and first released in 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun relicensed most of its Java technologies under the GNU General Public License. Others have also developed alternative implementations of these Sun technologies, such as the GNU Compiler for Java and GNU Class path.


why we use java


Java is a programming language and computing platform first released by Sun Microsystems in 1995. It is the underlying technology that powers state-of-the-art programs including utilities, games, and business applications. Java runs on more than 850 million personal computers worldwide, and on billions of devices worldwide, including mobile and TV devices.

Why do I need Java?

There are lots of applications and websites that won't work unless you have Java installed, and more are created every day. Java is fast, secure, and reliable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!


Usage


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 enable 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 an 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.


History of java




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. 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 (see Google section below). Java software runs on 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.   

Platform



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 Java bytecode, instead of directly to platform-specific machine code. Java byte code instructions are analogous to machine code, but they are intended to be interpreted by a virtual machine (VM) written specifically for the host hardware. End-users commonly use a Java Runtime Environment (JRE) installed on their own machine for standalone Java applications, or in a Web browser for Java applets. Standardized libraries provide a generic way to access host-specific features such as graphics, threading, 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 executable would. Just-in-Time (JIT) compilers were introduced from an early stage that compile byte codes to machine code during runtime.

   Java editions


       There are 3 editions for java:-

Java Platform, Standard Edition


Java Platform, Standard Edition or Java SE is a widely used platform for programming in the Java language. It is the Java Platform used to deploy portable applications for general use. In practical terms, Java SE consists of a virtual machine, which must be used to run Java programs, together with a set of libraries (or "packages") needed to allow the use of file systems, networks, graphical interfaces, and so on, from within those programs.

Java Platform, Enterprise Edition


Java Platform, Enterprise Edition or Java EE is Oracle's enterprise Java computing platform. The platform provides an API and runtime environment for developing and running enterprise software, including network and web services, and other large-scale, multi-tiered, scalable, reliable, and secure network applications. Java EE extends the Java Platform, Standard Edition (Java SE/J2SE),[1] providing an API for object-relational mapping, distributed and multi-tier architectures, and web services. The platform incorporates a design based largely on modular components running on an application server. Software for Java EE is primarily developed in the Java programming language and uses XML for configuration.

Java Platform, Micro Edition


Java Platform, Micro Edition, or Java ME, is a Java platform designed for embedded systems (mobile devices are one kind of such systems). Target devices range from industrial controls to mobile phones (especially feature phones) and set-top boxes. Java ME was formerly known as Java 2 Platform, Micro Edition (J2ME). Java ME was designed by Sun Microsystems, acquired by Oracle Corporation in 2010; the platform replaced a similar technology, PersonalJava. Originally developed under the Java Community Process as JSR 68, the different flavors of Java ME have evolved in separate JSRs. Sun provides a reference implementation of the specification, but has tended not to provide free binary implementations of its Java ME runtime environment for mobile devices, rather relying on third parties to provide their own. As of 22 December 2006, the Java ME source code is licensed under the GNU General Public License, and is released under the project name phoneME. As of 2008, all Java ME platforms are currently restricted to JRE 1.3 features and use that version of the class file format (internally known as version 47.0). Should Oracle ever declare a new round of Java ME configuration versions that support the later class file formats and language features, such as those corresponding to JRE 1.5 or 1.6 (notably, generics), it will entail extra work on the part of all platform vendors to update their JREs. Java ME devices implement a profile. The most common of these are the Mobile Information Device Profile aimed at mobile devices, such as cell phones, and the Personal Profile aimed at consumer products and embedded devices like set-top boxes and PDAs. Profiles are subsets of configurations, of which there are currently two: the Connected Limited Device Configuration (CLDC) and the Connected Device Configuration (CDC).[1] There are more than 2.1 billion Java ME enabled mobile phones and PDAs.[2] Although it's not used on some of today's newest mobile platforms (e.g. iPhone, Windows Phone, BlackBerry 10, Android), it continues to be very popular in sub $200 devices such as Nokia's Series 40. It is also used on new Bada operating system and on Symbian OS along with native software. Also, there are implementations for Windows CE, Windows Mobile, Maemo, MeeGo and Android available for separate download.

 

Configure Java environment on Windows


After installing

Java Development Kit on Windows, you may still need to do some configuration to get Java ready for compiling and executing Java programs. The following instruction will guide you through the process of setting up JDK for software development.
JDK is typically installed under C:\Program Files directory. For Java 6 Update 10, its installation folder will be C:\Program Files\Java\jdk1.6.0_10. Perform the following steps to make Java tools accessible.

Click Start > Control Panel > System icon to open System Properties dialog box.


Click Advanced > Environment Variables.


Click New button in System variables panel and create JAVA_HOME and CLASSPATH variables with values as shown:

While at it, you may also want to set up and configure for Apache Ant, a tool widely used in building and executing Java applications. You may need to move and/or rename Ant's installation folder.

Edit the Path variable to make the Java compiler and associated tools available by appending to its existing value the string
";%JAVA_HOME%\bin;% ANT_HOME%\bin;".


You can verify the availability of Java compiler by executing the following command in the command window:


 



·         Write a sample program for console application



Hello world program line by line

Summary

In this tutorial we will discuss Hello world program line by line and familiarize reader with the very basic principles of Java.

Code analysis

Let's recall source code for the Hello world program first:

HelloWorld.java
public class HelloWorld {

/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Hello World! I am new to Java.");
}

}




First of all, Java is an object-oriented programming language. Thus, Java program necessarily consists of classes. There are no global variables and functions, as you may see in C++. We called the class HelloWorld:

public class HelloWorld {

}


Draw attention to the fact, that filename of the file is <class name>.java. It is obligatory in Java.


Entry point


Each application in Java has an entry point to start from. It is a public static method called main. Arguments to application are passed through args parameter.

public static void main(String[] args) {

}


Print command


System.out.println("Hello World! I am new to Java.");

The command above prints "Hello World! I am new to Java." to the console. We won't expect this line in depth here. At present just memorize it as a tool to output something to the console.

Comments


Above the main method declaration you see comments block:

/**
* @param args
*/

It is special comments, called Javadoc. Using this system, one may automatically generate documentation for properly commented source.

Build and run


Now you know all about Hello world program. In previous article we built and ran it with the click in Eclipse, but it is also useful to know, how to build applications manually.


Building

Enter the directory with your source file and run the following command:

javac HelloWorld.java
After it is executed you will see a new file HelloWorld.class. This file is a compiled HelloWorld class.



Running


Now you can run it using following command:
java HelloWorld
If you done everything right, "Hello World! I am new to Java." should appear in the console:






·         Getting Started with Eclipse


Beginners Eclipse Tutorial



In this tutorial I will show you how to use the Eclipse IDE for the first time.


Firstly, download the latest version of Eclipse.


Here is a direct link to the download:


Once its downloaded & installed, double click the Eclipse icon to start.

http://www.javaprogrammingforums.com/images/eclipse_tutorial/1.jpg

Because this is your first time running Eclipse, it will take a while to load as it sets up the environment.

http://www.javaprogrammingforums.com/images/eclipse_tutorial/2.jpg

Once Eclipse is fully loaded you will see the Welcome Screen. You can close this straight away..

http://www.javaprogrammingforums.com/images/eclipse_tutorial/3.jpg

OK now lets start our first application.

Click File > New > Java Project

http://www.javaprogrammingforums.com/images/eclipse_tutorial/4.jpg

The 'Create a Java Project' box will popup.

Give your Project a name. In this case I have named it 'EclipseTutorial'

http://www.javaprogrammingforums.com/images/eclipse_tutorial/5.jpg

Click FINISH.

You have now setup your first project which will appear in the Package Explorer window.

http://www.javaprogrammingforums.com/images/eclipse_tutorial/6.jpg

Before we can begin to write any code, we must first add a Package which will contain all our project files.

Make sure your new project is highlighted and click the 'New Java Package' icon.

http://www.javaprogrammingforums.com/images/eclipse_tutorial/7.jpg

Give your package a name relevant to your project.

http://www.javaprogrammingforums.com/images/eclipse_tutorial/8.jpg

Click FINISH

Now your Package has been created we need to add a Class file. Make sure the Package is highlighted by clicking it once and then click the 'New Java Class' icon.

http://www.javaprogrammingforums.com/images/eclipse_tutorial/9.jpg

The Create a New Java Class box will popup.

Give your Class a name and tick the public static void main(String[] args) box.

http://www.javaprogrammingforums.com/images/eclipse_tutorial/10.jpg

Your Class will now appear in the Workspace and you are ready to start writing code!

http://www.javaprogrammingforums.com/images/eclipse_tutorial/11.jpg

Here I have wrote a simple Hello World application which will print the words into the console.

http://www.javaprogrammingforums.com/images/eclipse_tutorial/12.jpg

To Run your Java project. Right click the 'TutorialClass.java' file in the Package Explorer window, then click Run As > Java Application

http://www.javaprogrammingforums.com/images/eclipse_tutorial/13.jpg

The output will now be displayed in the console.

http://www.javaprogrammingforums.com/images/eclipse_tutorial/14.jpg


Congratulations! You have just wrote your first Java application in Eclipse!!





Once you are familiar with Eclipse, you will find this next thread very helpful:




·         Uninstall all-then reinstall the newest Java


Uninstall all, but the newest Java version


If you are getting Security Alert Certificate Errors or Generic Exception Errors when opening a document in Blackboard CE8 or if you are experiencing problems with the Java based chat/whiteboard or HTML editing tools in Blackboard CE8, try uninstalling all previous versions of Java and then reinstall the latest version. Even if you have the current version installed, any older versions that exist on your machine may cause problems with the Java functionality until they are uninstalled. NOTE: The HTML Creator does not work with Firefox 4.0.1 on the PC or any versions of Firefox on the Mac.
o    Windows XP
Sometimes having multiple versions of Java installed on a machine causes problems. Thus, if you are having problems, we recommend that you uninstall ALL versions of Java and then reinstall the latest version of Java available from the Web.
o    Windows VISTA / 7
The version of Java that comes with the Vista/7 operating system is problematic for Blackboard CE8. Thus, if you are using Vista, we recommend that you uninstall ALL versions of Java and then reinstall the latest version of Java available from the Web.
o    Macintosh
You should not experience Java problems on the Mac. The Macintosh operating system has Java built into it as part of its Operating System. If you are experiencing Java issues, try refreshing your operating system to download the latest version.

  Uninstall all-then reinstall the newest Java for Windows XP

o    Open My Computer
o    On the left, click on Control Panel
o    Select the Add or Remove Programs option

o    Scroll down to the Java installations, press the Remove button on all Java applications and updates

o    Reboot your Computer
o    To Reinstall Java, go to http://www.java.com/en/ Leaving this Site
o    Click on the FREE JAVA DOWNLOAD option
o    Follow the Java instructions for installation

 

  Uninstall-then reinstall the newest Java version for Windows Vista

o    Open Computer
o    On the left, click on Control Panel
o    Select the Uninstall a program option
o    Scroll down to the Java installations
o    Click on each Java Update, press the Uninstall button at the top for all Java applications and updates


o    Reboot your Computer

o    To Reinstall Java, go to http://www.java.com/en/ Leaving this Site
o    Click on the FREE JAVA DOWNLOAD option
o    Follow the Java instructions for installation

 


Enable Java

If you are getting generic exception errors when opening a document in Blackboard CE8 or if you're not able to load Blackboard CE8 tools such as the HTML editor or the Chat/Whiteboard, it is possible that Java has been disabled on your machine. Java is required for Blackboard CE8 and must be enabled. Below are instructions on how to enable Java in Internet Explorer, Firefox, and Safari.

  Internet Explorer 7 & 8: Enable Java

NOTE: Instructions for Internet Explorer 5 & 6 are below
o    From Internet Explorer 7 or 8, select the Tools menu
o    Then Internet Options
o    Select the Programs tab
o    Click the Manage add-ons button
o    Scroll down to the Java Plug-in
o    Select Enable on all Java Plug-ins available
o    Close and Restart your browser

  Internet Explorer 5 & 6: Enable Java

o    From the Tools menu, choose Internet Options...
o    Click the Security tab
o    Click Custom Level... 
o    Scroll down to the Java VM / Java permissions section
o    Click Low, Medium or High Safety
o    Close and Restart your browser

  Firefox: Enable Java

o    From Firefox, select the Tools menu
o    Then Options
o    Select Content
o    Then check Enable Java
o    Press OK

  Safari: Enable Java

o    From Safari on a Mac, select the Safari menu
o    Then Preferences...
 

o    From Safari on a PC, select the Edit menu
o    Then Preferences...
o    Select Security
o    Then check Enable Java
 
o    Close the window



 Download JDK & JRE
Click here to download java platforms


Click Here to download java development toolkit
Click Here to download java runtime envirnoment