Java first week

Source: Internet
Author: User
Tags float double

Summary of the first to second chapter

1. Data type

1) integer type byte short int long

2) Decimal type float double

3) Character type Char

4) BOOL Type Boolean

2. Operators

1) arithmetic operator +-*/%

2) logical Operators && | | !

3) Relational operators > < =

4) increment, decrement operator + +--(add to front, increment first)

5) composite operator + = = *=

3. Identifiers

Rules: Consisting of numbers, underscores, letters, and dollar signs;

Start with a letter, underscore, dollar sign

Naming rules: Hump naming method, Pascal's nomenclature

4. Packing class

The integer contains a basic int type

Double contains a basic double type

5. Constants

When you add a final to a variable, the variable becomes a constant.

The constant name requires capital!

Why do you give a constant a name?

1), for the constant into business meaning

2), a modification, change everywhere

6. Data type Conversion

1) Automatic data type conversion (small data type conversion to Big data type)

2) Force data type conversions (large data types to small data types)

It is important to be careful when using forced data type conversions, which can lead to loss of precision.

Note that the Boolean data type cannot be converted to another data type

7. Java annotations

1) Single-line comment//comment content

2) Multi-line Comment

/*

Comment Content

*/

3) Text Comment

/**

Comment Content

*/(more comments on classes and methods)

8. Process Control

1) Invocation of the method

2) SELECT statement

3) Loop statement

A Boolean type is required for both selection and looping statements

9, Boolean logic combined Boolean logic of four kinds

1) and

2) or

3) XOR or

4) Non-

10. SELECT statement

The If statement consists of three forms

1) Single Branch if statement (expression is true, execute, otherwise, execute Next statement)

2) Dual-branch if statement (expression True, execution of first statement, false, execution of another statement)

3) Multi-branch If statement (expression 1 is true, EXECUTE statement block 1, if expression 1 is false, expression 2 is true, expression 2 is executed, and so on)

11. Receive input

Importing a file import Java.util.Scanner;

Scanner input = new Scanner (system.in);

int num = Input.nextint (); (Receive integer input)

Double d = input.nextdouble (); (Receive decimal input)

string s = Input.nextline (); (Receive string input)

12. Switch statement can omit default and break

13. Circular Statements

14. Generation of random numbers int random = (int) (Math.random () *100)

Summary of the third chapter

1, the use of Boolean value

Boolean right = false;

while (!right) {

}

2. Comparison of strings

String name = Input.next ();

if ("Zhang Fei". Equals (name))

System.out.print ("Welcome");

Else

System.out.print ("Do not know");

Iii. Summary of the fourth chapter

In Clipse, it is based on the project;

Package

When the Java file is managed as a package, the path is added to the name of the package at the time of the reference.

That is, the name of the package and the name of the class.

Pkg.test.PkgDemo//Fully qualified name

The declaration of the package must be the first executable statement in the source file

Add: javac-d Pkgdemo.java Generate Package file

Naming conventions for the package:

Naming with an inverted organization domain name

Www.baidu.com

com.baidu.department.hr

Structured programming (process-oriented) programming around functions, tasks to be solved

Object-oriented programming (oriented programing) around problem fields, objects to design

What is a class?

An abstraction with the same characteristic object.

A class is an abstraction of an object, and an object is an instance of a class.

A class is a collection of sets of objects that have the same properties and behavior.

The characteristic is the attribute (static, noun), the behavior is the method (verb).

Access modifiers (the embodiment of security)

public.

Protected protected

Private privately owned

Writing of methods

Public String toString () {return ' name ' + name + ' \ n age ' + ages; }

/* Access modifier return value type method name ([parameter list]) {method Body-function code block to be implemented} */

A variable directly declared in a class is called a member variable.

Member variables do not need to be initialized, they have their own default initial value, the string is null, the integer is 0, and the floating-point number is 0.0

Instantiating objects (creating objects)

This guarantee refers to the current object, which is used when local variables and member variables have the same name.

Add:

Null pointer exception
NullPointerException
Reason: Forget to initialize Class (new)

Java first week

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.