JAVA notes-basics, java notes --

Source: Internet
Author: User

JAVA notes-basics, java notes --

Class Structure:

Package name;

Class name extends parent class implenments interface name {

Member variables;

Member method;

Constructor;

}

Class Example:

Public class Hello {// a main function, equivalent to the entry to the idiom public static void main (String args []) {// execute the statement System. out. println ("hello! ");}
} // Public: indicates that this class is public. a java file can only have one public class. // class: indicates that this is a class. // Hello: class Name (the name of a common class must be consistent with the file name) // static // void no response

Annotation

1. member variables

It is generally a basic data type or a reference type (pointing to another class)

2. Member methods (functions)

Public return type method name (parameter list)

{

Statement; // method (function) Subject

}

Parameter List: member function input

Return type (data type): indicates the member function output.

Method (function) Subject: indicates to implement a function code block

Note: The return type and return result type must be the same.

3. Constructor

Purpose: Initialize the new object.

Features: The method name and class name are the same and there is no returned value. When a class object is created, the system automatically calls the constructor of this class to initialize the new object.

Differences and relationships between classes and objects

1. Classes are abstract, conceptual, and representative of a class of things.

2. objects are specific and actual, representing a specific thing

3. A class is an object template, and an object is an entity of a class.

Two methods for creating an object

1. Declare and create again

Object Declaration: Class Name Object Name

Object creation: Object Name = new Class Name ()

2. One-step approach

Class Name object name = new Class Name ();

Object Access member variable method

Object Name. variable name;

Differences between heavy load and rewriting

Heavy Load

Simply put, a function or method has the same name but the parameter list is different. Such functions or methods with different parameters of the same name are called overload functions or methods.

Rewrite

Rewriting refers to the situation where two methods with the same names and parameter lists exist in the subclass and parent classes of Java. Because they have the same method signature, the new method in the subclass will overwrite the original method in the parent class.

 Bitwise AND shift operations

Java has four bitwise operations: bitwise AND &, bitwise OR |, bitwise XOR or ^, and bitwise inversion.

The calculation rules are as follows:

Bitwise AND &: both are 1, and the result is 1.

Bitwise OR |: one of the two is 1 and the result is 1.

Bitwise OR: one or two digits have 0 digits, one is 1, and the result is 1.

Bitwise inversion: 0-> 1, 1-> 0

Java has three shift operators:

>>,< Arithmetic right shift and arithmetic left shift

Calculation rules:

Right Shift of arithmetic: low Overflow, the symbol bit remains unchanged, and uses the symbol bit to fill the overflow high

Arithmetic shift left: The symbol bit remains unchanged, and the low position is 0.

>>> Logical right shift

Low overflow, High Fill 0

Note: The computation is based on the complement code.

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.