Java Programing

June 16, 2007

The interpreter searches for the class in the

Filed under: Java Programming — webmaster @ 6:31 pm

The interpreter searches for the class in the class path , a list of directories where packages of classes are stored. We’ll discuss the class path in detail in the next section. The class path is typically specified by an environment variable, which you can override with the command-line option -classpath . After loading the class specified on the command line, the interpreter executes the class’s main( ) method. From there, the application can start additional threads, reference other classes, and create its user interface or other structures, as shown in Figure 3.1. Figure 3.1. Starting a Java application The main( ) method must have the right method signature . A method signature is a collection of information about the method, like a C prototype or a forward function declaration in other languages. It includes the method’s name, type, and visibility, as well as its arguments and return type. The main( ) method must be a public, static method that takes an array of String objects as its argument and does not return any value (void): public static void main ( String [] myArgs ) Because main( ) is a public and static method, it can be accessed directly from another class using the name of the class that contains it. We’ll discuss the implications of visibility modifiers such as public and the meaning of static in through Chapter 6. The main( ) method’s single argument, the array of String objects, holds the command-line arguments passed to the application. As in C, the name that we give the parameter doesn’t matter; only the type is important. Unlike C, the content of myArgs is a true array. There’s no need for an argument count parameter, because myArgs knows how many arguments it contains and can happily provide that information: int argc = myArgs.length; Java also differs from C in another respect here: myArgs[0] is the first command-line argument, not the name of the application. If you’re accustomed to parsing C command-line arguments, you’ll need to be careful not to trip over this difference. The Java interpreter continues to run until the main( )method of the initial class file has returned, and until any threads that it started are complete. Special threads designated as “daemon” threads are silently killed when the rest of the application has completed. .2 Policy Files Java 2 provides a simple mechanism for protecting your computer from evil programs like viruses. If you download a program from somewhere on the Internet, how can you prevent it from stealing information on your computer and sending it back out into the Internet? How can you prevent a - 55

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by Java Web Hosting