java-Basics-Variables-keywords-four classes eight data types-data conversion

Source: Internet
Author: User
Tags class definition

    Java Overview

public class Demo {//define a class

public static void Main (string[] args) {//Main method, starting point of all Programs

/* Print output on the screen */

System.out.println ("Hello world!");

}

}

(1) public class definition:

The class name must be consistent with the file name, or the program will not compile in a *. There can be only one public class in Java;

(2) Main method main ():

The Main method represents the beginning of a program, and all the program code is executed sequentially, and the main method in Java is also placed in a class.

(3) System output SYSTEM.OUT.PRINTLN ():

The function of this statement is to display the output information directly on the screen. Each complete statement code requires the use of ";" To the end.

(4) Note:

Represents a single-line comment, which is a double slash (//) before the content of the comment, and the Java compiler ignores this part of the message.

/*...*/represents a multiline comment, a multiline comment, which begins with a single slash plus a star marker (/*) in front of the comment content and ends with a star-shaped marker plus a single slash (*/) at the end of the comment content. This method is generally used when the comment content is more than one line.

identifiers, Keywords

in the program used to define the name of the identifier , such as the file name, class name, method name or variable name, etc., in the

The definition of identifiers in Java is formatted by letters , numbers , _ ( underscores ), and can be made up of $ , which cannot be duplicated, cannot start with a number, and cannot be a keyword in java. And every identifier has its own meaning.

Note : identifiers are case-sensitive.

There are case differences when defining identifiers, such as oracle,oracle,oracle, and so on, although the words are the same, but all belong to different identifiers.

hint : A simple suggestion for writing identifiers.

Some readers who are just in touch with programming languages may find it cumbersome to remember the rules above, so remind readers here that identifiers should always start with letters and try not to include other symbols.

Java keywords in :

abstract abstract

assert

boolean Boolean

break  jump out of the loop

byte   byte

CASE 

catch

Char character class

class

Continue jump out of the current loop

Const Constants

Default Object Methods

Do and Loop

Double floating-point data type

else judge

extends inherit

enum

< Span style= "FONT-SIZE:16PX; Color: #ff0000 ">final cannot be inherited, can inherit

< P align= "left" >finally

float double floating-point

for Span style= "COLOR: #0000ff" > loop

Goto

If judgment

Implements implementation Interface

Import Guide Package

instanceof Determine whether an object belongs to a data type

int integral type

Interface defining interface keywords

Long Integer type

Native

New instantiates an object

Package Packages

Private privatization modifier

Protected

Public Common

return return value

short short

static modifier

synchronized

super call parent class

STRICTFP

this Represents itself

Throw

Throws

Transient

Try

void

Volatile

While Loop

Basic types of 4 classes 8 kinds
four class

eight types

Number of bytes

Data Representation range

Integral type

Byte

1

-128~127

Short

2

-32768~32767

Int

4

-2147483648~2147483648

Long

8

-263~263-1

Floating point Type

Float

4

-3.403e38~3.403e38

Double

8

-1.798e308~1.798e308

Character type

Char

2

Represents a character, such as (' A ', ' a ', ' 0 ', ' home ')

Boolean type

Boolean

1

Only two values true and False

Note: The default integer type in Java is type int

The default floating-point type in Java is double type

         

        to define the syntax format for a variable :

Data type variable name = data value;

int a = 100;

       A variable can be assigned without assigning a value after it is defined. No assignment can be used . variables have scope restrictions when used, variables cannot be defined repeatedly.

Data type conversions:

Automatic type conversion

A data type that represents a small range is converted to a large range of data types, which is called automatic type conversion

Automatic type conversion format:

Data type variable with large range = data type value with a small range;

Such as:

Double d = 1000;

Or

int i = 100;

Double D2 = i;

Forcing type conversions

A data type that represents a large range is converted to a small range of data types, which is called coercion type conversion

Forced type conversion Format:

Range small Data type variable = (range small data type) range large data type value;

Such as:

int i = (int) 6.718; The value of I is 6

Or

Double d = 3.14;

int i2 = (int) d; The value of I2 is 3

java-Basics-Variables-keywords-four classes eight data types-data conversion

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.