Java Fundamentals Point Summary 1

Source: Internet
Author: User
Tags arithmetic operators float double logical operators modifier modifiers switch case try catch

> Identifiers: All names and similar distinctions are easy to call
Naming rules: composed of a number of letters _$ cannot be case-sensitive with a number cannot be a Java keyword
Naming conventions: try to increase readability
Class Name: Capitalize all words in the first letter
Variable name/method name: In addition to the first word, other words are capitalized in the first letter
Final constant: All uppercase letters
> keywords: words or characters that are assigned special meanings in Java
static void
byte short int long float double Boolean char
Protected private Public
Static final abstract synchronized
Class interface
instanceof
Try catch throws throw finally
If else for and do break continue return
Switch case Default
{} () <> []; : ? ,
> Data type:
First Data property classification and then by space size classification
Integer type: Number with no decimal point
---byte byte type [-128,127] is the smallest unit of Java descriptive data
---short shorter integer 2 bytes
---int integer 4 bytes An integer constant is the int type by default
---Long integer 8 bytes An integer constant followed by a l/l is a long type
Floating-point type: A number with a decimal point
---Float single precision accounted for 4 bytes floating-point constant after plus f/f is float type
---Double doubles as 8 bytes floating-point type constants are double by default
Character type: all symbols
---Char character 2 bytes A constant of type char must have a single quote and only one character
Boolean type: Only two options are available and the opposite is the case
---A boolean boolean of 1 bytes true, False
> Number Type Conversions
Automatic type conversion Situation one: high precision variable = low precision data;
float f1=12;
Automatically converts 4 bytes of int type 12 to float type 4 byte 12.0f
Automatic type conversion Situation two: Byte, short,char type variable =int constant value;
BYTE b1=13;
Detects if the B1 can load 13 will automatically convert the 4 byte int 13 to 1 bytes byte of type 13
Short s1=999999;
Detection S1 can not be installed 999999 no longer convert direct error
Forced type conversion: low precision variable = (low precision variable type) high precision data;
int i1= (int) 12.3;
> The data type of the result after the operation
1 byte short char cannot participate directly the operation must be converted to int to participate in the operation
The data type of the result after the 2 operation depends on the data with the highest precision ' 1 ' + (byte) 12+12+12.5
> Operators
1 arithmetic operators: +-*/
% of the remainder modulo n%m=n divided by M to get an integer in addition to the endless part
4.5%1.1=0.1
+ +-Self-increasing self-reduction
A++;++a; fully equivalent to a= (the type of a) (a+1);
b=a++; fully equivalent to b=a;a++
B=++a; fully equivalent to a++;b=a;
int I=2;//3
int j= (i++) + (I/++i) + (-i) + (i--) + (++i*2) +i/3;
2 + 3/4 + 3 + 3*2+3/3
+ + is the first to participate in this operation before
+ + After participating in the operation after the first
+ String connector
The data is then concatenated with the string to form a new string
2 comparison operators: > >= < <=
! = is not equal to judge whether the data on both sides is unequal
= = constant equals to determine whether the data on both sides is equal
3 assignment Operator: = assigns the value on the right side of the equal sign to the left variable
A+=b; fully equivalent to a= (the type of a) (A+B);
A-=b; fully equivalent to a= (a type) (A-B);
A*=b; fully equivalent to a= (the type of a) (A*B);
A/=b; fully equivalent to a= (a type) (A/b);
A%=b; fully equivalent to a= (the type of a) (A%B);

Short s=12; s=s+1;
Short s=12; S+=1;
4 Logical operators:
& && and two as long as there is a false result is false
| || Or two as long as there is a true result is true
^ Xor the same or false on both sides is true
!
The difference between single and double:
Same: As logical operators & and && | | | The results are all the same
Differences: (1) A logical short-circuit when the first expression knows the result, the second expression no longer executes the result directly
(2) The binary of a number that can also be manipulated as a bitwise operator
5-bit operator: (binary of the manipulated number)
>>
<<
&
|
^
63-Tuple Operator: Boolean type of data? value 1: Value 2

> Process Control:
Sequential structure: From left to right from top to bottom
Select structure: Code writing specification snapping indent
if () {}
if () {}else{}
if () {}else if () {}else{}
SWICTH (expression) {
Case value 1:
Statement Block 1;
Break
Case Value 2:
Statement Block 2;
Break
Case Value 3:
Statement Block 3;
Break
Case Value 4:
Statement Block 4;
Break
Default
statement block N;
Break
}
Note: (1) The value after the case cannot be duplicated
(2) The data type of the expression value after switch is limited to a byte short char int
(3) Run default only if all case values are not equal to the value of the switch expression
Independent of its location
(4) Break function is to end the entire switch structure

Loop structure:
while () {}
Do{}while ();
for (;;) {}

for (int a=1;a<=10;a++) {
for (int b=1;b<=10;b++) {

}
}
Jump:
Continue: End this cycle continue i++ the next cycle
Break: End the entire loop
Arrays: Containers with the same type specifying several data
Must be created explicitly: what (element type) is loaded (number of elements)
Keywords: []
Create array format: (1) element type [] Array name =new element type [number of elements];
(2) element type [] Array name =new element type []{value 1, value 2, value 3 ...};
(3) element type [] Array name ={value 1, value 2, value 3 ...};
Maximum value:
Define the value of the variable record maximum value to assign the initial value to the first element
int max=arr[0];
Compare Max with other elements of the array
for (int i=1;i<arr.length;i++) {
max=arr[i]>max?arr[i]:max;
}
Array sorting:
Sequential ordering: Compares the current element and all the elements behind it, in turn
for (int i=0;i<arr.length-1;i++) {
for (int j=i+1;j<arr.length;j++) {
if (Arr[i]<arr[j]) {
int k=arr[i];
ARR[I]=ARR[J];
Arr[j]=k;
}
}
}
Bubble sort: Compare adjacent elements in turn
for (int i=0;i<arr.length-1;i++) {
for (int j=0;j<arr.length-1-i;j++) {
if (Arr[j+1]<arr[j]) {
int k=arr[i];
ARR[I]=ARR[J+1];
Arr[j+1]=k;
}
}
}
Insert sort: Assuming that the preceding element is ordered sequentially, the current element is inverted and the element preceding it is compared
for (int i=1;i<arr.length;i++) {
Define variables to record the current element
int k=arr[i];
Defines the subscript for the preceding element of a variable record
Int J;
for (j=i-1;j>=0;j--) {
if (K>arr[j]) {
ARR[J+1]=ARR[J];
}else{
Break
}
}
Put K in the j+1 position.
Arr[j+1]=k;
}

Object-oriented 567
Object-oriented: Find an object that has the ability to help me solve the problem the command object solves the problem
Eg: Find a restaurant to eat
Process-oriented: the process of solving the problem is divided into several steps to complete each step by action
Eg: Cook your own food
Pros: > Simplifies complex issues
> Programmer's role transformed from performer to conductor
> more in line with the way people think now
To use the object-oriented writing procedure:
(1) Creating classes to describe a class of things
Extracting data from a surface to make member variables
Extracting dynamic functions to make member methods
(2) Create an object from a class: The Class Name Object name =new construction method;
A class defines those member variables that directly determine which properties the object owns.
The member methods defined in the class directly determine which of the objects have those functions
(3) Assigning values to an object's properties
(4) method of invoking the object to solve the problem

Class: A description of a class of things is a design sheet template for creating objects
Object: An example of a model class in the computer of a real thing

Member: Member variable member method (constructor method normal method) inner class static code block construction code block

member variables and local variables:
(1) The location of the definition is different
(2) different scopes
(3) Whether there is a default initial value
(4) different modifiers

overloaded: Several methods in a class have different names for the same parameter list
Requirements:The same parameter list must be different for the same class method name (parameter number different parameter type different parameter order)
rewrite: The method of the parent class cannot satisfy the subclass's requirements subclasses redefine the existing methods of the parent class according to their own requirements
Requirements:except that the range modifier can be expanded to throw less small exceptions other method declarations must be exactly the same as the parent class
Difference:> different Locations: Overloading is overridden in a class that occurs in a subclass
> Requirements: Overload requirements: The same class method name must be different for the same parameter list
Rewrite requirements: Except that the range modifier can be expanded to throw less small exceptions other method declarations must be exactly the same as the parent class
> Impact Differences:
Overloaded methods do not respond to each other: simply by using the method parameter list to differentiate
Subclasses override methods of the parent class the method of the parent class is hidden

Construction method: The method that is called when the object is created
The difference between a construction method and a common method:
> Different format: Construction method no return value without void label
> Different: The construction method works by creating objects
An ordinary method represents a specified function of an object of this class
> Call Different: Construct a new object called once by the keyword new call
An object called by an object can be called more than once by an ordinary method
> Naming differs: Constructor method name must be the same as class name
Common method names can be class names (cannot be class names by specification)
> Whether there is a default: A class does not have a constructor method that adds a parameterless constructor by default

Create object memory graph:
> class load If the class has static members also create a static zone
> Create reference
> Create object:
>> via super (12,11) Loads the members defined in the parent class into the subclass object memory

>> run the parent class through Super (12,11) other statements in the constructor method
>> through the subclass constructor method the member defined in the class is loaded into the subclass object in memory

> > Hide a member of the parent class that is redefined
>> Run sub-class constructs other statements in the method
> References to objects created

static modifier
Statically decorated members: static member class members
Member without static decoration: instance member
static modifier variable: class variable shared data
> static modifier variables can be called directly by the class as well as by the object
> static modifier variable An object that changes the value of this property other objects this property value is changed
Static Modification method
> Static modifiers can be called directly by the class as well as by the object
> Static decoration method can only call a Statics member

This
Use scenario One: variable names default to local variables when the name of the member variable and local variable is the same
Use the this variable name to point to the member variable
Note: All members are preceded by this. (Current object)
Use Scenario Two: One constructor method calls another constructor method (multiplexing its method body)
Invokes the specified construction method through this (argument list)
Note: This (parameter list) must be the first statement

Inheritance: Extends
When a new class has all the members of an existing class, you can have this new class derive from the existing class
Format: Class Zi extends fu{}
Characteristics:
> Subclasses can inherit all members of the parent class
> subclasses can inherit private members of a parent class but cannot use it directly using other methods that can only be passed through the parent class
> Subclasses cannot inherit the construction method of the parent class
> subclasses can have members that are unique to subclasses
> subclasses can redefine members of a parent class
Redefine the member variable of the parent class: requires the same variable name
To redefine a member method of a parent class: overrides except the range modifier can be expanded to throw less small exceptions other method declarations must be exactly the same as the parent class
> The first statement of all child class construction methods calls the parent class without arguments by default construction method
Invoking the constructor of the parent class with arguments by super (argument list)
>java only supports single inheritance of classes

Polymorphic:
What is polymorphic: A parent class name for a subclass object
What are the characteristics of polymorphic objects: In addition to overriding the method, the other is exactly the same as the parent class object
How to use polymorphism:
Defining a method parameter list when defining a method return value type when defining a member variable of a class when defining an array is defined as a parent class type
This allows you to pass an object that returns an assignment of any subclass type

1 Improve Code reusability
2 Increase the extensibility of the program

Abstraction: Abstract vague information incomplete
Characteristics:
> Abstract method cannot write method body
> classes that have abstract methods must be abstract classes
> Abstract classes cannot create objects can only define references (point to subclass objects)
> subclass Inherits abstract class unless overriding all overriding methods is still abstract
> Abstract classes have constructed methods to load non-abstract methods and member variables into subclass object memory by constructing methods

Interface: interface this abstract class can be defined as an interface when all methods are abstract methods
Features: variable default modifier in > interface public static final
Method default modifier in > Interface public abstract
> Interfaces cannot create objects can only define references (point to an implementation class object)
> class implements interface by keyword implements a class can implement multiple interfaces
> Java supports multiple inheritance between interfaces

Interfaces are used as abstract classes
Interface is an agreement between the two sides.
1 Improve Code reusability
2 Increase the extensibility of the program
3 reducing the coupling between modules

Turn upward
Down transformation
Instanceof Object instanceof Class name
Import
Package



Base Class Library: Common class Library Exception collection thread IO stream socket XML
Common class Libraries:
Object:string toString () Gets the string representation of the current object
Boolean equals (Object obj) to determine whether the current reference and parameter reference are pointing to the same object
* Override Equals method
> method declaration cannot be changed
> Judging by instanceof that the parameter object is not the type of the current class
> Downward transformation
> Return on request
String: Strings are constants: String objects cannot be changed once a sequence of characters is created

Java Fundamentals Point Summary 1

Related Article

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.