2018-07-14java base + basic data type + Auto/force data type conversion + define variable + operator

Source: Internet
Author: User
Tags class definition integer division java se

Java View version:

CMD inside Input: java–version Enter!

In the enterprise is generally jdk1.5-->1.7 version!

①j2se:java 2 Platform Standard Edition (renamed to Java SE after 2005 years)! Contains classes that make up the core of the Java language, such as database connections, interface definitions, data structures, input/output, network programming!

②j2ee:java 2 Platform Enterprise Edition (renamed to Java EE after 2005 years)! Enterprise Edition (Corporate Edition) contains all the classes in J2SE and also contains classes for developing Enterprise-class apps! For example, Ejb,servlet,jsp,xml, transaction control, which is now the main direction of Java applications, like some banks or telecommunications systems mostly based on this architecture!

③j2me:java 2 Platform Micro Edition (renamed to Java ME after 2005 years)! Software development for consumer electronics products! such as pagers, smart cards, mobile phones, PDAs, set-top boxes!

Emphasize: All Java program file suffix should be "*.java", and any one *.java program must be compiled, after compiling will form a *.class file (bytecode file), and then execute on the computer (Tips: The *.class file is executed), But the computer that interprets the program is not really a computer, but a computer Java virtual machine that is simulated by software and hardware (Java VM is the JVM)!

Quick access to CMD in this path method:

In CMD, run the statement that you just wrote:

C:\users\jason\desktop\javapro\2018-07-14java>javac Demo1.java

After executing the JAVAC, generate the. class file!

C:\users\jason\desktop\javapro\2018-07-14java>java Demo1

Shenwang Deleo!

If the code is modified after compiling (JAVAC) and executing (Java), it should be compiled again with Javac, and the *.class file will be updated to the latest code (simply: Compile-and-execute first)!

Java is a Class!

The Java file name is consistent with the class name, where: Demo1.java

public class Demo1

{

This is the main method, the entrance to the program!

public static void Main (string[] args)

{

Strictly case-sensitive in Java!

Output statement, put "God Wang Delee!" "Print it Out!"

System.out.println ("God Wang Delee! ");

}

}

There can be a lot of classes, but there can only be one for public to decorate!

Class Person

{

}

println and Print differences:

System.out.println (); It's a line-break!

System.out.print (); It's not a wrap!

Note Content does not enter the *.class file, only in the *.java file!!!

JRE (Java runtime Environment:java running environment)

Including the core class libraries required by Java virtual machines (Jvm:java) and Java programs, if you want to run a well-developed Java program, you only need to install the JRE on your computer!

JDK (Java Development Kit:java Development Kit)

The JDK is available to Java developers with Java development tools and jre! So with the JDK installed, there's no need to install the JRE separately!

Commands that are common in DOS command line:

Dir: List the files and folders in the current directory!

Md: Create a directory!

RD: Delete Directory!

Cd: Enter the specified directory!

Cd.. : Back to the top level directory!

Cd\: Go back to the root directory!

Del: Delete Files!

Exit: Exit the DOS command line!

①public class Definition:

The class name must be consistent with the file name, or the program will not compile, and there can be only one class with the public modifier decorated in a *.java!

② Master 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.

③ Each complete statement code requires the use of ";" To the end!

④//Single-line comment

/* Multiline Comment */

Emphasize:

① is used in the program to define the name of the identifier, such as file name, class name, method name or variable name, in Java, the definition of identifiers is composed of letters, numbers, _ (underscore), $, which cannot be duplicated, cannot start with a number, cannot be a keyword in Java, And every identifier must have its own meaning, such as Studentname, is the name of the student!

② when defining identifiers, there are case differences, such as Fuck,fuck and so on, although the words are the same, but all belong to different identifiers (Tips: You cannot define two variables with exactly the same name)!

Keywords in Java:

Abstract

Assert

Boolean

Break

Byte

Case

Catch

Char

Class

Continue

Const

Default

Do

Double

Else

Extends

Enum

Final

Finally

Float

For

Goto

If

Implements

Import

instanceof

Int

Interface

Long

Native

New

Package

Private

Protected

Public

Return

Short

Static

Synchronized

Super

Strictfp

This

Throw

Throws

Transient

Try

void

Volatile

While

Fixed constant is called Constants!

Variable:

Variables are small boxes of data stored in memory that can be used to store data and fetch data, and to have an unambiguous data type, what data type loads what data!

Data type conversions:

Small precision-auto-fit and high precision

High precision---------Low precision

Whether it is a memory or a hard disk, the smallest unit of informationin a computer's storage device is called a bit, and we call it "bit", usually in lowercase letter B! The smallest storage unit of the computer is called "byte", usually denoted by the capital letter B, and the byte is made up of 8 consecutive bits!

When a program needs to use storage space, the minimum operating system is assigned to a program of 1 bytes instead of 1 bits!

For example: It's like you just need 1 cigarettes, you go to the store to buy cigarettes, the smallest unit of the store allocation is 1 boxes (20), he can't sell you 1 cigarettes!

Introduction to storage units:

1B (bytes) = 8bit

1KB = 1024B

1MB = 1024KB

1GB = 1024MB

1TB = 1024GB

1PB = 1024TB

Escape characters in Java:

Basic data types in Java:

The default integer type in Java is type int:

If you think 12345678901 is between -263~263-1, so it's a long type, it's wrong! Integer constants in Java If you do not have to add an L suffix between -2147483648~2147483648 (it is recommended to use uppercase), you can also add an "l" suffix between -2147483648~2147483648!

The float type constant must have an "F" suffix added!

The default floating-point type in Java is double type

①3.14 does not have a suffix, so it is a double type!

②5.28d is a double type!

③1.26f is a float type!

Define the basic format of the variable:

Data type variable name = data value;

Considerations for Using Variables:

① variable can not be assigned after the definition (declaration only), use the value of the assignment, no assignment can not be used (there is no value in memory space so can not be used, it is recommended to initialize a value at the time of declaration)!

The ② variable uses a scope restriction (within the curly brace {} that declares it)!

③ variables can not be defined repeatedly (in a class can not be repeated definition, can be repeated assignment)!

Data type conversions:

Byte-->short-->int-->long-->float-->double

Precision from small to large!

Automatic data type conversions:

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

To force data type conversions:

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

Operator:

Operator

Arithmetic rules

Example

Results

+

Positive sign

+3

3

+

Add

2+3

5

+

Connection string

"Chinese" + "country"

China

-

Minus sign

int A=3;-a

-3

-

Reducing

3-1

2

*

By

2*3

6

/

Except

5/2

2

%

Take surplus

5/2

1

++

Self-increment

int A=1;a++/++a

2

--

Self-reduction

int B=3;a--/--a

2

① Division "/" when both sides are integers, take the integer part, and when one side is floating point, divide by normal rule!

②0 cannot do divisor (5/0 is a mistake)!

Assignment operators:

Operator

Arithmetic rules

Example

Results

=

Assign value

int a=2

2

+=

Add after Assignment

int a=2,a+=2, (a=a+2)

4

-=

Reduced-value Assignment

int a=2,a-=2

(a=a-2)

0

*=

Multiply post-Assign value

int a=2,a*=2

(a=a*2)

4

/=

Assign value after integer division

int a=2,a/=2

1

%=

Assign value after modulo

int a=2,a%=2

0

Comparison operators:

Operator

Arithmetic rules

Example

Results

==

Equivalent to

4==3

False

!=

Not equal to

4!=3

True

<

Less than

4<3

False

>

Greater than

4>3

True

<=

Less than or equal

4<=3

False

>=

Greater than or equal

4>=3

True

The = number of the ① assignment operator is the variable that assigns the value to the right of the = sign to the left!

The ②== number is used to determine if the value on the right side of the = = number is equal to the value on the left (generates a Boolean value)!

Example code:

int num1=3;

int num2=4;

System.out.println (NUM1=NUM2);

System.out.println (NUM1==NUM2);

The result of the above code output first value is 4, the second value is true!

String that is not in the base data type, but is a reference data type!

Class Demo3

{

public static void Main (string[] args)

{

int numx;

System.out.println (NUMX);

BUG: Error: The variable may not have been initialized numx!

Data type conversions (by large turn small)

int num1=100;

BYTE Num2=num1;

Error: The accuracy may be lost!

Cast:

int num1=100;

byte num2= (byte) num1;

int num1=100;

Short num2= (short) num1;

In addition to the issues to note:

int KEY1=5/2;

Double KEY2=5/2;

Double KEY3=5D/2;

System.out.println (key1+ "..." +key2+ "..." +key3);

}

}

2018-07-14java base + basic data type + Auto/force data type conversion + define variable + operator

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.