| Although Java has become well-known because it can be used in conjunction with World Wide Web pages, you can also use it to write any type of computer program. The Saluton program you wrote during Hour 2, "Writing Your First Program," is an example of a Java application. To try out another program, use your word processor to open up a new file and enter everything from Listing 4.1. Remember not to enter the line numbers and colons along the left side of the listing; these items are used to make parts of programs easier to describe in the book. When you're done, save the file as Root.java, making sure to save it in text-only or plain ASCII text format. Listing 4.1. The Full Text of Root.java1: class Root {
2: public static void main(String[] arguments) {
3: int number = 225;
4: System.out.println("The square root of "
5: + number
6: + " is "
7: + Math.sqrt(number) );
8: }
9: }
The Root application accomplishes the following tasks:
Before you can test out this application, you need to compile it using the Java Development Kit's javac compiler or the compiler included with another Java development environment. If you're using the JDK, go to a command line, open the folder that contains the Root.java file, and then compile Root.java by entering the following at a command line: javac Root.java If you have entered Listing 4.1 without any typos, including all punctuation and every word capitalized exactly as shown, it should compile without any errors. The compiler responds to a successful compilation by not responding with any message at all. Java applications are compiled into a class file that can be run by a Java interpreter. If you're using the JDK, you can run the compiled Root.class file by typing this command: java Root The output should be the following: The square root of 225 is 15.0 |
Friday, May 6, 2011
Creating an Application on java
Popular Posts
-
QUESTION 1 Marks Write four different Java statements where each statement adds 1 to integer variable x. 4 Answer x =x+1; x+=1; ++x; x...
-
BEGIN PROGRAM Main_menu Use variables: choice OF TYPE Integer Report1,Report2 OF TYPE String ACCEPT file DISPLAY “En...
-
All the elements of a communication network should be hardened so that it is resistant to various security attacks. Maintaining latest up...
-
One of the easiest ways into a system is by using a USB flash drive that implements the U3 standard. The U3 system is a secondary partition...
-
I. What is Linux? Linux is basically an operating system (OS for short). The Windows machine you're (probably) using now uses the Mcf...
-
Fatal error: the system has become unstable or is busy," it says. "Enter to return to Windows or press Control-Alt-Delete to rest...
-
BEGIN RECORD member HAS FIELDS Number : Integer Name : String Contact no. : String ...
-
This hour's first project is an applet that displays the string "Saluton mondo!", the traditional Esperanto greeting that ...
-
Linux refers to the family of Unix-like computer operating systems using the Linux kernel . Linux can be installed on a wide va...


11:29 AM
mitraaa
0 comments:
Post a Comment