Basics of Java Start

Source: Internet
Author: User

Chapter I.

Compile the Java file into a class file:

Edit the Java code in Notepad-----Modify the file name of the. java file----Open cmd---The file path where the file is located such as f:----executed in the command window

Javac file name. java--Execute Command: Java file name

The package name is lowercase, the class name is capitalized, and the class name is. java file name to be exactly the same, is \ n Note not/

Use the Javac file. Java command compilation, followed by the Java class name to execute the resulting class file

Chapter II

Naming rules for identifiers: (camel name) variable name, method name the first word in lowercase followed by the first letter of each word capitalized

Three kinds of comments: single line, multiple lines "Hold down SHIFT mouse click to start end, ctrl+shift+/", text comment

Scan class Library: Scnner input=new Scanner (system.in);

Get input content: answer= input.next ();

Boolean flag= input.hasnextint (); Determines whether the input value is an integer, returns true, otherwise false

Know 8 basic data types (Byte,short,int, Long,float,double,char (a=97,a=65), Boolean) exist in the stack

Reference data types: arrays, classes, interfaces (in the heap)

Byteàshortàintàlongàfloatàdouble

Char

Char can be automatically converted to an int type the higher the number of storage bits, the higher the level of the type

/*int age1=19;

Char sex= ' female ';

int result=age1+sex; Note that int and char types are added automatically to the advanced int type, with the result int type

SYSTEM.OUT.PRINTLN (result); */

The relational expression of the relational operator results in a Boolean value

logical operators and &,|,!

Priority level:! > & > ^ > | > && >| | (Short-circuit && if the previous one does not set up the back of the not to participate in the operation)

A null value cannot be used to determine equivalence by the Equals method;

Ternary expression: Condition? Expression 1: Expression 2 (condition is true for expression 1, condition is false execution expression 2)

Short S=1, s2=4; Short s5=s+s2; Two variables of the short type can be added) (s=s+8; error)

String. Equals compares a value (cannot be null), = = compares the address of a string

Chapter III

1.Switch: (conversion)

Switch (int mingci) {//accelerator alt+/+ Enter

Case 1:system.out.print ("Attending MIT one months of summer camp") break;

Case 2:system.out.print ("Send Notebook") break; Jump out of the loop

Continue//Continue the next cycle

Default: The default content is executed only if all of the case does not match

}

Switch in the judgment, jdk1.7 cannot be a string, can be Int,enum,char (can be automatically converted to int)

while (condition) {loop body} executes when condition is true, the straight condition is false

Note: Do...while (); There is a semicolon after the end

for (int i=0;i<10;i++) {loop body;}

Program Debugging Issues:

1. Double-click Add Breakpoint--à2. Press and hold the bug or F12 to start debugging---à3.f6 Single step Debugging (F5 stepping in, jumping in the inside of the program, such as entering the method)

    1. Enhanced Foreach Loop (for score:scores) {System.out.print (score) in Java;}

for (int i:scores) {system.out.print (I)}

The difference between a for loop and a foreach loop:

    1. The For loop needs to know the number of cycles, and foreach does not need to know the number of loops
    2. foreach is used to iterate over arrays and collections using a simpler
    3. The Foreach loop syntax is simpler, requires no subscript, no assignment statements, no loop conditions, no iteration statements, and these operations have a system to manipulate
    4. Foeach Loop do not attempt to change the value of an array element because the array element is assigned a temporary variable

The function of the 2.Return statement:

    1. Ends the execution of the current method and exits
    2. Returns a statement that calls the method

Fourth Chapter

1. Arrays are contiguous in memory (the elements stored in an array can be either basic data types or reference base data types and must be of the same data type)

(1) int scores[]={1,2,3,4}; or int[] scores={1,2,3,4};

Int[] a={3,5} does not specify a length when defining an array,

(2) int[] A=new int[]{1,2,3}; The length is not specified when initializing an array

(3) int[] A; A=new Int[5]; A[1]={2};

An array is a variable that stores a set of data of the same data type

The subscript of the array starts with 0;

Compile errors and run-time exceptions for arrays;

2. Use of two-D arrays

Definition and initialization of two-dimensional arrays:

Int[][] Scores=new int[5][5];

Int[][] scores={};

Int[][] Scores=new int[][]{{1,2}, {1,3},{3,4,4}};

Arrays class is an extremely common method:. Equals (Array1,array2); Compares two arrays for equality

. sort (array); ascending arrangement of arrays

. toString (); array converts arrays to a string

. Fill (array,val); Assigns all elements of array arrays to Val;

. CopyOf (array,length); Copies an array of arrays into a new array of length

. BinarySearch (array,val) query element val subscript in array

3. The data type in the array must be "uniformly" automatically converted to the same data type

Int[] array={2,4, ' a '}

Sixth chapter

1. Object-oriented

Class and object relationships: abstract and concrete relationships

Class name must be uppercase

Member variables have default initial values;

OOA Object-Oriented Analysis Ood object-oriented analysis

2. Object-Oriented Advantages:

1. Consistent with human thinking habits,

2. Information hiding, improving the maintainability and security of the program

3. Improved reusability of the program

Class members consist mainly of two parts: member variables and member methods

3. Advantages of method overloading: You can use different implementation methods depending on the parameters, and do not need to write multiple names, just remember a method name

Overloaded Condition: Method name is the same, parameter list is different (parameter number and parameter type are different,

Parameters are of the same type and number, in different order)

4. The difference between a member variable and a local variable:

    1. Different scopes
    2. The initial value is different (for a member variable if it is not assigned an initial value in the class definition, Java gives her a default, the base data type is 0, the reference data type is NULL, but Java does not assign a value to the local variable must be assigned after the initial value)
    3. Local variables with the same name are not allowed in the same method
    4. Local variables can have the same name as member variables, and local variables have higher precedence in use

5. Construction method: If one or more constructor methods are customized, Java does not automatically add the default constructor method

1. The construction method must be the same as the class name

2. No return value type

3. Used to create objects, initialize data

Use of 6.This Keywords:

    1. Use this to call member variables to resolve conflicting names of member variables and local variables

person (int age) {This.age=age}

    1. Use this to call the Member Method This.work ();
    2. Use this to invoke the overloaded construction method, which can only be used in the constructor method, and must be the first statement of the constructor method

Public Penguin (String name,string sex) {this.name=name;this.sex=sex;}

Public Penguin (String name,int health,int love,string Sex)

{This (name,sex); this.health=health;this.love=love;}

This can only call member properties, instance methods, constructor methods, cannot call class variables and class methods, and cannot call local variables

This can call class methods and class variables :

This can call a class variable, but the class method needs to be called through the class name. class method. This is a pointer to the current object, and the object is an instance of the class, so this is pointing to a current instance of a class, not to the class itself

7. The role of encapsulation:

    1. Avoid the effects of external operations
    2. Improved loose coupling and code reuse

Encapsulation Concept: Privatize properties and provide public methods to access private properties.

8. The role of the package:

Organization of the 1.java file

2. Managing Java Files

3. Resolve file name issue

4. Also an access control mechanism

The tools used below the Java.lang package do not need to be imported and can be referenced directly

9. Access modifiers

Modifier

In the same class

In the same package

In subclasses

Any place

Private

Yes

No

No

No

No access modifier

Yes

Yes

No

No

Protected

Yes

Yes

Yes

No

Public

Yes

Yes

Yes

Yes

10. Declare the member variable in the class:

Member variable can be a member variable of class type

public class student{

Private person person; A member variable in a class that defines a reference data type

}

Seventh Chapter

1. Inheritance: A way to enable a Class A to directly use the properties and methods of another class B

Class A can have its own properties and methods

2. Inherited syntax:

Modifier class Subclass extends Parent class {//class definition part}

What the subclass inherits from the parent class:

    1. Inherit public and protected decorated properties and methods, regardless of whether the subclass and parent class are in the same package.
    2. Inherit the properties and methods decorated by the default permission modifier, but the subclass and parent must be in the same package

Subclasses cannot inherit:

    1. Properties and methods for private adornments cannot be inherited
    2. Unable to inherit the parent class's construction method
    3. The subclass is not decorated with the parent class in the same package using the default access modifier (friendly)

If the method inherited from the parent class does not meet the requirements of the subclass, the parent class can be overridden with the same name method in the child class.

    1. Override of method or override of method (overriding)

A method of inheriting a parent class based on requirements in a subclass is rewritten

    1. Conditions for overriding the composition method:

1. Must have the same method name

2. Must have the same parameter list

3. The return value type must be the same or its child class

4. Cannot narrow access to overridden methods

What is the difference between overloading (overloading) and overriding (overriding):

Overloading involves a method of the same name in the same class, requiring the same method name, with different parameter lists, regardless of the return value type

Overrides involve a method of the same name between the subclass and the parent class, requiring the same method name, the same argument list, the same return value type, or its subclass

Use of 5.super Keywords:

Super represents the default reference for the immediate parent class object of the current object

The super must be in the subclass (the generic method of the subclass [Super. Method name] and the constructor method) instead of the other location.

Super and this cannot be present in a single construction method

Super refers to the parent class:

    1. Call the parent class member: member variable, member method, by Super.xxx

2. Call the Parent class constructor method, through super (), must appear in the first sentence of the constructor method

Used to access the members of the parent class, such as properties of the parent class, methods, construction methods

Restrictions on access permissions, such as inability to access private members through super.

    1. Calling rules for constructing methods under inheritance conditions:
      1. Rule one: If the constructor method of a subclass does not call the constructor of the parent class with a parameter in the super display, and does not call its own other construction method through the this display, then the default constructor method of the parent class is called first, in which case the "super ()" is written, and the statement effect is the same.
      2. Rule two: If the constructor method of a subclass is called by the super display to call the parent class's parameter constructor method, that will execute the parent class corresponding constructor method, but does not execute the parent class no parameter constructs the method
      3. Rule three: If the subclass is constructed by using this to display other constructor methods of itself, the above two rules are applied in the corresponding construction method.
      4. In the inheritance condition, the execution of the code executes the parent class without the parameter construction method after the child class is recalled, in a class, the parent class property is loaded first, then the parent class constructor method is loaded, then the subclass property, and the last subclass constructs the method

Construction method cannot loop nested calls

    1. The Equals () method of Object

Equal property values: Two objects with the same type, same property

Same Reference object: Two references point to the same object, that is, to the same address

Note: If you simply use the Equals () method of the object class to compare objects with the same reference object, then there is no difference between the operator "= ="

    1. A class construction method is always executed in the following two cases:
      1. Create an object of the class (instantiation)
      2. An object that creates a subclass of the class (instantiation of the child class)

Access modifiers

8. Class Diagram:-sex:string

    1. Polymorphic

The term "polymorphic" usually means that it can present many different forms or patterns. He means that a variable of a particular type can refer to different types of objects and can automatically invoke methods of referenced objects.

The rewrite of the method is the basis for implementing polymorphism.

10. Rules when a subclass is converted to a parent class:

    1. To point a reference to a parent class to a subclass object, called up conversion, to automatically type conversions
    2. The method that is called by the parent class reference variable is a subclass that overrides or inherits the parent class's method, not the parent class's method
    3. You cannot call a method that is unique to a subclass by referring to a variable from the parent class

11. The requirement for downward transformation is also used for interfaces and abstract (normal) parent classes

12.Instanceof implementation (Boolean Flag=pet instanceof Dog)

When using instanceof, the object must be of the same type as the large class specified after the instanceof argument, or a compilation error will occur.

13. The advantages of polymorphism:

    1. Replaceable: polymorphic to existing code with replaceable lines
    2. Extensibility: Polymorphism has extensibility to code, adding new subclasses does not affect the polymorphism of existing classes, inheritance, and the operation and manipulation of other features, in fact, the new subclass more easily get polymorphic functions.
    3. Interface: Polymorphism is a parent class that provides a common interface to subclasses, which are implemented by subclasses to refine or overwrite.
    4. Flexibility: Multi-state in the application of flexible and diverse operation, improve the efficiency of use
    5. Simplification: Polymorphism simplifies the process of coding and modifying the application software, especially when dealing with the operation and operation of a large number of objects, which is particularly prominent and important.

14.final decorated class, cosmetic method, cosmetic property

Modifier class, can no longer be inherited

Modification method, cannot be overridden by quilt class

Modified variables become constants and can only be assigned at initialization time (each letter of the word is capitalized)

Use of 15.static

Decorated property: Called with the class name. Property name

Non-static properties cannot be used in the static method;

Modified Static code block:

1. Static code Cubby The construction method executes first, the execution order is to load the static code block in the parent class first-after loading the static code block in the subclass, then executes the constructor method of the subclass after executing the parent class constructor method

2. Static code blocks in a class no matter how many objects are created, only the first time that you run the static code is fast

3. Static methods in the calling class in the main function will also execute the code base in the class first

4. The static code base is executed when the object is created

16. Polymorphic Use:

1. Parent class pointing to child class object

2. The formal parameter as a method

3. The return value as a method

18.return returns many different types of variables, using variable parameters of a variety of indeterminate types

1. You can define a parameter that returns a object[] type

2. You can define a class in which properties in a class are defined as properties of different types, assigning different types to properties

public class Master {

public void Feed (pet pet) {

if (pet instanceof Dog) {

System.out.println ("*********8");

}

}

public void Methad (int[] a) {

}

public void methad1 (int ... IS) {

}

public void Methad2 (String s,int ... IS) {

}

public void Methad3 (object...objects) {

}

public void Methad4 (object[] a) {

}

Public Pet getpet (int money) {

Pet Pet=null;

if (money>10) {

Pet=new Dog ();

}else if (money>5) {

Pet=new Penguin ();

}

return pet;

}

8th Chapter

1. Abstract class

    1. Abstract classes cannot be instantiated
    2. The abstract modifier cannot be used with the final modifier.
    3. Abstract methods that are modified by abstract have no method body
    4. Private keyword does not modify abstract methods
    5. The abstract keyword must be between the access modifier and the return value type
    6. A class that inherits an abstract class must override all inherited abstract methods, unless it is also an abstract class

2. Abstract classes and interfaces

1. Difference: The ordinary method must have the method body, the abstract method cannot have the method body, the abstract method must have the abstraction modification.

2. Abstract classes cannot create objects, ordinary classes can create objects

3. An abstract class is a class that cannot be instantiated, it can have an abstract method or a common method

4. Abstract class is easy to reuse, interface facilitates code maintenance

5.Public abstract class person () {abstract method, or normal method}

3. Interface: is a type that cannot be instantiated and can have only abstract methods

1. Only abstract methods can be used with the Interface keyword interface

2.Public Interface Person () {abstract method}

3. The variables defined in the interface are the common (public) static (static) final (final) constant (must be assigned the initial value)

4. The method defined in the interface is by default the abstract (public) method

5. The method in the interface must have a return value type

6. Interface static does not modify the methods in the interface

7. The final decoration method cannot be used in the interface

8. There is no construction method in the interface

9. Interfaces can inherit multiple interfaces, but interfaces cannot inherit classes

Interfaces are for behavioral purposes.

Multi-use combinations with less inheritance

Programming for interfaces, not relying on specific implementations

Open for expansion, closed for change

4. Why the methods in the interface do not have to be abstract, because only abstract methods in the interface do not have to be modified with abstract

Rules:

    1. Abstract classes and interfaces cannot be instantiated
    2. where abstract classes and interfaces are inherited and implemented separately, their subclasses must implement the abstract methods
    3. The access modifier for an abstract method in an abstract class cannot be private, the access modifier for a normal method in an abstract class can be private, and the access modifier for an abstract method in an interface must be public

5.implement Implementation Interface

1. Implementing an interface must implement all the abstract methods inside the interface

2. A class inherits a parent class at the same time, extends before, implements in the middle after the comma, separated must implement all the methods inside

3. The inheritance in the interface, with the extends keyword, the interface can inherit multiple interfaces, the inherited multiple interfaces separated by commas

6. When a subclass inherits a parent class and implements multiple interfaces:

1. Call the fields and methods in the parent class using SUPER.XXX

2 calling the fields and methods in the interface with: Define a member variable of an interface type in a subclass, use a variable of the interface type to go to the fields and methods in the interface

7. Anonymous inner class:

Anonymous inner class refers to a parent class that is an abstract class that creates an object of the parent class type in the main method within Test and overrides all the abstract methods in the parent class.

The wording in the parent class Cook cook=new Cook () {Rewrite the abstract method in the parent class here, or add your own method, see Book1selfstudy-oop-test3}; There's a semicolon behind.

8. Internal class See Book1selfstudy-oop-test2}

Calling the properties of an external class in an inner class Kitchen.this.XXXX method with an external class name

An abstract class can have a construction method,

9th Chapter

1. Classification of exceptions:

Object is the root class of the exception, followed by the Throwable as the parent class of the exception class, divided into

    1. Error is a Java Virtual machine exception
    2. Exception exception class, exception class is divided into Sqlexcepton and runtimeexception, etc.

2. Common Exceptions:

1.ArithmeticException Calculation exception

2.ArrayIndexOutOfBoundsException array out of bounds exception

3.NullPointException NULL pointer exception

4.ClassNotFoundException did not find the corresponding class file (may not have imported the appropriate jar package)

5.NumberFormatException Data formatting exceptions (exceptions that do not convert numbers to numeric formats)

6.inputMismatchException Array data mismatch exception (user input type does not match type in data)

The 7.IllegalArgumentException method received an illegal parameter

8.ClassCastException object coercion type conversion error

3.try {}catch () {The exception to catch is to match the exception to occur}

4.try {}--catch () {}--finally{} statement structure

1. If there is a return statement in a try or catch, the program executes the code in the finally statement, executes or executes the return statement, or return in the try {}catch{} statement if the Ruturn statement in finally is not executed.

2. In the TRY-CATCH-FINALLY statement structure, the TRY statement block must exist, and the catch and finally statement blocks are optional, but at least one of them appears.

5. Termination of the application, System.exit (0); normal exit

System.exit (-1); Non-0 number is abnormal exit

Exception handling in 6.java is achieved by 5 keywords

Try

Catch catch exception

Finally the code in the finally statement block is always executed, regardless of whether an exception occurs, except in the case where the exception handling code executes SYSTEM.EXIT (1) Exits the Java Virtual machine

Throw

Throws

Throws declares the various exceptions that the method might throw,

Throw throws an exception manually

E.printstacktrace ();//Print Stack exception information

The difference between 7.throw and throws:

1. Different functions: Throw for the programmer to generate and throw an exception, throws in and declare the method throws an exception

2. In different locations, throw is inside the method body and can be used as a separate statement; Thorws must be followed by the method parameter list and cannot be used alone.

3. Different content, throw throws an exception object, and can only be one; throws is followed by an exception type, and can be followed by multiple exception classes.

8. Custom exception: throw new Custom Exception class name ("Exception Reason");

Basics of Java Start

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.