Java learning notes (cainiao original), java learning notes original

Source: Internet
Author: User
Tags float double switch case try catch

Java learning notes (cainiao original), java learning notes original

Build a Java Development Environment
Use development tools to develop Myeclipse
Core: JAVASEEEME object-oriented api jvm.
JAVAEE refers to java enterprise edition and java enterprise edition, which are mostly used for enterprise-level development, including web development and many other forms.
JAVASE refers to java standard edition and Java standard edition, which can be considered as a subset of Java ee.

JVM (java virtual machine) source code myprogram. Java -- (compiler) binary bytecode myprogram. class -- (Interpreter) myprogram
JDK: (JAVA Development Kit)
JRE :( JAVA Runtime Environment) JDK includes JRE, JRE includes JVM

Build a Java Development Environment
Step 1: Install JDK
Second: configure the environment variable java-home to configure the JDK installation path (separated by the first and foremost paths). Configure the JDK command file bin path classpath (. it indicates the current path; it indicates the path to separate the lib path) configure the location of the library file lib

Use NotePad to write java programs
Use the javac command to compile the java source code as a binary bytecode file. class, and use the interpretor interpreter to interpret the. class file.
The javac compiler command must be followed by the extension. The java command cannot be followed by the extension. class.

IDE is a set of tools that integrate the development environment, including eclipse myeclipse netbean and so on, to bring together the development environment and debugging environment.
Use eclipse for Program Development
1. Create a java project, 2. Create a package, 3. Write a java program, and 4. Run the Java program.
Create a project, including source code, images, videos, scripts, and so on. Create a package to facilitate code management. For example, the same name can be placed in different packages. The package name is generally the inverse of the Project Name Domain Name, such as com. imooc
Pubic modifier class keyword, helloworld and source code file name must be consistent
Public static void is required to be the same, and main is the entry of the program.
Myeclipse is an extension of eclipse and a collection of eclipse plug-ins that are excellent for java and javaee development.

The java language is case sensitive. System. out. println ("welcome to imooc ");

Program migration, project import and export operations. Find the properties attribute of the project. If you have a location, you can know the storage location of the project. Copy, paste, and export the project. Then, import the data in the window import -- general -- existing project -- select the project location and import it.

Common tips:
1. Practice more. Enterprises must have strong hands-on skills. It is also a nonsense that you cannot write,
2. ask more questions. avoid detours on the website forum, refuse to drill corners, and save time,
3. debug, review, and summarize multiple debugging errors.
4. Each time I write a small knowledge point, I will make a summary every week. I will make a summary every month. I will take note of the mistakes I 've made, blog, and consolidate the learned knowledge points. (the technology is too strong, there are many knowledge points, so we need to summarize and consolidate them .)
Although easy to learn, it is not easy to learn, and learn and cherish.

Java keyword try catch finally throw throws true char false boolean int short long float double if else switch case break continue default for private protected public implements extends interface super class static void main null new package byte validate class instanceof synchronized (synchronous) import
In addition, java is case sensitive, so Void is not a keyword.

Identifier: a symbol used to name variables, classes, and methods in a JAVA program. Its rules are as follows:
1. An identifier may consist of letters, numbers, underscores (_), and dollar signs ($), but it cannot contain other special characters such as @, %, and space. It cannot start with a number. For example, 123 name is invalid.
2. The identifier cannot be a Java keyword or a reserved word (a reserved keyword in Java, which may be used as a keyword in later versions), but can contain keywords and reserved words. For example, void cannot be used as an identifier, but Myvoid can
3. The identifier is case sensitive. Therefore, it must be clear that imooc and IMooc are two different identifiers!
4. It is recommended that the name of the identifier reflect its role, so that you can understand the name.
Habits of excellent city siege teachers:
1. When a variable name is composed of multiple words, the first letter of the first word is lowercase, and the first letter of the subsequent word is capitalized, also known as the camel naming method (also known as the camper naming method), such as myAge
2. When naming a variable, try to be brief and clear about the role of the variable, so that you can understand the name. For example, define the variable name stuName to save the "Student name" information.
PS: there is no limit on the length of the Java variable name, but the Java language is case sensitive, so price and Price are two completely different variables!

Java is a strongly typed language. In general, the data stored in Java is of a type and must be determined at compilation. Integer floating point Boolean type, class, interface, array. When int 4, char 2 boolean 1 float 4 double 8 is forcibly converted, the numeric value is not rounded, but the decimal place is truncated directly. During automatic conversion, int can be automatically converted to double, and vice versa, because double is eight bits and int Is four bits. 3 is converted to 3.0.

A constant. We can understand it as a special variable. After its value is set, it cannot be changed during the program running. Syntax: final constant name = value. Using constants in a program can improve the maintainability of the Code. Note: constant names generally use uppercase characters.
We can use the javadoc command to extract content from the document comment and generate the program's API help document. Javadoc-d doc Demon03.java !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!! Document comments !!!!!!!!!!!!!!
Be sure to pay attention to it! The auto-increment and auto-increment operators can only be used for operation variables. They cannot be used directly for Operation values or constants! For example, the writing methods such as 5 ++ and 8 -- are all incorrect!

PS: % is used to calculate the remainder, also known as the modulo operator.
1.>, <, >=, <= only the operands on both sides of the left and right are numerical values.
2, = ,! = The operands on both sides can be numeric or reference type
The comparison operator is used to determine the size of two data types, for example, greater than, equal to, or not equal. The comparison result is a Boolean value (true or false ).
String sex = "female ";
Sex. equals ("male ");
Import java. util. Arrays;
Public int sort (int [] scores ){
Arrays. sort (scores );
System. out. println (Array. toString (scores ));
}

If the same class contains two or more methods with the same name, number of method parameters, sequence, or type, this method can also be called overloaded.
Basis for determining method overloading:
1. It must be in the same class
2. The method name is the same
3. The number, sequence, or type of method parameters are different.
4. It is irrelevant to the modifier or return value of the method.

Constructor
1. Use the new + constructor to create a new object.
2. constructor is a method defined in a java class to initialize an object. It is used to create and initialize an object. The constructor must have the same name as the class and has no return value.
3. Format: public constructor name (parameter) {content}
4. When no constructor is specified, the system automatically calls the default constructor and assigns an initial value.
5. If a constructor has a specified constructor, no parameter or constructor will automatically add a constructor without parameters. For example, if a constructor with parameters is defined, and a constructor without parameters is called, this will not work.
6. A constructor with or without parameters is a method overload.
7. Avoid the problem of insecure value passing by parameter constructor.

Static variable static: Multiple objects in the same class share the same member. The static modified member becomes a static member or class member, which belongs to the whole class, rather than the whole object, that is, all objects of the class are shared ,!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Static members can use class names for direct access or object names for access. In view of their special characteristics, we recommend that you use class names for access. Static members belong to the entire class. When the system uses this class for the first time, it will allocate memory space for it until the class is detached and the resources will be recycled, which can be modified/

Static methods can directly call static members of the same type, but cannot directly call non-static members. To call non-static variables in a static method, you can create a class object. Then access non-static variables through the object. Static methods can be called directly by classes. Non-static methods can be called directly by objects.
Public static void print (){
HelloWorld hello = new HelloWorld ();
System. out. println ("welcome" + hello. name + "| ");
System. out. println ("hobbies" + holobby + ",");
}
In common member methods, you can directly access non-static and static variables of the same type. Non-static methods cannot be called in static methods, and non-static members must be accessed through objects.
The output result shows that the static initialization block is executed first when the program is running, then the common initialization block is executed, and the constructor is executed finally. Because the static initialization block is only executed once during class loading, the static initialization block is not executed when the object hello2 is created again.

Three main features of object-oriented, encapsulation, inheritance, and polymorphism.
Encapsulate attributes. The setter \ getter method is used. The object calls the setter \ getter method to assign values.

To better manage java classes and solve conflicts with files of the same name (distinguish two classes with the same name)
Package definition, package name, must be placed in the first line of the java source program, package names can be separated by ".", eg: com. imooc. MyClass, hierarchical
Packages in the system:
Java. (function). (class)
Java. lang (class) contains the java language-based class String Integer Double/Math .......
Util contains various tool classes in java: Scander, Date, and Calendar
Io contains the input and output functions.
Import com. java. util. MyClass.
The specification of the package is to spell all lowercase letters. You can load all files under a certain package or all files under a specific package.

A: What is an internal class? The main functions of the Internal class are as follows:
1. Internal classes provide better encapsulation. Internal classes can be hidden from external classes, and other classes in the same package are not allowed to access this class.
2. Internal class methods can directly access all data of the external class, including private data
3. functions implemented by internal classes can also be implemented using external classes, but sometimes internal classes are more convenient.

Static internal classes are static modified internal classes, which are characterized:
1. static internal classes cannot directly access non-static members of external classes, but they can be accessed through new external classes (). members.
2. If the static member name of the external class is the same as that of the internal class, you can use the "class name. "Static members" Access static members of the external class. If the static members of the external class are different from those of the internal class, you can directly call the static members of the external class using the "member name ".
3. When creating static internal class objects without external class objects, you can directly create an internal Class Object Name = new internal class ();

The internal class of the method cannot be used outside the external class's method, so the internal class of the method cannot use the access controller and static modifier.

Inheritance, extends, and override of the subclass method.
Inherited initialization sequence: Initialize the parent class and then initialize the subclass. First, execute the attributes in the initialization object, and then execute the initialization in the constructor.

Final-modified classes cannot be inherited, final-modified methods cannot be overwritten, and final-modified attributes with initial values cannot be included in the constructor. The final attribute that is not assigned a value can be assigned a value in the constructor. If the final modified attribute does not have an initial value, the system reports an error.
Local variables in the method cannot be changed after being modified by final, which is called constants.

In java, the super keyword is used inside the object. It can represent the parent class object. The attribute used to access the parent class object is super. age. The method used to access the parent class is super. eat (). The constructor of the parent class is implicitly called in the constructor of the subclass.
If the parent class constructor method is not displayed in the subclass constructor, the implicit super () method is called.
If the constructor that calls the parent class is displayed, it is placed in the first row of the subclass constructor.
If a constructor with parameters is defined in the parent class, the first line of the Child class must have the super () method, because no super will call the default constructor implicitly, so .....


Object Class
1. toString () method. The returned object is a hash code. (object address string) The toString method can be rewritten to display the object attributes.
2. The equals method compares whether the object reference occupies the same memory address. Generally, the equals method is used to compare whether the values are equal.
Dog dog = new Dog () is the construction method of a new Dog class to create an object and pay the object to dog. In fact, dog is not the object we created. It is the address of our object, it is also called object reference. = Whether the referenced values of the comparison are the same.

Polymorphism:
1. Reference Polymorphism
The reference of the parent class can point to the object of this class.
The reference of the parent class can also point to the object of the subclass.
Subclass references cannot point to the parent class objects.
2. Method Polymorphism
The method called when creating this class object is this class Method
When a subclass object is created, if a method for calling rewrite is a subclass object, the parent class is called if the method is not overwritten.
You cannot use the reference of the parent class to call Methods unique to the subclass.


Conversion of reference types:
There is no risk in the up, down, and how to avoid risks, you can use the instanceof modifier to avoid the security problem of type conversion. It is its subtype.

Abstract class
Abstract modifier, public abstract class, and public abstract void method.
The abstract method is declared only without writing content.
Classes that contain abstract methods are called abstract classes. subclasses that inherit abstract classes can define other methods.

Multiple Interfaces can be implemented.
Generally, the first letter is capitalized.
The modifier must be public. Both the output and method are abstract methods.
It inherits the abstract class and must implement the abstract method of the abstract class. It calls the interface and must implement the abstract method of the interface.
Inherit the parent class before calling the interface.

Exception, thread (erro. exception (runtimeexception ))

After a String object is created, it cannot be modified. The so-called modification is actually to create a new object with different memory spaces,
Once a string is created in memory, it cannot be changed. If you need a variable string, we can use StringBuffer or StringBuilder. Each time a new string is created, a new object is generated. Even if the content of the two strings is the same, using "=" to compare only their reference or reference addresses. Use equals for comparison

When using substring (beginIndex, endIndex) for string truncation, including the beginIndex position, excluding the endIndex position

When you use indexOf to search for characters or strings, if a match is returned, the location index is returned. If no match is returned,-1 is returned.

The index of characters in string str starts from 0 and ranges from 0 to str. length ()-1
ToLowerCase () // converts a string to lowercase.
CharAt () // get the character whose index position is 1
GetBytes () // converts a string to byte [].
 
Conversion between the basic type and the packaging class, double B = 87.6 Double a = new Double (B); Double a = B;
Automatic packing, manual packing, automatic unpacking, and manual unpacking. Double c = a. doubleValue (); double d =;

Conversion between the basic type and string: Double. toString (a); Sg. valueof (a); Double. parseDouble (str); Double. valueof (str );

Java collection framework: collection (list (arraylist) queue (sorted list) set (hashset) map (hashmap)


Class. Everything is an object. Static classes and members are objects. is a common data type an object?

127.0.0.1 local loopback address MySQL-uroot-p-P-h127.0.0.1

Me:
The difference between String Buffer append and String +:
Me:
The append method of StringBuffer is put together in memory, and ++ is not put together.


Database User-Defined Function declaration, stored procedure declaration, and storage engine Recognition
There are also various links, internal connections, left outer links, right outer links, and various seed queries.

Map generic
Oracle mailbox is QQ mailbox, password is SHAOke12345

The Action operation at the control layer encapsulates each method in Dao into an Action class.
Then, the main method calls this Action class to call various functions, which is more convenient.










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.