Java:java Foundation (1)

Source: Internet
Author: User
Tags switch case

Java compiler has a solid optimization mechanism, if it is a constant calculation, will directly determine the value of the constant calculation results range, if it is a variable, there is no way to determine the value of the calculation
Scope, the compilation will be an exception (such as the addition of two variables of type byte).

Constants in Java refer to variables that are decorated with static final. You can see 6322651.

Integer default type is int type, floating-point number default type is double type

At the time of the operation, the Byte,short,char is implicitly converted to the int type, and the remaining data types are int-long-float-double from small to large.

The character type participates in the operation, converts the ASCII table to the corresponding number, and then computes that the string type converts any type to a
String type (in the order of calculation, if the string is at the top of the formula, the result above, but if the previous 1+1+ "Hello", then the first calculation
The result is 2hello, the parentheses can increase the calculation priority).

&& If the left side is determined to be false, then the logical expression on the right is not executed because the end result is false
|| The same left is true, then the logical expression on the right is not executed, because the end result is true

ternary operator int a = (a > B)? A:b means that if the logical expression inside the parentheses is true, take the value of a and false to the value of B.

The expression of the switch statement can only accept short char byte int String enumeration type, long, etc. type not accepted.

Jump out of specified loops with labels such as a:for (...) {Loop statement}, then if break A; represents a loop that jumps after a:.

Method overloading means that there are multiple methods of the same name in a class with different number of arguments and types, and the return value type may not be the same, when the overloaded method is called.
The compiler can automatically select the appropriate method based on the type and number of parameters. It is commonly used to create a set of methods that have similar tasks but differ in number and type of parameters.

The value passed by the base data type does not change, because after the call is finished, the local variable disappears and the value of the reference data type is passed to change the original value because the object is saved in the heap
Inside, you can continue to access through the address (such as the method to pass the value).

The delivery of a value in Java can only be a value, because the address passed by the reference data type is actually just the value of an address.

In cases where the name of the member variable and the local variable is the same, the general access is the nearest principle, so the general local variable overrides the member variable.

A file contains two or more than two classes, the class containing the main method must be a common class name to match the file name

The main function must be a public static method, such as publicly static void main (string[] args) {}

If the switch case does not break, then the program will be executed from where it was correctly matched to a break and return.
Regardless of whether the following case matches.

-----------------------------------------------------------------------------------------------------

The main method is that the JVM (Java Virtual machine) automatically calls

The location of the JVM calling the main method is naturally not in a class, or in a package, so it is visible to the JVM only when the main method is on the public level.
So the Mian method requires public modification,

The class that contains the main method also requires the public modifier.

In addition, because the main method is the entry of all programs, that is, when main is called, no object is created, and a method is not called by the object.
Only the method is defined as a static method, so the main method is a static method that requires both static adornments.

The JVM is already at the bottom of the Java program, and the return value of the method called by it has no place to go, so the main method return value is NULL,
It needs to be modified with void.

As for the parameter of the main method string[] arg we now have little chance to use it, which is used to accept arguments passed in at the command line.

------------------------------------------------------------------------------------------------------

A class cannot inherit more than one, but an interface can inherit multiple interfaces, so a multi-inheritance function is implemented through an interface.

If all the variables and methods in a class are static (static), you can set the construction method to private to prevent others from creating objects.

Generate Document: javadoc-d api-version-author-encoding utf-8 Classfilename.java

Subclasses inherit the parent class, and if the parent class does not have an empty parameter construction method, then the subclass constructor method must use Super (param ...). Call the parent class construction method.

Final-modified variables can be explicitly initialized, or they can be initialized in the constructor.

After the upward transformation, the non-private static final method is dynamically bound, as follows: If you point to the object of the child class with a reference to the parent class,
The method that actually calls the dynamic binding is the method that calls the subclass. However, you cannot use the new method of subclasses, and if you want to use it, you need to change it down again:
Son son = (son) father;

The instanceof function is to determine if the reference on the left is the same as the object on the right. If you are transitioning upward, it returns false.

Abstract a method or class, if a method is abstract, its class must be abstract. Its subclasses are also set to abstract,
Either rewrite all of its abstract methods. The abstract method cannot have a code block {}.

Abstract cannot coexist with static final private.

Interfaces are defined by interface, and the methods in the interfaces must all be abstract methods. Class implements interfaces with implements. Similarly, classes must implement the interface
All abstract methods. A class can be abstract.

member variables in an interface can only be constants all default modifier public static final, member methods all default to public abstract.

A class can implement multiple interfaces, and interfaces are separated by commas, and interfaces can have inheritance between interfaces and can inherit more.

Compiles the class javac-d with the package. Classname.java, use the class Com.xxx.ClassName with the package. (not recommended for this use, with import)

Inner class: Use format: External class name. Internal Class name = External Class object. An inner class object, such as Fclass.sclass fs = new Fclass (). New Sclass ()
Inner classes can access members of external classes, including private, external classes that access internal classes that must create objects.

New Interface name () {...} This is an object that implements an interface (which can be said to be a subclass of an interface), the new class name () {} This inherits a class, is a subclass, and then creates
Object. This subclass can add new methods to the code block, and so on. Because the parent class is simply inherited and then created, the subclass has no name, which is called an anonymous inner class.

Anonymous inner classes, which can be understood as subclasses, are implemented directly in the parent class. {} is a subclass. So an anonymous subclass is implemented directly within the parent class, so it's called
Inner class, which is probably the parent class {Anonymous class extends parent class {}}

Java:java Foundation (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.