Some basic knowledge of Java

Source: Internet
Author: User
Tags mathematical functions

For beginners in Java, let's first understand what is Jave language? Java is an object-oriented programming language, not only absorbs the various advantages of the C + + language, but also rejects the more difficult to understand in C + + inheritance, pointers and other concepts. As the representative of static object-oriented programming language, the Java language is an excellent implementation of object-oriented theory, allowing programmers to do complex programming in an elegant way of thinking. Jave has the features of simplicity, object-oriented, distributed, robustness, security, platform independence and portability, multi-threading, and dynamic. Java can write desktop applications, Web applications, distributed systems, and embedded applications.

Java (source) program structure

The Ijava program consists of one or more compilation units, each of which is a text file with a. java extension, also known as a Java source program file. Include several different elements in the Java compilation unit, i.e.

Package  Statement Import     Statement class (Class) declaration or pretext (interface) declaration statement

A program can include several classes. There are juxtaposition, inheritance, and containment relationships between categories. These classes usually work together in tandem. Programming can only be done in methods. The statements in the classes and methods are contained between "{" and "{". Each statement ends with a ";". Statements are composed of expressions, variables, literals, and keywords. After compiling each class produces a ". Class" file.

package name, import   Packagename, Class class   name 1  {      domain definition      method name 1 ()  {     ...      }       Method Name 2 ()     {      ...   }  ...... } ...

Several types of Java programs

①application (Java application )

"Java applications" are Java programs that can run independently. Executed by the Java interpreter control.

②applet (Java applet)

The Java applet cannot run on its own, but is embedded in a Web page. Performed by a Java-compatible browser control.

③serverlets

The reader can run your first Java program.

1. Write and run the program using the JDK utility

Go to "command Prompt".

Operate in the order shown.

Application

D:\> edit helloapplication. Javad:  \>javac helloapplication. Javad:  \>java  Helloapplicationhellow, Javaworld!

Applet

d:\> edit helloapplet.javad:\> javac helloapplet.javad:\>  edit test.htmld:\ >  appletviewer  test.html

The composition of the Java program

A Java program consists of one or more compilation units, each of which is a text file with a. java extension, also known as a Java program source file.

Example F (x) program calculates mathematical functions. SOURCE program file name: Fx.java.

A x>0

F (x)

-A x<0

 public  class   fx{ public   int  FX (int   if  (X>213 return  1
      
      else  
      return  0
      "}  
      public  
      static  
      void  
       main (String     Args[] {fx y  =
      new  
       FX ();     System.out.prinln ( "f (x) =" +y.fx (267
      
     

About the main () method

The main () method is a method that is automatically executed by the interpreter or the Java Virtual machine and is the starting point for the Java application to run.

The class that contains the main () method is called the "main class". When there are multiple classes in the same source program, the main () method should be placed in the class that is decorated by public.

The method declaration (format) of the main () method must be

 Public Static void Main (String "" args)

The type of the argument must be a string "", and the parameter name can be any name, but it is customary to use args or argv.

Basic Structure of Applet program

Importjava.awt.*;Importjava.applet.*; Public classClass nameextendsApplet { Public voidinit () {} Public voidstop () {} Public voidstart () {} Public voiddestroy () {} Public voidPaint (Graphics g) {}}

Execution HTML markup for applet programs

<applet

[Codebase=applet program URL]

Code=applet Program class name

Width= Display Area Height

>

[<param name = parameter name value= argument value]

......

</APPLET>

Some basic knowledge of Java

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.