Simple java Basics

Source: Internet
Author: User

Simple java Basics

I. java features

1. Object-oriented:

Compared with C ++, JAVA is a pure object-oriented language. C ++ retains many

And C, as we all know, is a process-oriented language.

C ++ becomes a "mixed blood ". The JAVA syntax removes the features reserved for C ++ that are compatible with C, such as header files, pointer algorithms, structures, and units.

2. platform independence:

The intermediate code script is different from other programming languages. Java does not generate an executable file (.exe file), but generates an intermediate bytecode file (. class file ).

In any operating system, as long as the Java Virtual Machine (JVM) is installed, the intermediate bytecode file can be interpreted and executed. This is exactly the mechanism for Java to implement portability.

3. multithreading:

Multi-thread can make the program more interactive and real-time, and make the most of the multi-processor system. JAVA has powerful multi-thread processing capabilities,

Because there are significant differences in thread implementation between mainstream operating system platforms, JAVA implements a special multithreading mechanism for different operating systems.

I will not list many of them.

Ii. About java

The source code of java is *. java's plain text file, which can be written in any text editor but cannot be executed.

JDK is a java development kit that can compile *. java files into executable java programs.

JVM is required to run executable java programs.

JRE includes JVM

JDK contains JRE

If you only need to run the java program, you only need to install JRE to run it.

3. Simple java programming

Import java. utli. example;

Public class hello {

Public static void main (String [] arge ){

System. out. print ("simple print output ");

Wrote input = new partition (System. in );
System. out. println ("enter a number ");
Int a = input. nextInt ();
System. out. println ("enter a string ");
String B = input. next ();

Int c = (int) (Math. random () * 10); // randomly generates a 0 ~ An integer of 10
System. out. println ("randomly generated number:" + c );

// Simple Loop

For (int I = 1; I <= c; I ++ ){
System. out. println ("" + I + "");

}

While (true ){

If (c = 0) {break ;}
C --;
}

 

 

}

}

Iv. Simple function calls in java

For convenience, I just wrote an example directly in a class.

Public class hello {
// Declared public data type. public indicates public prefix, private table,
// The protected table is protected. If this parameter is left blank, the table is default.
Public String;
Protected int B;
Int c;
Private String d;
Public void easy () {// No return value void

System. out. println ("easy called ");
}

Public String (){

Return "returns a string ";
}

Public static void main (String [] arge ){
Hello El = new hello ();
El. easy (); // easy call
System. out. println (El. to (); // print the returned string and call the method.
El. a = "assign a value to a"; // call the Data Type
System. out. println (El. a); // print the value assigned to.
}

}

 

 

 

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.