Overview and basic grammar of Javase

Source: Internet
Author: User
Tags microsoft c

Well, this should have been sent before OOP, do not care, a replacement, this article will only be a basic outline of javase grammar, I will be in the recent new open a new pit, that is, the Java EE series, there will be CPP (compared to C + +, I prefer the name CPP) Series Ah, Linux series ah a variety of new pits, we step by step slowly.

For the basic grammar of the javase, in fact, most of the language is borrowed from the C language syntax (many languages are like this), here, first of all to clarify that a concept is strongly typed language, and weak type language, the characteristics of strong type language is that each variable has its fixed type, and can not be implicitly converted, Java is one of the representatives. The representative of a weakly typed language is JavaScript.

Java provides the following basic data types:

Byte (bytes) 8-128-127 0
Shot (short-integer) 16-32768-32768 0
int (integral type) 32-2147483648-2147483648 0
Long (length) 64-9233372036854477808-9233372036854477808 0
Float (float type) 32-3.40292347e+38-3.40292347e+38 0.0f
Double (dual precision) 64-1.79769313486231570e+308-1.79769313486231570e+308 0.0d
char (character type) + ' \u0000-u\ffff ' \u0000 '
Boolean (Boolean) 1 True/false false

There is also a reference data type: String

It is worth mentioning that the Java program running environment is the JDK built-in JVM (Java Virtual machine Java VM), even running Java programs on different platforms, is also running on the virtual machine, so his data type is not platform-limited, and has the so-called "cross-platform". And CPP is different, he relies on the platform, on different platforms, its various data types occupy a different space, this is not a detailed discussion (= O =), after the CPP series will be described in detail.

One of the points that must get to is "cross-platform", the reason why Java is so popular is because it is cross-platform, it is well known that Microsoft C # is very similar to Java, but it is not hot in Java, it can only run under Windows.

What is the specific embodiment of cross-platform?

1 Android, I don't have to say more.

2 Linux system servers, deploy Java EE on the server. On the market with Windows to do server, but less, how many? A few percent, this is still in the country is not very developed regions, such as the north of Guangzhou and Shenzhen with Windows Server estimates are not 1%.

To be honest, Java's execution efficiency is not very good (compared to c/cpp), but the computer is strong enough, Java execution efficiency is not weaker than the previous Cpp (laughter), compared to some scripting languages, such as Python, or a lot faster.

All variables must be initialized before they are used.

 public  class   Demo { public  static  void   main (string[] args) { int  i = 0;//  Declare and initialize  double  J //  declares a variable  j = 2.0; //         float          K; System.out.println (k);.  //  error, K uninitialized.  }}  

We can use the/* */To make code comments, you can also use//for single-line comment,/**. * * Effect with/*. */Note effect similar, different place is/**. */We can use some HTML tags and output them as a document using the Javadoc command.

/**Demo Class*/ Public classDemo { Public Static voidMain (string[] args) {/*we comment on the code*/        inti = 0; intj = 2; intK = i + j;//You can use variables for various operations//can use//to make a single-line comment.     }}
Method:

/**Method Demo:*/ Public classDemo { Public Static voidMain (string[] args) {inti = 3; intj = 5; System.out.println (Add (i, j));//Output 8    }     Public Static intAddintXinty) {returnX +y; }}

The C/cpp method is a function in the. Return keyword that returns a value of the specified type.

/**Method Demo:*/ Public classDemo { Public Static voidMain (string[] args) {inti = 3; intj = 5;    Add (i, j); }     Public Static intAddintXinty) {System.out.println (x+ y);//Output 8        return; }}

When you specify a return type of void, you do not need to return a value, but the return keyword still works, and it can return the method to be used, that is, to end the current method.

PS: About Java beginners, for a c/cpp beginners are almost no difficulty, but different languages have their own unique ideas and programming style. If you want to have a deep understanding of Java, it is recommended to read "Effective Java" "Corejava" "Thinking in Java", the former two selected 1 can be, when there is a certain basis can see thinking in Java, see a few times (laughter).

Overview and basic grammar of Javase

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.