Java programs which do run within a browser which is Java-compatible are known as applets.
Here we have discussed about the components of a stand-alone Java program, that is, a
program written in the Java language which can run independently of any browser.
A D V E R T I S E M E N T
Stand-alone programs in Java are also known as Java applications.
The following application "DateApp" displays the current time and date.
import java.util.Date;
class DateApp
{
public static void main (String args[])
{
Date today = new Date();
System.out.println(today);
}
}
Import statement
As we can see the first line in the program imports the Date class from the package called
"java.util". By importing we can make that class available to the file into which it has been imported.
A "java.util" package is a collection of classes that do provide miscellaneous functionality.
The "Date" class from the java.util package allows you to manage and also manipulate calendar
dates in system independent way.
How to Define a Class
In Java language, the general form of class definition is as shown below
class name
{
. . .
}
The keyword class begins the class definition for a given classname here it is "name".
All variables and methods of the given class are held inside the curly brackets that
begins and ends the definition block of a class. In the class "DateApp" has no variables
and has only one method called main().
Method: main()
main() method is called the brain of the Java application.you need to specify the name
of the class which you want to run while running a Java application using the Java
interpreter. Interpreter will do invokes the main() method defined in the class.
The main() method will control the program flow, allocates all the resources which are
needed, and will run any of the methods that do provide the functionality to the
application.
Using Objects in the Programs
The first line in the method "main()", will declare, initialize and instantiate
an object called "today". The default constructor is used to initialize today,
that initializes the object new Date to contain the current time and date.
In the second line of the method "main()" uses dot operator to refer to the class's or
object's methods or variables. The above code illustrates the uses of
instance variables and methods and class methods and variables
How to Save, Compile and Run an Application
To create and edit Java program, you can make use of any editor or word processing program.
Java programs should be saved with the .java extension, so using any ASCII
editor, write the program exactly as it appears in this page and save the
program with the file name DateApp.java.
After creating your Java program, you should compile the program using the Java
compiler before running it
When a Java source file is compiled, the compiler creates a .class extension file
in the folder in which the source file is stored. The compiler will name the resulting
.class file after the class is defined in the source file. For example, when you
compile the "DateApp" class which you have created above, the compiler will name the
resulting class file "DateApp.class" after the class, with regardless of the name
of the source file. Even if you would save the DateApp class as Wow.java, the compiler
would still create a file called "DateApp.class".
After compilation, using the Java interpreter you can run the application . The program
must display the current time and date.
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Keywords: java system application server, free mobile java application, iden web java
application, java application loader, java system application server platform
edition, iden java application loader, video in a java application, free java
application for nokia 6125, types of java application, java technology
downloads application server