Java Basics Review 1

Source: Internet
Author: User

Jre:java Operating Environment

Jdk:java Development tools (including JRE)

Java two major mechanisms: JVM (Java Virtual machine)

Garbage collection

Categories of variables:

1. Divide by data type:

1) Basic data type: 8 kinds

Integral type: byte short int long

Float type: Double float

Character type: Char

Boolean Type: Boolean

2) Reference data type:

Classes: Class

Interface: interface

Array: []

====================

Negative number modulo:

-38%3=-2

38%-3=2

& and && differences:

& All conditions must be judged

&& as long as there is one condition not satisfied then false stop after the judgment

The << and >> bitwise operators move the binary numbers around the corresponding number of digits to get the result example:

2<<3 00010→10000 =16

16>>3 10000→00010 =2

& and Operators

16&2 =0

Ternary operators

int max = 100<200?  1:2; Max=1

If there is a public declaration in the Java file Class example: public class student{} source file name and class name must be consistent otherwise compilation fails
There can be multiple classes in a Java file, but only one class of the public type. 、

Array:

Declaration array: type [] varname=null;

Allocate memory space for array: Varname=new Type[length];

The array element subscript starts at 0.

How to assign a value to an array when it is created:

int n1[]={1,2,3};

int N2[]=new int[]{1,2,3};

Error mode: int n3[]=new int[length]{2,3,4};

Classes and objects:

Three main features of object-oriented: encapsulation inheritance polymorphism

Every class in Java has at least one constructor. If no constructor is written, the system will default to a parameterless constructor public Student () {} Once the definition of one or more constructed methods is displayed the system will no longer provide the default constructor method.

The primary role of the constructor is to initialize the properties of the object

Formal parameters and arguments:

Overloads of the method:

A method with the same name can be overridden by varying the number of arguments or by different parameter types.

Override of Method:

Variable number type return value must be the same

The subclass method must not have access to a smaller class than the parent

void Add (int a,int b) {}

void Add (int a,int b,int c) {}

void Add (String a,int b) {}

Inheritance (solves the redundancy of the Code):

Subclasses inherit the variables and methods of the parent class but cannot inherit the private member variables and methods of the parent class

Super

is a reference to the parent class object in the Child class object method

Use: 1. Calling a member of a parent class object in a subclass method

2. Constructor example of a parent class called by Super (parameter) in a subclass super ("Mouse", 55);

By default, the sub-class calls the constructor of the parent class without a parameter if the parent class writes a constructor with a parameter, the system no longer provides a default constructor and the constructor for a parent class must be called in the child class

Polymorphic:

A variable of the parent class type points to a subclass object, and the method that is easily overridden in the calling parent class is a polymorphic

The newly added method of subclasses cannot be called in polymorphic situations

The object can be cast in polymorphic situations and can be cast only if there is a parent-child relationship

Compare strings with Equals ()

Static method cannot call a non-static variable non-static method can call a static variable

List mode:

1. Privatization of constructors

2. Static the object private

3. Provide the public get method of the object for external use of the object

public Class A single {
Private single () {}
private static Single Instance = new single ();
public static single Getsingle () {
return instance;
}
}
public class TestSingle {
public static void Main (string[] args) {
Single Instance1 = Single.getsingle ();
Single instance2 = Single.getsingle ();
System.out.println (INSTANCE1==INSTANCE2);//true

}
}

Final: Is the final attribute cannot be modified that is constant

The final variable must be initialized at the time of declaration or initialized in a non-static code block or in a constructor.

Abstract Abstraction:

Classes with abstract methods must be abstract classes abstract classes do not necessarily have abstract methods

Abstract classes cannot be instantiated

The abstract method has no method body only method is affirm

Interface:

An interface is a collection of abstract methods and constants that cannot have any other component

The method in the interface defaults to public abstract

The default decoration for constants is: public static final

Interfaces can inherit between

Inner class:

Exception handling:

1. Array subscript out of bounds exception

2. Mathematical anomalies

3. Type Conversion exception

4. Null pointer exception

Catch can be followed by multiple catch but the parent class cannot be preceded

The finally statement is bound to execute try () {} and can be directly followed by finally

The throws keyword throws an exception that can throw multiple exceptions at the same time between multiple uses, split.

Overriding methods cannot throw exceptions that are larger than overridden methods

Java Collection

Set: Unordered non-repeatable collection

List: An ordered and repeatable collection

Map: A collection of mapped relationships

Statement format for foreach:
for (element type T element variable x: Traverse object obj) {
A Java statement that references X;
}

Set Set:

Unordered cannot be repeated if repeat add fails

HashSet is the most typical implementation of set

HashSet is based on the hashcode () value to hold the element, so unordered
The same criterion for judging two elements is that the Equals () value returns True

HashSet thread is not secure

Linkedhashset Orderly

Java Basics Review 1

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.