First knowledge of Java

Source: Internet
Author: User

Java is a compiled and interpreted language, the Java program is written to write classes, Java programs are stored in the class file, a Java file can only have one public class, and the Java file file name must be declared in the file public class name The compiled Java code is called a bytecode, and the bytecode appears as a. class file. In the Java programming textbook, the author gives us the above summary of Java programs and writing.

In the first section of the professional class, the teacher on our emphasis on the Java program in the case of code is very important, not like C language as arbitrary (of course, C can not be arbitrary). I'll write the following information about Java that we have learned in a few days.

1. Basic Java Syntax

A, keywords, used to define the language, these words for the compiler has a special meaning, and can not be used as identifiers, these keywords have a lot of the C language we have met, this is not listed, and its role is roughly the same. And in Java, Main is not a keyword, and three reserved words (true, false, NULL) are not keywords, but cannot be used as identifiers.

b, identifiers, and also has its own rules for the marker Java:

> keywords and three reserved words cannot be used

> identifiers can contain letters, numbers 0~9, underscores (_), or dollar signs ($)

>, the first character of an identifier must be a letter, an underscore (_), or a dollar sign ($)

>, identifiers are case-sensitive but dollar-defined lengths

Identifiers are not only subject to rules but also certain rules (hump naming or Pascal nomenclature) when naming.

C, basic data types

int, long Integer (long), short integer, floating point (float), double type (double), character type (char), Boolean (Boolean), Byte type (byte)

D. Define Constants

Final data type character constant name = value; In normal case the constant is named uppercase

Naming a constant can be brought into business meaning and modified everywhere. This is the two great benefits of naming constants.

2. Program Flow control

A, there are three main methods of process Control: Invoke, select (if/else, switch), loop (for, while, Do/while).

B, Boolean logic refers to two to multiple Boolean expressions combined into a single Boolean expression, when combined, there are four types of logic (and, or, XOR, non)

C, Boolean operator: short-circuit and (&&), short-circuit or (| | ), XOR (^), and (&), or (|), Non (|)

3. Classes, objects, packages

A, speaking of which, we should talk about structured programming and object-oriented programming:

Collusion programming: Splitting a big problem into smaller tasks and then writing a process (or function) for each smaller task is a common method of C language;

Object-Oriented Programming: It is used to design the object of the problem to be solved in Java;

B, a class is a set of objects that have the same properties and behaviors, and objects include behaviors and properties; The package declaration must be the first executable statement of the source file.

C, the name of the package: Use the organization domain name inversion method, using lowercase letters and numbers.

Class name + package name = fully qualified name;

D, access modifiers:

Themost restrictive modifier in the >, Public:java language, commonly referred to as "public". The classes, properties, and methods that are decorated are not only accessible across classes, but also across packages (package).

        >, Private:java language is generally referred to as "private." Classes, properties, and methods that are modified by them can only be accessed by objects of that class, their subclasses cannot be accessed, and cross-package access is not allowed.

        > , protect: An access modifier between public and private, commonly referred to as a "protected form." Classes, properties, and methods that are modified by them can only be accessed by methods and subclasses of the class itself, even if the subclasses are accessible in different packages.

>, default: That is, no access modifier, often referred to as the "Default access mode." In this mode, access is allowed only in the same package.

Learning to be here ...

First 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.