Java Basic Notes

Source: Internet
Author: User

Installation of JDK:

    1. Download, install
    2. Configuring Environment variables

A) path:.; %java_home%\bin;

b) installation directory for JAVA_HOME:JDK

c) classpath

JDK and JRE and JVM:

JAVA program run Process:

    1. Compiling Javac: Compiling the Java source file into a class byte-code file
    2. Run Java: Run the class file

identifiers ( naming classes, methods, variables) :

    1. Start with a letter ( in Unicode character set), underscore, $
    2. The remainder can be: letter ( in Unicode character set), underscore, $, number
    3. cannot be a keyword

Variable:

    1. Local variables

Defined within a method or within a statement block. belongs to a method or statement block.

You must initialize it manually before using it!

    1. Member variable (instance variable field)

Defined inside the class, outside of the method. belong to the object!

If we do not initialize the member variables manually, the system will initialize automatically. The rules for initializing are as follows:

Number: 0,0.0 Boolean: False char:\u0000 reference type: null

    1. Static variables (class variables)

Defined inside the class, outside the method, using the static modifier. belongs to the class!

If we do not initialize the static variable manually, the system will initialize automatically. Initializes the rule to the same member variable.

Data type:

    1. 1. Basic data Types

a) number

I. integer: Byte (1 bytes) Short (2 bytes) int (4 bytes, integer constant Amount default this type) long (8 bytes)

II. Floating-point number: Float (4 bytes) Double (8 bytes, floating point Changshime that type)

b) character char (2 bytes)

c) Boolean boolean (1 -bit)

    1. 2. Reference type (4 bytes)

a) array

b) object

c) interface

An expression:

    1. 1. automatic promotion of type

If there is a long , the result is long .

If there is a double , the result is a double .

    1. 2. Forced Transformation

Operator:

    1. 1. assignment operator (=)

if (b=true) if (b) if (c=3) if (3==c)

    1. 2. arithmetic Operators
    2. 3. relational operators (= =)

Common error wording: 1<a<3 1<a&&a<3

    1. 4. logical Operators

&&, | |,!

&,| 3&4

    1. 5. Bitwise operators

&,|, << (shift left one is equivalent to multiplying by 2 ),>>> ( shift right one is equivalent to dividing by 2)

3*4

    1. 6. Extension Operators

+=,-=,*=,/=,%=

    1. 7. three mesh operator

( boolean expression)? A:B

Control statements:

    1. Sequential structure
    2. Select structure

A) If

b) If Else

c) If else if ... else

d) switch multi-value selection expression: int or Char/short/byte, enumeration

Break problem

    1. Loop structure

A) While judging after execution

b) for

c) Do and judge after first execution

Break: Force the entire loop to terminate

Continue: End this cycle and continue the next time!

Object-Oriented Basics:

    1. The evolutionary History of objects

A) No data management era for basic data type stage data

b) More array data to put together the same type of data in a weak management

c) The structure of the data is much, the data is complex. Put different types of data together for strong management

d) The object data is many, the type is complex, the behavior is complex. Put different types of data together to manage it very strongly

Objects and classes:

The object is concrete, and the class is abstract. Class is also a template, through the class template we can also new

Object.

To define a class:

Public[Microsoft User 1] class name [Microsoft User 2] {

Property

Private data Type property name; It is recommended to add the appropriate getter, setter method

Method

Construction method

}

Construction Method:

    1. The method name must be consistent with the class name
    2. No return type
    3. Called by new.
    4. No parameter constructor problem:

A) If we do not manually define the constructor, the system will automatically add an argument-free constructor for us

b) If we define the constructor ourselves, the system will not add the parameterless constructor for us

    1. The first sentence of the construction method is always: Super, which is the constructor that calls the immediate parent class.

A) sequence of constructed method invocations with inheritance relationships

overloading of methods (overload) :

Two identical (the same class, the same method name) three different (the parameter list is different:; type, number, order)

is the return value different, which makes up the overload? No

The formal parameter name is different, does the composition weigh in? No

This

In the normal method, the object of this method is called.

The object that is being initialized in the constructor method.

can also be used to invoke other constructor methods

Super

Static

The variables and methods modified by it become static variables and static methods. belongs to the class. Called by the class name. is actually stored in the method area.

Package

The package must be in the first sentence of a non-commented line.

Package Name: Domain name to this write

Import

Introduction of external classes

Import static: The properties of the imported class

Final

Modifier variables: Constants (Naming conventions: All caps, separated by underscores between multiple words)

Modification method: cannot be overridden

Modifier class: Cannot be inherited

Three main features of object-oriented:

Packaging

Encapsulates a property or method by using the private, default, protected, public keywords.

"High cohesion, low coupling"

Inherited

Through extends. Two benefits:

    1. Code reuse
    2. More accurate modeling of the real world through inheritance

Class has only single inheritance, no multiple inheritance like C + +

method Override (override) The main points:

=: Method names remain consistent

>=: The subclass permission modifier can be greater than or equal to the parent class.

<=, <=: The return value type of the subclass is less than or equal to the type of the parent class. The subclass declares that the exception type cannot exceed the type of the parent class.

Object class:

    1. 1. is the foundation of all our classes
    2. 2. toString
    3. 3. equals, Hashcode
    4. 4. wait, notify, Notifyall

Polymorphic (polymorphism)

Three prerequisites: Inheritance, Method overrides, parent-class references to child-class objects

dynamic binding , static binding:

Abstract class:

    1. Classes that contain abstract methods [Microsoft User 3] must be abstract classes.
    2. Abstract classes cannot be new.
    3. Abstract classes can include: common methods, member variables, construction methods.

Interface:

    1. Interface
    2. Class implementation interface: Implements can implement multiple interfaces
    3. Interfaces can inherit multiple
    4. A set of specifications for an interface definition! Implement the real world logic: if you are ... You must be able to ...

Memory mechanism:

Stack

    1. Store local Variables
    2. Can not be shared by multiple threads
    3. Continuous space, fast speed

Heap

    1. Storing objects
    2. Can be shared by multiple threads
    3. The space is not continuous, the speed is slow. But flexible

Method area

    1. Information for storing classes: code, static variables, string constants, etc.
    2. Can be shared by multiple threads
    3. The space is not continuous, the speed is slow. But flexible

Garbage collector (GC garbage Collection):

    1. Programmers cannot call the garbage collector. However, recycling can be recommended through System.GC ().
    2. Finallize: General also does not use the tune

[Microsoft User 1]public class name needs to be the same as our file name

[Microsoft User 2] capitalize first letter

[Microsoft User 3] abstract methods must be overridden by the quilt class!

Java Basic Notes

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.