JDK: A toolkit for Java developers, including Java development tools, as well as JRE. Among the development tools are the compilation tools (Javac.exe), the Run tool (Java.exe), the Packaging Tool (Jar.exe), and so on.
Jre:java's operating environment, including the core class libraries required for Java virtual machines and Java programs to run.
Jvm:java virtual machines.
The relationship between the two:
jdk=jre+ Development Tools
jre=jvm+ Core Class Library
Java Configuration JDK Environment variables
Java_home C:\Program files\java\jdk1.7.0_21
Path%java_home%\bin;
Use "JAVA–CP Test.jar test" When using the jar package
Remember the first error that is easy to make in a Java program: Java.lang.NoClassDefFoundError
– Beginners often encounter this error and encounter this error, 99.9% of the time, because you forgot in the Classpath
Dropped the required jar package.
– So, with this error, go back to gathered up all your jar packages and then go to the Java community to ask questions
All letters in the keyword are lowercase;
Naming conventions for Java:
Package Name: All letters are lowercase when multiple words are composed, and the domain name is written backwards (com.***.www)
Class name Interface name: When multiple words are composed, the first letter of all words is capitalized
Variable name and function name: When multiple words are composed, the first letter is lowercase, the second word starts with the first letter of each word capitalized
Constant name: All letters are capitalized, and when multiple words are underlined, each word is connected with an underscore
Java Data type:
Byte 1 bytes (8 bits) -2^7------2^7-1 =-128 to 127
Short 2-byte (16-bit) -2^15------2^15-1 3W
int integer 4-byte (32-bit) -2^31------2^31-1 billion
Long 8 bytes (64 bits) -2^63------2^63-1 (plus L)
Float 4 bytes (32 bits) single precision (rear plus f)
Double 8-byte (64-bit) dual-precision
Char 2 bytes
Boolean 1 bytes True false
Coercion type conversion: (Byte) (a+10)--cast a+10 to Byte
Characters and numbers are converted to ASCII numbers and digital computations
In the switch function expression, Java 1.6 (including) used to support data that is equivalent to an int primitive type: Byte, Short,char,int (None of the others). 1.7 new features added can support string types of data.
Method (function):
Attention:
1) method cannot be defined in another method
2) method can call another method
3) method does not return a value without writing the declaration of the return method to write void, write return
4) method does not call do not execute
Method naming rules: If it is a word to all lowercase, if it is two words, the second word is capitalized in the first letter
What is overloading: in the same class, if the method name is the same, the type of the parameter and the number of arguments are different, note that the return value is irrelevant.
Memory Analysis:
Stack memory: For storing local variables, the occupied space is automatically freed when the data is used. Method Run Si cho into the stack memory, when no longer used, only delete the stack memory method, methods in the method area remain.
Heap Memory: Arrays and objects are placed in heap memory by the instance created by new, each entity has a memory address value, the variables in the entity have default initialization values, entities are no longer used, are reclaimed by the garbage collector for an indeterminate amount of time, and the global variables are stored.
Method area (data area): Used for storing methods, divided into static and non-static method areas.
Note: int [] [] arr= new int[10][]; one dimension must have a value to correctly establish a two-dimensional array.
Features of the array:
1) A given size when created (can give 0 but, when printed or assigned, run-time error is reported)
2) Array initial value: int type default 0 float type default 0.0f boolean default False
Char default ' \u0000 ' compared to when ' (null character)
3) array has subscript, and starting from 0
4) Get the property of the array size: array name. length
Maximum value:
int maxelement = a[0];
for (int x = 1; x < a.length; × x + +) {
if (A[x] > Maxelement) {
Maxelement = A[x];
}
}
return maxelement;
Select Sort:
for (int i = 0; i < arr.length-1; i++) {
for (int j = i + 1; j < Arr.length; J + +) {
if (Arr[i] > Arr[j]) {
int min = arr[j];
ARR[J] = Arr[i];
Arr[i] = min;
}
}
Bubble Sort:
for (int i=0;i<arr.length-1;i++) {//control the number of comparisons-1: Because it is 22 compared, the number of comparisons is less than the length of the array 1
for (int j=0;j<arr.length-1-i;j++) {//-1: Because it is a 22 comparison;-I: Every comparison, the last value must be on the last side, so the maximum value will not be compared.
if (Arr[j]>arr[j+1]) {//small put front, big put back
int temp=arr[j+1];
ARR[J+1]=ARR[J];
Arr[j]=temp;
}
}
Binary Search Method:
int min=0;
int max=arr.length-1;
int mid = (Min+max)/2;
while (Arr[mid]! = key) {
if (Key>arr[mid]) {
min=mid+1;
}
else if (key< Arr[mid]) {
Max=mid-1;
}
if (max<min) {
return-1;
}
Mid= (max+min)/2;
}
return mid;
Sort the array:
Arrays.sort () Method: An array is ordered from small to large and needs to be introduced into the package java.util.Arrays
To find an array:
Java.util.Arrays.binarySearch (Object [] arr, object key)//An array is a number to be looked up
There is a return value: If a return subscript is found, no return-1 is found
Note: This method is used at the bottom of the binary lookup method (binary lookup method), so before using this method first sort
Copy of the array:
Java.lang.System.arraycopy (source array name, source array start position, target array, target array insertion position, length to copy)
No return value
Note: If there are 6 in the source array, we want to copy 7 to the target array, and the array subscript bounds the exception.
Process oriented:
Each step by ourselves to complete, shortcomings, low efficiency, not easy to maintain, poor reusability
Object-oriented features: Make complex events simple
From the performer into the conductor.
High efficiency, easy maintenance, good reusability.
Note: Class name. Method Name ()
The name of the object. The difference between the method name ()?
Class name. Method Name () method name added static
The name of the object. Method Name () method name does not add static
A class file can have more than one class, but the class name must be preceded by a public, and only one class name is public.
No main () method is allowed in a class, but it cannot be called by the JVM.
Note:
Class Name Variable name = new class name ();
Variable name =null;
Variable name. property = value.
Variable name. method (); A null pointer exception is reported
What is the difference between a local variable and a global variable?
1. Global variables are set in the class, and the entire class can be used
A local variable is defined in a method, in a code block, in a statement, and only the owning zone is valid
2. Global variables exist in heap (heap), local variables exist in Yu Yu (Stack)
3. Global variables exist as objects are created and disappear as objects disappear.
Local variables exist as the owning region executes, and the execution ends and disappears.
4. Global variables have default initial values, no value can be used
Local variables do not have default initial values and do not give value
Local variables and global variable names
The same name first in the region to find the variable, if the region does not go to the global search, if you have to use the variable in the region
Class type (reference type) when parameters: the same attributes in an object we can write their common attributes in a single method.
Anonymous object: Object with no Name New Ren ();
Anonymous object Features: If the method or property in this object is called only once, then the main function of the anonymous object is to simplify the programmer's writing code.
Basic data type when parameter: The parameter of the method is a numeric value
Reference data type when parameter: Method parameter is an address
Java Permissions access modifier
1.public: Public permission to decorate classes, properties, methods. can be accessed by any class.
2.protected: Protected permissions decorated with properties, methods. can be accessed by the same package class, if it is not the same package class, it must be a subclass of that class.
3.default: The same package permission modifies the class, property, method. can only be accessed by the same package class.
4.private: Private permission Adornment property, method. can only be accessed in this class.
Encapsulation: Refers to the properties and implementation details of hidden objects, providing public access only to the outside.
Benefits: Isolate changes, ease of use, improve reusability, and improve security.
Encapsulation principle: To hide the content that does not need to be provided externally, to hide the attributes, and to provide public methods to access them.
Encapsulation mainly uses private
Use MyEclipse to write set () get ()
Right------"Source---> Getters and Setters in class
Note: Private private is an embodiment of encapsulation, which is encapsulation, but encapsulation refers not only to private.
What is the construction method for?
is used to create objects.
Classification of construction methods?
Default constructor methods and custom construction methods
Construction method Features:
The class name and the method name are the same, and the access permission modifier is the same as the access modifier for the class (which can be omitted).
The construction method does not return a value and does not have a void.
What is the difference between a default constructor method and a custom construction method?
1) The default constructor method is no parameter. The custom constructor method is a parameter.
2) Custom construction methods can have multiple, multiple construction methods exist in the form of overloading,
The default constructor method has only one.
3) The default constructor method exists in the class by default (not written).
4) If you have a custom constructor method in the class, but do not write out the default constructor method, the default construction method disappears.
When do I use a custom construction method?
When creating an object, you want the object to be created with some specified values, using a custom construction method.
The default constructor is used if a default value is taken.
What is the difference between a construction method and a common method?
1. Construction method: When an object is created, the method is automatically constructed and the class is initialized.
Normal method: After object creation, the normal method can be called
2. When an object is created, the constructor method is called only once
Common method: After an object is created, it can be called multiple times
Note: Construction methods and Assignment methods do not conflict
This: Represents the current object
How does this work?
1. When the parameter name and the global variable are the same, this is used when assigning the value!!!!!! (required),
2. Object Call property with this (not required, can be omitted)
3. Object Invocation method with this (not required, can be omitted)
4. Default constructor method call Custom constructor method: Book3 (,,)
1) The default constructor method in this (,,), must be placed in the first row of the current construction method
2) Custom constructor method call default constructor method Book3 ()
The custom construction method this () must be placed in the first row of the current construction method
Note: Do not have a dead loop when you call the construct method with this.
Static: Statically. You can modify properties, methods, and blocks of code.
Property:
1) through the class name. Property name
2) shared by all objects
Method: By the class name. Method Name-----The name of the object. Method Name ()
Code block: Executes when the class is loaded and executes once
Static code blocks > Constructing code blocks > Construction Methods
Static code block
Loads as the class is loaded and executes only once
Used to initialize a class
Constructing blocks of code (constructor method for object initialization)
{ }
Static code blocks and construction code blocks appear at the same time precedence
Static code blocks > Constructing code blocks > Construction Methods
Static use time:
Static Modifier Property: This property is shared by all objects.
Static Modification Method: The method is to access static variables in the object.
The static method can access only static variables, and non-static methods can access static and non-static variables.
The static method cannot use the This keyword, and local variables cannot be decorated with static.
What is the difference between a non-static variable and a static variable?
Two variables have a different life cycle
Non-static variables exist as objects are created and released as objects are recycled
Static variables exist as classes are loaded and disappear as classes disappear
Different calling methods
Non-static variables can only be called by an object
A static variable can be called by an object, or by a class.
Different aliases
Non-static variables are called instance variables
Static variables are called class variables
Different data storage Locations
Non-static variables are stored in the heap memory object, also known as the object's unique data
Static variable data is stored in the static area of the method area (data area)
Java Learning Notes (i)