|
|
||
|
Home | Hindi | Kabir | Poetry | Workshop | BoloKids | Writers | Contribute | Search | Contact | Share This Page! Shop Online |
|||
|
Computing |
Java So if you are a keen
follower of this section of mine, u might now be well versatile with
Object Oriented Programming Concepts and Objects and Classes in Java.
This week is going to be more interactive for you. This is because you
are going to create your own JAVA application. Java programs fall
into two main groups: Applets and
Applications.
Applets, as you may have
experienced, are Java programs that are downloaded over the World Wide
Web and executed by a Web browser on the reader's machine. Applets
depend on a Java-capable browser in order to run (although they can also
be viewed using a tool called the applet viewer) Java applications are more
general programs written in the Java language. Java applications don't
require a browser to run, and in fact, Java can be used to create all
the kinds of applications that you would normally use a more
conventional programming language to create. HotJava itself is a Java
application.
A single Java program can be
an applet or an application or both, depending on how you write that
program and the capabilities that program uses. Throughout this article,
you'll be writing mostly applications; then you'll apply what you've
learned to write applets in the later articles. If you're eager to get
started with applets, be patient. Everything that you learn while you're
creating simple Java applications will apply to creating applets, and
it's easier to start with the basics before moving onto the hard stuff.
Creating a Java
Application Let's start by creating a
simple Java application. As with all programming
languages, your Java source files are created in a plain text editor, or
in an editor that can save files in plain ASCII without any formatting
characters. On Unix, emacs, pico, or vi will work; on Windows, Notepad
or DOS Edit are both text editors.
Fire up your editor of
choice, and enter the Java program shown in List a. Type this program,
as shown, in your text editor. Be careful that all the parentheses,
braces, and quotes are there.
List a) Your first Java
application: 1) /* 2) This is a simple
Java program 3) Call this file
"Demo.java". 4) */ 5) class Example{ 6) //Your program
begins with a call to main( ). 7) Public static void
main (String args [ ] ) { 8) System.out.println
( "This is a simple Java program."); 9) } 10) } Warning: The numbers before
each line are part of the listing and not part of the program; they're
there so I can refer to specific line numbers when I explain what's
going on in the program. Do not include them in your own file. Entering the Program: In Java, unlike other
programming languages, the name of the source file should be followed by
the .java (dot java) extension. In Java the source of a file is
officially called a compilation unit. It is a text file that
contains one or more class definitions. The Java compiler requires that
a source file use the .java filename extension.
Compiling the program: To compile the example
program, execute the compiler, javac, specifying the name of the source
file on the command line as, shown below: C:\>javac Example.java The javac compiler creates a
file called Example.class that contains the bytecode version of the
program. To actually run the program,
you must use the java interpreter, called java. It is as shown below: C:\>java Example When the program is run, the
following output is displayed: This is a simple Java
program. CLOSER EXAMINATION OF THE
PROGRAM:
In the forthcoming articles
we will have a look at some of the applets in JAVA. –
Deepak Chandrasekaran By Deepak Chandrasekaran JAVA: A Beginner's Guide Oops... I did it Again! Objects and Classes First Java Application Your First Java Applet Statements and Expressions Variable Type & Declaration Variables and Strings Arrays and Overloading in JAVA
By Neeraj Mathur
By Ruchi Gupta
Computing |
|
|
|
|
Analysis |
Architecture |
Astrology |
Ayurveda |
Book Reviews |
Buddhism |
Cartoons | Cinema |
Computing |
Culture |
Dances |
|
Home | Hindi | Bolography | BoloKids | Kabir | Poetry | Quotes | Workshop | Writers | Contribute | Search | Contact |
|
|