Java Learning Notes (Collector Edition + Basic Edition)

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

Building a Java development environment
Developing MyEclipse with development tools
Base Core: Javaseeeme Object-oriented API JVM.
Java EE refers to Edition,java Enterprise Edition, which is used for enterprise-level development, including web development and many other
Javase refers to Java standard Edition,java, which is the development of generic Java programs, can be seen as a subset of Java EE

JVM (Java Virtual machine) source code MyProgram. java--(compiler) binary byte code myprogram.class--(interpreter) MyProgram
JDK: (Java Development Kit)
JRE: (Java Runtime Environment) JDK includes JRE,JRE including JVM

Java Development Environment Building
First step: Install the JDK
Second part: Configure the environment variable Java-home Configure the JDK installation path (front and back path with; separate) Configure the JDK command file bin path Classpath (. Indicates the current path; the path separates the Lib path) the location of the Configuration class library file Lib

Writing Java programs using Notepad
Use the Javac command to compile the Java source code for the binary bytecode file. class, using the explanatory Interpretor to interpret the. class file.
After the Javac compiler command is followed by the extension, the Java command cannot be followed by the extension. class

The IDE is a set of tools that integrates the program development environment and the program debugging environment, including the Eclipse MyEclipse Netbean, in an integrated development environment.
Development of programs using eclipse
1 Creating a Java project, 2 creating a package, 3 writing a Java Edge program 4 running a Java program
Create a project that includes source code, pictures, videos, scripts, and much more. The package is created to facilitate the management of the code. For example, the same name can be placed in a different package. The package name is generally named reverse of the name of the project name, for example COM.IMOOC
Pubic modifier class keyword, HelloWorld the same as the source code file name
public static void is required, and main is the entry for the program.
MyEclipse is an extension of Eclipse and is an excellent collection of Eclipse plugins for developing JAVA,JAVAEE

The Java language is case sensitive. System.out.println ("Welcome to IMOOC");

Porting of programs, import of projects, and export operations. Find the project Properties property, there is a location to know where the project is stored, copy and paste the export, and then import is, window import--general--existing project--Select the project location is poured in.

Common tips:
1, more practice, enterprises need hands-on ability, lip can not write is also a drag,
2, ask more, the Forum on the website to avoid detours, refuse to be dead, save time,
3, Multi-Hands debugging errors, will debug, review and summary.
4, each write a small knowledge point to do a summary, a weekly summary, a big summary of the month, notes made mistakes, blogs, to consolidate the knowledge points, (technical type is too strong, the knowledge point is very much, so need to summarize and consolidate. )
Learning is easy, learning is not easy, and learning and cherish.

Java keyword Try Catch finally throw throws True char Boolean int short long float double if else switch case break Conti Nue 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: It is used to give the Java program the variables, classes, methods, such as the name of the symbol, its rules:
1. Identifiers can consist of letters, numbers, underscores (_), dollar symbols ($), but cannot contain other special characters, such as @,%, space, etc., and cannot begin with a number. For example: 123name is not legal drop
2. Identifiers cannot be Java keywords and reserved words (Java reserved keywords, which may be used as keywords in later versions of the upgrade), but can contain keywords and reserved words. For example, void may not be used as an identifier, but myvoid can
3. Identifiers are strictly case-sensitive. So nirvana, be sure to distinguish between Chu Imooc and Imooc is two different identifiers Oh!
4. The name of the identifier should best reflect its role, to be known.
The habit of good siege master:
1, the variable name consists of multiple words, the first letter lowercase, followed by the first letter of the word capitalization, commonly known as camel-named method (also known as hump name), such as MyAge
2, when the variable name, as short as possible and can clearly express the role of variables, do see the name of understanding. Such as: Define variable name stuname save "student name" information
The length of the Ps:java variable name is not limited, but the Java language is case-sensitive, so price and price are two completely different variables Oh!

The Java language is a strongly typed language. The popular point is that the data stored in Java is typed and must be determined at compile time. Integer floating-point Boolean, class, interface, array. int 4,char 2 Boolean 1 float 4 double 8 when forced conversions, the values are not rounded, but the decimal bits are truncated directly. When auto-converting, int can be automatically converted to double, otherwise not, because double is eight bits and int is 4 bits. 3 is converted to 3.0.

constants, which we can understand as a special variable, whose value is set, is not allowed to change during program operation. Syntax: final constant name = value; Using Constants in programs can improve the maintainability of your code. Guys, watch out: constant names generally use uppercase characters.
We can use the Javadoc command to extract the content from the documentation comments and generate the program's API help documentation. javadoc-d Doc Demon03.java!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Document Comment!!!!!!!!!!!!!!
Must pay attention to Oh! The increment and decrement operators can only be used for operation variables and cannot be used directly to manipulate values or constants! For example, 5++, 8--and so on are all wrong!

ps:% is used to find the remainder, also known as the modulo operator.
1, >, <, >=, <= only support the left and right sides of the operand is a numeric type
2, = =,! = The operands on either side of the number can be numeric types, or they can be reference types
The comparison operator is used to determine the size of two data, for example: greater than, equal to, not equal to. The result of the comparison 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));
}

overloading if the same class contains two or more than two methods with the same name, the number of method arguments, the order, or a different type of method, it is called a method, or it can be called overloaded.
The basis for judging method overloading:
1. Must be in the same class
2. Same method name
3, the number of method parameters, order or type is different
4, not related to the modifier or return value of a method

Construction method
1. Create a new object using the new+ construction method
2, the constructor method is defined in the Java class to initialize the object's method, its purpose is to create and initialize an object, the construction method must have the same name as the class and no return value.
3, the format is, public construction method name (parameter) {content}
4, when there is no specified construction method, the system will automatically call the default construction method, and assign the initial value
5, when there is a specified construction method, whether it is a parameter, no parameter of the construction method, will not automatically add the construction method without parameters. For example, it is not feasible to define a method to construct a parameter, and to invoke an parameterless construction method.
6, the argument and the non-parametric construction method is the method of overloading
7. Avoid the problem of unsafe transfer value of the parameter construction method.

Static variable statics: Multiple objects of the same class share the same member, the member of the static modifier becomes a static member, or a class member, he belongs to the entire class, not all of the objects, which are shared by all objects of the class,!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!! Static members can be accessed directly using the class name, or they can be accessed using the object name, which is recommended for use with the class name. Static members belong to the entire class, and when the system first uses the class, it allocates memory space until the class is unloaded for resource recycling and can be modified oh oh/

A static method can invoke a static member directly in the same class, but not a non-static member directly. If you want to call a non-static variable in a static method, you can create the object of the class by creating it. Non-static variables are then accessed through the object. Static methods can be called directly by the class, and non-static methods can be called directly by the object.
public static void print () {
HelloWorld Hello = new HelloWorld ();
System.out.println ("Welcome You" +hello.name+ "|");
System.out.println ("Hobby" +hobby+ ",");
}
Ordinary member methods, you can directly access the same kind of non-static variables and static variables. A non-static method cannot be called in a static method, and a non-static member needs to be accessed through an object.
by outputting The result, we can see that the static initialization block is executed first when the program is run, then the normal initialization block is executed, and the construction method is finally executed. Because static initialization blocks are only executed once when the class is loaded, static initialization blocks are not executed when the object Hello2 is created again.

Object-oriented three major features, encapsulation, inheritance, polymorphism.
Encapsulates a property, Setter\getter method, that an object calls the Setter\getter method to assign a value.

Package concept, better manage Java classes, resolve file conflicts with the same name (two classes with the same name are distinguished)
Package definition, package name, must be placed in the first line of the Java source program, the package name can be used between the "." Separate, eg:com.imooc.MyClass, distinguish levels
Packages in the system:
Java. (function). (Class)
Java.lang (Class) contains the Java language foundation of the class string Integer Double/math ....
Util contains various tool classes in the Java language Scander,date,calendar
IO contains the input and output related functions of the class each more a point function more detailed.
Import Com.java.util.MyClass.
Package specifications are spelled in full lowercase letters. You can load all the files under a package, or you can load all the files under a specific package.

A: What is an internal class? The main functions of the inner class are as follows:
1. The inner class provides a better encapsulation that hides the inner class within the outer class and does not allow other classes in the same package to access the class
2. The method of the inner class can access all the data of the external class directly, including the private data
3. Functions implemented by internal classes can also be implemented using external classes, but sometimes it is easier to use internal classes

Static inner classes are internal classes of static adornments, which are characterized by:
1. Static inner classes cannot directly access non-static members of an external class, but can be accessed through the new external class (). Members
2. If the static member of the outer class is the same as the member name of the inner class, the static member of the external class can be accessed through the class name. static member; If the static member of the outer class is not the same as the member name of the inner class, the static member of the outer class can be called directly through the member name
3. When creating an object of a static inner class, you do not need an object of an external class, you can directly create an inner class object name = New inner class ();

The inner class of a method cannot be used outside of the method of the outer class, so the method inner class cannot use the access control and the static modifier.

Inheritance, extends, overrides for inheriting subclass methods.
Initialization Order of Inheritance: Initializes the parent class, initializes the subclass, executes the properties in the initialization object, and then initializes the constructor method.

Final-Modified classes cannot be inherited, and final-modified methods cannot be overridden, and final-modified properties that have already been assigned an initial value cannot be changed to include in the constructor method. The final property, which is not assigned, can be assigned in the constructor method. If the final modified property is not assigned an initial value, the system will error.
A local variable in a method cannot be changed after it is final modified, or it is called a constant.

Super keyword in Java: Used inside an object, can represent the parent class object, access the property of the parent class object Super.age, access the parent class's method, Super.eat (). The construction method of the parent class is implicitly called in the constructor method of the child class.
The implicit super () call is called if the constructor method of the parent class is not shown in the subclass construction method.
If the constructor method that calls the parent class is displayed, it is placed in the first row of the subclass construction method.
If you define a constructor with parameters in the parent class, the first row in the subclass must have the super () method, because no super will implicitly call the default constructor method, so ...


Object class
1, the ToString () method, the returned object is a hash code, (object address string) can be overridden by the ToString method to display the object's properties.
2, the Equals method, compares whether the object reference occupies the same memory address. The general comparison is whether the values are equal, so the Equals method is to be re-used.
Dog dog = new Dog () is a constructor of the new dog class that creates an object that pays the object to dog, which is not the object we created, but the address of our object, which is called the object reference. = = is also the comparison of the referenced value is the same.

Polymorphic:
1. Multi-state referencing
References to the parent class can point to objects of this class
A reference to the parent class can also point to the object of the subclass
A reference to a subclass cannot point to the object of the parent class
2. Method polymorphism
When you create this type of object, the method that is called is the method of this class
When a subclass object is created, if there is an object that overrides the calling method as a subclass, the parent class is called if there is no override.
A method unique to a subclass can not be called with a reference to the parent class.


Reference type conversions:
No risk-up, downside risk, and how to mitigate risk, then use the instanceof modifier to avoid the security of type conversions. The judgment is its subtype.

Abstract class
Abstract modifier, public abstract class, public abstract void method.
Abstract methods only declare, do not write content.
Classes that contain abstract methods are called abstract classes, and subclasses of the abstract class can define other methods.

Interfaces can implement multiple interfaces.
General name first letter capitalization
Modifiers must be public, both yield and method are abstract methods.
Inheriting an abstract class, you must implement an abstract method of the abstract class, invoke an interface, and you must implement an abstract method of the interface.
Inherit the parent class before calling the interface.

Exception, Thread (Erro.exception (runtimeexception))

A String object cannot be modified after it is created, so the so-called modification is actually creating a new object, pointing to a different memory space,
Once a string is created in memory, the string will not be changed. If you need a string that can be changed, we can use StringBuffer or StringBuilder. Each time new is a string that produces a new object, even if the contents of the two strings are the same, the "= =" comparison is used to compare only their references or the addresses they refer to. Compare content with equals

When using substring (beginindex, endIndex) for string interception, characters that include the beginindex position, not including the EndIndex position

When using IndexOf for character or string lookups, if the match returns a position index, or 1 if there is no matching result

The index of the characters in the string Str starts at 0 and ranges from 0 to Str.length ()-1
toLowerCase ()//convert string to lowercase
CharAt ()//Get the character with index position 1
GetBytes ()//convert string to byte[].

Conversion between the base type and wrapper class, double b =87.6 double A = new double (b); Double a = b;
Automatic box packing, manual packing, automatic unpacking, manual unpacking.  Double c = a.doublevalue (); Double d = A;

Conversions between basic types and strings: Double.tostring (a); Sg.valueof (a);D ouble.parsedouble (str);D ouble.valueof (str);

Java Collection framework: Collection (List (ArrayList) queue (LinkedList) set (HashSet)) map (HashMap)


Class, everything is objects, static classes and members are objects, ordinary data types are not objects

127.0.0.1 Local loopback address mysql-uroot-p-p-h127.0.0.1

I:
The difference between String Buffer append and string+:
I:
The Append method of StringBuffer is put together in memory, and the + is not put together


Database of custom function declarations, declaration of stored procedures, knowledge of the storage engine
There are various links, internal links, left outer link, right outside the link, there are various sub-queries.

Map generics
Oracle mailbox is QQ mailbox, password is SHAOke12345

The action of the control layer is to encapsulate the various methods in the DAO into an action class
The action class is then called in the Main method, which makes it easier to invoke each function.










This article is from the "11923789" blog, please be sure to keep this source http://11933789.blog.51cto.com/11923789/1834530

Java Learning Notes (Collector Edition + Basic Edition)

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.