Java- Basic Structure (Java Learning Notes (1.1))

zhaozj2021-02-17  67

Java- Basic Structure (Java Learning Notes (1.1))

Editor: IMDT

Date: 2002-7-4

Java program classification

(1) Java program is divided into two categories: Java Application and Java Applet. Java Application must be performed under the operating system where you are located. Java Applet must be used in Hypertext Markup Language, ie HTML.

Java Application

(1) The structure of Java Application:

Below is a typical Java Application program.

Public Class Ko2_1

{

Public static void main (string args [])

{

System.out.println ('Hello World!');

}

}

[Note 1] When the class declaration is started, if the public declaration is used, the file name must be the same as the name.

[Note 2] main () function is the entry of the program

[Note 3] args [] is used to pass the command line parameters, that is, there is no parameters, and this parameter cannot be deleted.

(2) The structure of Java Applet:

Here is a typical Java Applet program.

Import java.awt. *;

Import java.applet. *;

Public Class Ko2_2 Extends Applet

{

Public void Paint (Graphics G)

{

g.drawstring ("Hello World!", 80, 60);

}

}

[Note 1] import ... IMPORT ... is equivalent to the #include description of the C or C language.

[Note 2] Four basic object methods of Java Application

1, public void init (): Used to generate an initialization action of graphical user interface, such as setting a glyph, screen prospect, and background colors.

2, public void start (): When the Java Applet object is loaded by AppletViewer or is called by the browser, the start () method is executed immediately after INIT.

3, public void stop (): When the user leaves the applet network, the stop () method is immediately executed, and the Java Applet object is notified to stop working.

4. Public Void Paint (Graphics G): Used to redraw the contents of the Java Applet object in the screen, so if there is no Paint () method, the screen will not display anything.

[Note 3] Applet use:

转载请注明原文地址:https://www.9cbs.com/read-31347.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.036, SQL: 9