Create a Java application-general Linux technology-Linux programming and kernel information. For more information, see the following. A common Java application must contain a class that can be directly called by the outside world (usually a java interpreter). We can call this class as the main class of the application.
Build Java applications
1: main member function
A common Java application must contain a class that can be directly called by the outside world (usually a java interpreter). We can call this class as the main class of the application, the main class must contain the main member function. The entire application starts to execute this member function, which is similar to the C program.
The main member functions are described as follows:
Public static void main (String args []);
2: command line parameters
The parameter args of the main member function is called a command line parameter. args can be used to receive parameters passed to the Java application. The following is an example to illustrate the specific process of parameter passing:
Public class DrwRect
{
Public static void main (String args [])
{
Class Rectangle
{
Int width, height, area;
Public Rectangle (int w, int h)
{
Width = w;
Height = h;
Area = getArea (w, h );
}
Protected int getArea (int w, int h)
{
Int;
A = w * h;
Return;
}
Public void drawRect ()
{
Int I, j;
For (I = width; I> 0; I --)
System. out. print ("#");
System. out. print ("");
For (I = height-2; I> 0; I --)
System. out. print ("#");
For (I = width; I> 0; I --)
System. out. print ("#");
System. out. print ("");
}
} // Rectangle
Int w = Integer. valueOf (args [0]). intValue ();
Int h = Integer. valueOf (args [1]). intValue ();
Rectangle myrect = new Rectangle (w, h );
Myrect. drawRect ();
}
}
After compiling the program with Javac, you can use the java interpreter to execute it. The specific process is as follows:
Javac doRect. java
Java doRect 2 3
Note that "2 3" is the command line parameter, which will be assigned to the args variable of the main member function of DrwRect. The value of args [0] is "2", the value of args [1] is "3", and Integer. valueOf (Stringstring ). the intValue function is to convert a number in a string into an integer value.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service