Java Fundamentals of Learning Java

Source: Internet
Author: User

First, comments

There are three types of comments in Java:

Block Comments (/* contents of comments */)

Line comment (//content of comment)

Comments for the document (the contents of the/** comment */)

Second, identifiers

Concept: In the Java language, there are names for variables, constants, functions, and statement blocks, which we call Java identifiers.

Identifiers are used to name classes, objects, methods, variables, interfaces, and custom data types.

Example:

Class Student {};

int identifier;

String username;

Identifiers consist of:

A Java identifier consists of a number, a letter and an underscore (_), a dollar sign ($), and can only begin with a character, "_", or "$".

Identifiers are case-insensitive and do not specify a maximum length.

The identifier cannot be a Java keyword.

Iii. naming conventions in the Java language

Classes and interfaces. The first letter of each word is capitalized and is case-sensitive. For example: Myclass,helloworld,time and so on.

The method name. The first letter is lowercase, the remainder is capitalized, and is case-sensitive. Use as little underline as possible. For example: Myname,settime and so on.

The constant name. The constant name of the base data type uses all uppercase letters, and the words are separated by underscores. Object constants can be mixed in case. For example: Size_name.

Iv. Key Words

Keywords are identifiers that have been used by Java, have specific meanings and uses, and are the following keywords for use in the Java programming language:

Abstract do true private throw implements class try

Boolean throws double import void protected float finally

Break else public transient char instanceof new for

byte int return extends Super interface switch NULL

Case false short continue native synchronized while if

Catch final long package static volatile default this

V. Types of data

  A data type is a method of programming language that describes things and objects. Java data types fall into two categories: basic data types and reference data types.

  Basic data types

Integer type: Used to represent numeric values without fractional parts, which allow for negative numbers, Java provides 4 types of integers (Byte,short,int,long), and the default value is 0.

Type

Storage requirements

Range of values

Default value

Int

4 bytes

-231~231-1 65535

0

Short

2 bytes

-215~215-1

0

Long

8 bytes

-263~263-1

0

Byte

1 bytes

-128~127

0

    

Floating-point type: Used to represent a numeric value that has a decimal part. Java has 2 floating-point types (Double,float), as shown in the following table:

Type

Storage requirements

Range of values

Default value

Float

4 bytes

-3.40292347E+38

~3.40292347e+38 F

0.0

Double

8 bytes

-1.79769313486231570e+308~

1.79769313486231570E+308

0.0

    

Character type: Used to represent a single character. Typically used to denote character constants, there is a character type (char) in Java. Occupies 2 bytes, Unicode encoding, characters are stored in \u0000~\uffff, the first byte in the encoding is still compatible with ASCII.

Boolean type: There are false and true two values that are used to determine the logical condition. An integer value and a Boolean value cannot be converted to each other. Type has one (Boolean)

  Reference type

Class

Interface

Array

Enumeration

Vi. Definition of variables

A variable is the amount of the value that can be changed during a program's run. Variables include the variable name, the value of the variable two parts.

Definition of a variable: the declaration of a variable and the initialization of a variable (first assignment), without assigning a value to a variable without allocating a memory space to the variable.

Variable declaration format: Data type variable name 1[, variable name 2, ...];    For example: int stuno; float x, y;

Initialization of a variable: After declaring a variable, the variable is displayed initialized by an assignment statement.

Variable declaration

Double salary;

Initialization of variables

salary=3.1415926;

A constant is the amount of its value that remains constant during the program's run. In Java, you use the keyword final to define constants. constants cannot be changed after they have been assigned.

The syntax format for a constant definition:final data type constant name = value; For example: Final Flaot pi=3.1415926;

Java Fundamentals of Learning 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.