One particularly obvious advantage of using inner classes is that you can inherit a parent class (interface) independently, and that the inheritance of the outer class has no effect on the inheritance of the inner class.Think in Java describes this:1 . The inner class can use multiple instances, each with its own state information, and the information of other peripheral objects is independent of each other
Transferred from: http://ly5633.iteye.com/blog/1218724————————————————————————————————————————These two classes are located within the Java.math package and must be referenced before the class to use them: import Java.math.BigInteger; and import java.math.BigDecimal;BigInteger and BigDecimal represent immutable arbitrary-precision integers and immutable signed arbitrary-precision decimal numbers (floating-point numbers), respectively. It is mainly use
First, describeWhen are classes in Java loaded by a JVM virtual machine? Because static member initialization is performed when the class is first loaded, we test the execution time of a static block of code to determine when the JVM loads the class.Summary: TheJVM is called only if it needs a class or uses Class.forName (className) to force the class to be invoked, and if it simply declares a reference to
significantly because each thread needs to execute, consuming CPU time. If the thread is not competing fiercely, and the time period of the lock is maintained. Suitable for use with spin locks. Note: This example is an unfair lock, and the order in which the locks are obtained is not carried out in the order in which they enter lock . bias Lock / Lightweight lock / heavyweight Lockthese three kinds of locks, that is, refers to the state of the lock, for synchronized. A biased lock is a piece of
the subclass, but the super's default constructor is not defined.To solve this problem, just 1) add a super () constructor to the Super class, like this:[Java]View PlainCopy
Public Super () {
System.out.println ("Super");
}
or 2) Delete the custom parent class constructor.3) explicitly calling the parent class constructor in a subclassThe following code is normal:The subclass (sub) constructor explicitly calls the parameter con
, and returns False if it fails. Failure indicates that the path specified by the file object already exists, or that the folder cannot be created because the entire path does not yet exist.The Mkdirs () method creates a folder and all its parent folders.Read DirectoryA directory is actually a file object that contains other files and folders.If you create a File object and it is a directory, then calling the Isdirectory () method returns True.You can extract a list of the files and folders it c
class.public class Triangle extends sharp{Define three edgesPrivate double a,b,c; Public Triangle (String color,double a,double b,double c){Super (color);This.a=a;This.b=b;This.c=c;}Rewrite the abstract method of calculating perimeter in the sharp classPublic double Calperimeter (){return a+b+c;}Overriding the abstract method of returning shapes in the sharp classPublic String get Type (){return "triangle";}}Assuming there is another circle class that inherits the Sharp class, the following co
//outer.inner in = new Outer.Inner ();//in.show ();//If the inner class is static, the member is static. Outer.Inner.function ();}}/* Why do internal classes have direct access to members of external classes? That's because the inner class holds references to external classes. external class name. this*/class outer{int num = 3;class inner{int num = 4;void Show (
class does not, the DOS result is displayed, is also an error. The next two situations are different, one is "overridden method" and the other is "overridden method".If both sides are static, there is no problem. DOS display compilation is possible.Therefore, the following considerations are noted. The second kind of rare, to polymorphic time, to explain to you, why is such a thing. For static methods, we say overwrite, not particularly accurate, because it is no longer dependent on the object,
outer classAs is, my heart can only be controlled by my body, others cannot access it directlyExample 5: Method Inner class
1234567891011121314151617181920
classOut {privateintage = 12;publicvoidPrint(finalintx) {classIn {public voidinPrint() {System.out.println(x);System.out.println(age);}}new In().inPrint();}}publicclassDemo {publicstaticvoidmain(String[] args) {Out out = newOut();out.Print(3);}}
Operation Result:312In the above code, we move the inner class into the
Inheritance implements the reuse of code, the abstract class takes into account the purpose of code reuse and the realization of polymorphism, interface is a 100% abstract class, its existence is purely for polymorphism.
Polymorphic, the sample code is as follows:
Public abstract class Animal {int size; public abstract void makenoise (); public abstract void Sleep ();} public class Ca T extends Animal {public void makenoise () {System.out.println ("miao! Miao! ");}} public class Dog extends Ani
Object class Java.lang.ObjectThe Java.lang package does not need to display the import when it is used, and is automatically imported by the compiler at compile time.The object class is the root of the class hierarchy, and all classes in Java are fundamentally inherited from this class.The object class is the only class in Java that does not have a parent class.
I. Collections class andCollectionInterface
CollectionsIt is a help class for collection classes. It provides a series of static methods for searching, sorting, thread security, and other operations on various sets.
Collection is the most basic collection interface. A collection represents a group of objects, namely, elements of the collection ). Some collections allow the same elements while others do not. Some can be sorted, while others cann
, SECONDpublic void Set (int field,int value)public void Add (int field,int amount)Public final Date GetTime ()Public final void SetTime (date date)Math class Java.lang.MathABS AbsoluteAcos,asin,atan,cos,sin,tan Trigonometric Functionssqrt square rootPow (double a,doble b) a power of BLog Natural logarithmExp e is the base indexMax (double a,double b)Min (double a,double b)Random () returns the number 0.0 to 1.0Long round (double a) double type data A is converted to long (rounded)Todegrees (dou
; jaxb:bindings>Note1: The new version of plugin can not only generate Java class, but also help generate the most important methods of object: ToString, Equals, Hashcode, clone, Just configure the plugin on the configuration.configuration> extension>Trueextension> args> arg>-xtostringarg> arg>-xequalsarg> arg>-xhashcodearg> arg>-xcopyablearg> args> plugins> plugin> groupId>Org.jvnet.jaxb2_com
Writing a Java program that accesses a database also requires several important classes and interfaces.DriverManager classThe DriverManager class handles the loading of the driver and establishes a new database connection. DriverManager is the class that is used in the java.sql package to manage database drivers. Typically, an application uses only the getconnection () static method of the class DriverManag
About this series, because the development is mainly used in the Java language, has always wanted to write some of the common Java Development classes (although this is the beginning of the third >_first, the data structureLet's take a look at the location of the ArrayList package, in Java.util.ArrayList (1-1), which is in the JDK util, which shows that it is mor
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.