What is Java technology and why do we need it?
Java is a programming language and computing platform first released by Sun Microsystems in 1995. There are lots of applications and websites that will not 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!
Java is a programming language in the tradition of C and C++. As a result, if you have any experience with C or C++, you'll find yourself in familiar territory often as you learn the various features of Java.
However, Java differs from other programming languages in a couple of significant ways. The following sections describe the most important differences.
However, Java differs from other programming languages in a couple of significant ways. The following sections describe the most important differences.
Is Java free to download?
Yes, Java is free to download. Get the latest version at java.com.
Platform independence
One of the main reasons Java is so popular is its platform independence, which means that Java programs can be run on many different types of computers. A Java program runs on any computer with a Java Runtime Environment, also known as a JRE, installed. A JRE is available for almost every type of computer — PCs running Windows, Macintosh computers, Unix or Linux computers, huge mainframe computers, and even cell phones.
Object orientation
Java is inherently object-oriented, which means that Java programs are made up of programming elements called objects. Simply put, an object is a programming entity that represents either some real-world object or an abstract concept.
All objects have two basic characteristics:
- Objects have data, also known as state. For example, an object that represents a book has data such as the book's title, author, and publisher.
- Objects also have behavior, which means that they can perform certain tasks. In Java, these tasks are called methods. For example, an object that represents a car might have methods such as start, stop, drive, or crash. Some methods simply allow you to access the object's data. For example, a book object might have a getTitle method that tells you the book's title.
Classes are closely related to objects. A class is the program code you write to create objects. The class describes the data and methods that define the object's state and behavior. Then, when the program executes, classes are used to create objects.
For example, suppose you're writing a payroll program. This program needs objects to represent the company's employees. So, the program includes a class (probably named Employee) that defines the data and methods for each Employee object. Then, when your program runs, it uses this class to create an object for each of your company's employees.
Writing Common Java Statements
Java statements build programs. Every Java class must have a body, which is made up of one or more statements. You can write different kinds of statements, including declaration and expression.
The break statement
break;
The continue statement
continue;
The do statement
do
{statements...}
while (expression);
The for statement
for (init; test; count)
{statements...}
The enhanced for statement
for (type variable : array-or-
collection)
{statements...}
The if statement
if (expression)
{statements...}
else
{statements...}
The throw statement
throw (exception)
The switch statement
switch (expression)
{
case constant:
statements;
break;
default:
statements;
break;
}
The while statement
while (expression)
{statements...}
The try statement
try
{statements...}
catch (exception-class e)
{statements...}...
finally
{statements...}
try
{statements...}
finally
{statements...}
Java programming examples
Example 1: Display message on computer screen.
This is similar to hello world java program. Download java programming class file.
Output of program:
Example 2: Print integers
Output:

Example 3:
If else control instructions:
Output:

Example 4:
Command line arguments:
Output:
No comments:
Post a Comment