Some knowledge points in Java that need to be documented (base part)

Source: Internet
Author: User

In order to prepare a year after the school recruit, began to review the Java, in order to facilitate beginners or other in the collation of basic knowledge of friends, send a log, welcome to discuss, and point out the error, thank you! The difference between    JDK and JRE: The JRE is the environment that all Java programs need to run, and any Java program is dependent on the JRE, which is the JRE that is currently installed from Java official website. The JDK is a toolkit for developers, a prerequisite for developers, typically a JRE in the JDK itself, but the generic JDK also installs a JRE, which is a public JRE () and the JDK needs to be downloaded from Oracle's website. The current mainstream editor, such as Eclipse, will find the location of the JRE and JDK and can, of course, be modified manually.  java Required environment variable Description: path: (required) Specifies that the compiled, running Java program is the path of the required program, typically in the JDK installation directory (note that jdk!!! And JRE is not the same!!! ) under the Bin folder. The current common setup method is to define a java_home variable, and refer to java_home:%java_home%/bin in path; CLASSPATH: (previously required, now not required) The purpose of setting up CLASSPATH is to tell the Java execution Environment, in which directories you can find the Java program (. class file) you want to execute, which is no longer required; Java_home: (Theoretically not necessary, actually required) set a variable to hold the Java program to run the path of the program, easy to reference in other places (no longer enter a long string of paths, directly using the Java_home variable), and now a lot of software will directly call the Java_home variable, not set error-prone.  1.java the main structure of each of the Java. java files are a class, and a Java project consists of many. java files, which are made up of Java classes. The main structure in a Java class is generally as follows: 1. Package statement: The Java class in this project belongs to which package, that is, the location of the project; 2. Imported Packages: External libraries, tools, 3. public class body (or interface) Definition: The class name must be the same as the Java file name, and the contents of the class are the main contents of the Java file 4. Other: Other classes Definition and interface definitions. In a Java project, from outside to Inside: source folder, Package, Class (. java, which is the half-day of the above BB), after compiling the compiled class (. Class) will be placed in the Bin folder with the source folder sibling. Different source FlodThe package in the ER can have the same name, and the class in the same package cannot have the same name (not even in two different source Floder)  2. Basic data Type 8: integer 4, floating-point 2, character, Boolean Btye maximum 128-1;short maximum 32768-1;int contains 10 digits at the beginning of the maximum 2, the numerical calculation takes into account the integer range of values, remember to add the conversion character; If the integer value exceeds the maximum range of int at the time of assignment, the integer is appended with the L description. Floating-point Type the assignment of float is followed by an F-description of the decimal, and the simple character-type variable (that is, each element is a character variable (PS. Addition of the ASCII code)) is equal to the ASCII code of each character added; The character and the string are added together to get a string)  3. Basic packaging class based on the common packaging of 7 kinds of classes (be sure to pay attention to the case!!!) ): String, Integer, Boolean, Byte, Character, Double, number; 4. Type conversions: char, int, double, and so on can be converted in a cast way, such as (int) ' A ', (char) 25;boolean type variable cannot be cast for conversions between individual variables and classes, and need to be implemented by invoking methods of individual objects. Such as: shaping, character type to string object conversion, you can use String.valueof ();  5. Constant assignment: Global constants must be assigned when initialized, and local constants can be initialized without assigning values, but can only be assigned once.  6. Variable valid range: The global variable is divided into instance variables and static variables (static), which can be used in other classes using the class name. The instance variable can only be used in this class. A local variable is only valid in the code block that defines the variable, which is the {} Two curly braces, starting with a variable declaration. A global variable with the same name as a local variable that is invalidated within the scope of the local variable's use. The difference between  7.switch and if ElseIf is that the same functionality can be achieved, but logically, if ElseIf must perform a check on each item in front of the match, and switch finds the match by a certain finding. Switch is more efficient when more items need to be checked, and the other advantage of switch is that the code is clear, but the disadvantage is that it is difficult to perform complex operations.  8. Use foreach loops to quickly iterate through arrays, objects, and so on, in the form of a for (int x:arr) {action}, but be aware of the foreachform cannot write to data  9.string object common method records (sorted by the usual degree of personal understanding, parameters and specific usage not specified) length () Gets the length of the string; equals () determines whether the contents of the string are the same, note that the equals sign cannot be used directly. Using the equals sign compares the locations in memory!!!!! Replace the substring in the replace () string, Split (), splits the string by the given symbol, saves it in the array, ToCharArray (), converts the string to a character array, trim () strips the space before and after the string, and note that the string is not changed. Instead, the corresponding copy is returned; substring () intercepts the character string, toLowerCase (), toUpperCase () the case conversion of the strings, IndexOf (), lastIndexOf () finds the substring position in the string; CharAt () Returns the character at the specified position in the string; StartsWith (), EndsWith () determines whether the string starts and ends with the specified string, CompareTo (), compares the string in dictionary order, and  10. Arrays objects commonly used methods of records (according to personal understanding of the common degree of ordering, parameters and specific usage is not specified) Arrays.fill (), padding array, can be used for array initialization, assignment, Arrays.sort (), sorting arrays; arrays.copyof (), Arrays.copyofrange the array for copying;  11. Note the use of static keywords specific analysis See Technical blog: http://www.cnblogs.com/dolphin0520/p/3799052. When HTML is used, a method, a variable to be called outside the class, and a static limiter are required, and the class (method) with the static limiter needs to call another method or global variable. The called method and global variable must also have a static modifier (this is because non-static variables must be created for the instance to be called). Typically used for classes (methods) that do not need to create instances, such as classes that are used as tools. To differentiate between static and permission modifiers, the purpose of static is to use static variables and methods without creating an instance, while the permission modifier specifies the scope of use of the method and the variable.  12.java Collection class holds data description ArrayList, HashMap and other collection classes are a feature of Java, but only reference data can be saved in it, and basic data cannot be saved. That is: integer can but int not.  13. The permission modifiers for class are described for the top-level class (in-PackageClass of the first tier), only the public modifier is available, which means that the class can be used across packages and, if not public, is available by default within the package, and a. java file has at most one of the classes that use public. For the inner class of the top-level class, its permission modifier is private, protected, public, and default. There is a need for in-depth research on the permissions of internal classes (such as the existence of a private variable in an inner class, the need to use the variable inside an external class), and a temporary skip here.  14. To determine whether two objects of a class are equal except for the underlying variable, the reference variable (object) cannot use two equals = = to determine whether the value is equal (the two objects generated by a class are equal), and the Equals method is used. Note, however, that the Equals method of a generic user-defined class is judged internally by the use of a double equal sign, and the user is overloaded with equals to achieve the desired effect. (is to write a method to judge)  15. Possible common methods in the wrapper class for basic variables Integerequals (), comparing the values of two integer objects Equal Bytevalue (), Intvalue (), Shortvalue () , returns the value of the corresponding type, tostring (), converts the Integer object to a String object (Tobinarystring (), tohexstring (), tooctalstring () integer.valueof (), Converts a String object to an Integer object Integer.parseint () and converts a string object to an int variable. Booleanbytecharactercharacter.inuppercase (), Character.inlowercase (), determines whether uppercase, lowercase characters character.touppercase (), Character.tolowercase (), converted to uppercase, lowercase characters tostring (), converts the character to a string double (float can refer to Doubel, the method is the same) Intvalue (), returns the Shaping variable tostring ( ), returns the string Double.valueof (), converts a string object to a double object   summary: When a conversion of the underlying class is required, you can use ToString () to convert to a string, and then convert the string to the required class using the valueOf of each class.  16. Commonly used mathematical calculation methods decimalformat the various methods of the class to format the numbers, get the string, the Math class trigonometric method, can goAll kinds of trigonometric functions, including the radian angle interchange exponential function method, square, square root, cubic, cubic root method, such as rounding function method, up, down rounding, the most recent maximum value minimum absolute value random number method (produce any double value between 0 to 1) Random class Nextint ( Returns an integer, Nextlong () returns a long Integer, Nextboolean () returns a Boolean variable, and Nextfloat () returns a floating-point number  17. About method overrides (different from overloading!!!!!!!!!!!!!! When overriding a method, you can modify the modifier of the method, the return value type (parameter type, number immutable), in most cases the final method in the parent class is not overridable (private final is not visible in the subclass, can be overridden, is a special case) when the subclass method overrides the parent class method, The modifier for a subclass method must be greater than the modifier permissions of the parent class method, and when the subclass is overridden on the parent class method, to modify the return value type in the subclass method, the type must be a subclass of the same method return value in the parent class;  18. The difference between method overrides and overloads in the same class, methods cannot be overridden. That is, there cannot be two methods of the same method name, number of arguments, parameter type in a class, in the same class, the method can be overloaded, that is, a class that allows multiple identical method names, different parameter types, and the number of arguments exist. The override of a method involves at least two classes of parent class, subclass, to override, cannot modify the method's parameter type and number, the method's overload only occurs in one class, to overload, you must modify the parameter type, number. All the methods in the parent class are inherited in the subclass, so there are two methods with the same method name and different parameters in the parent class and the child class, which can be considered to be inherited first and then overloaded.  19. Abstract class abstract A class can only be inherited and has no other function, whereas abstract methods in abstract classes have to be rewritten after they have been inherited, and there is no method body for abstract methods. If the class contains an abstract method, the class must be an abstract class.  20. Interface interface (interface) of the permission modifier (to be resolved), the interface method is public and does not contain the method body needs to be overridden, regardless of the principle of application, the interface is generally used public decoration, The non-public interface can only be used in different classes in the same package (still the default protected), plus the public interface to be used across packages, but only interface with the same name as the. Java can use public. But inside the interface, except static, default method, other methods can not have method body.  21. Transforming objects Transformation into an upward transformation and downward transformation, subclass objects can be continuously upward transformation (will automatically transform), the transformation of the parent object to consider it isNo sub-class objects can be transferred (requires forced transformation). For example, a A = new B (), and B is a subclass of a, then end a is treated as an object of type A, but essentially a class B, a reference to a parent class can call all the properties and methods defined in the parent class, and it is not a match for methods and properties that exist only with subclasses. That is, a can invoke the methods and properties that are inherited from Class A in type B, but cannot invoke methods and properties that are unique in class B. In the same way as a method call, assuming that C inherits from B inherits from a, the C type Object C, when invoking a method in the class, finds the overloaded version of the method in the available range (the available range references the previous sentence), and if it does not exist, it is converted to B and looks for the overloaded version of the type B parameter. Until you find an overloaded version of the executable method, if it does not exist, it cannot be called and will error.  22. About class packages in real development, the class package should be specified for all classes, and the declaration of the package must be the first line of non-commented code in the file, and all class packages are in lowercase letters. When importing a package, if you use * to import all the classes in the package, the subclass is not imported, and the subclass needs to be imported again if you need to import the child classes. You can import static members from a class by using import static.  23. For constant categorical local constants and global constants defined by constant final, local constants cannot be redefined during their lifetime, but they can be assigned new values each time they are created, and global constants generally use public static final, during program runs. The value of the global constant is not changed.  ps: Polymorphic failed to understand thoroughly, the permission modifier to go into the interface was not understood thoroughly, to be further

Some of the knowledge points in Java that need to be logged (the underlying section)

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.