Recalling Java memoirs (1): Java 01 basic data types and statements, Java 01

Source: Internet
Author: User

Recalling Java memoirs (1): Java 01 basic data types and statements, Java 01


Basic requirements for writing java programs

1. Writing a java class is actually writing a java file (by default, the class name and file name must be consistent)

2. classes should be written in a package)

Package Description: display of a folder (reflecting the hierarchical relationship of a file)

The layers in the package depend on. for distinguishing different java files

Application between packages

1. Create a class package name (specifying the class location)

2. Use the class import package name. Class Name (you can use * to represent all)

 

Basic Data Type:

1. identifier

Naming rules:

1. It is composed of letters, underscores, numbers, $, but numbers cannot start.

2. Case Sensitive

3. You cannot use keywords.

4. Habits

1. Certain semantics is required. All letters must be in lowercase.

2. The first letter of the class name is capital Student, and the first letter of the variable name is lowercase studentName

3. Use _ to connect file_path between words

 

2. Basic data types (8 types)

1. Integer

Byte

1B 8-bit

-128--127

 

 

 

Short

2B 16

-2 ^ 15

 

 

 

Int

4 32

-2 ^ 31

 

 

 

Long

8 64

-2 ^ 63

 

 

 

2. Floating Point

Float

4B 32

Double

8B 64

3. Character

Char

2 16

 

4. Boolean

 

 

Boolean

1B true/false

 

 

Conversions between types

1. Forward

Byte-short (char)-int-long-float-double

2. Reverse (forced conversion)

(Conversion Type) identifier/Number

 

Java features

Reference data type

Class, interface, array

Reference type identifier (variable) = new reference type (parameter)/[parameter]: constructor of reference type

String s = new String ("");

Int arr [] = new int [10]

 

Difference between reference type and basic type (memory)

Stack memory: stores simple data types (variable names and values)

Heap memory: Used together by the stack memory. The stack stores the first address of heap memory and the referenced instance in the heap (Entry/attribute defined by the method)

 

 

Basic statement:

Operator

 

Shift Operator

> Move all symbols right

>>> Add 0 to the high position of the right shift

Logical operators

&/|

&/|

!

Arithmetic Operation

 

++ Usage: Do not use I + = 1;

Declaration of process statement Variables

Global variable: the scope is the entire file.

Local variable: Partial Method

Use of Operators

 

Sequence

Branch if. else/

Switch (byte/short/int/char)

 

... Do case

Loop for/while

 

**************************************** **************************************** ***************************

Reference Type

Array: an object

Declare an array

Type [] array; Recommended/type array []

Create an array

Open up space in heap memory and specify the length of the array. Once specified, the length cannot be changed.

// Multi-dimensional array

Type [] [] .. Array // declaration and Creation

 

Attributes and methods of Arrays

Arrays are provided by Java APIs and have certain methods and attributes.

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.