Java essential knowledge test (a) ---- Java foundation

 

How to run Java?

Java source code developed by javac compiled into bytecode files (class) platform-independent, through the JVM and the bytecode interpreter interpreted into machine code corresponding to

 

"Compile once, run anywhere" understanding

Say is cross-platform features of java, and JVM are inseparable, different environments and platforms have installed JDK java runtime environment, not to say that java is a cross-platform language; the key and prerequisite for running JVM is everywhere, you can run the JVM He places his mouth within a JVM operating system, so that Java provides a variety of virtual mechanisms on different platforms, thereby achieving the effect of running everywhere

 

Difference JDK, JRE, JVM's

JDK java Development Kit
JRE java runtime environment, including the JVM and Java class libraries
JVM Virtual machine, the runtime environment java bytecode

 

What is encapsulation, inheritance, abstract?

Package Hidden object's properties and implementation details, only way to provide external access to public - security, reusability
inherit Is-a relationship, the subclass to accept common properties and methods, and adding unique properties and methods
abstract There are methods and class, to achieve specific subclass

 

Inheritance Notes

1, the subclass can only inherit all non-private members of the parent class (member methods, member variables)

2, a subclass can not inherit the parent class constructor, but by the super keyword to access the parent class constructor

 

The difference equals and ==

== Comparison of heap memory is a variable memory address, it is determined whether the two objects of the same address, i.e., whether the same object
equals Compare contents of two objects are equal, Object class also has equals, but calling ==, if the class does not override equals method, then calling the Object equals

 

HashCode and equals the number of conventions

a: equals equal, hashCode must be equal

b: override hashCode should override equals

c: hashCode need to maintain consistency, the state change the hash value returned is still to be consistent

 

How to understand polymorphism? benefit? Why polymorphism?

Polymorphism: reference point subclasses of the parent class

Benefits: subclass function may be the parent class or reference variable called

Why: reusability, high cohesion and low coupling, scalability

 

The difference between this and super

this Representative of this class object reference
super Representative of this class the parent class references, representative of the identity of the parent storage

 

Code block execution order

Static block of code (one time only) -> block configuration (prior to execution is performed each time the constructor) -> Constructor

Ordinary class initialization sequence

Static properties (variable, method) -> static block of code -> Member Properties -> block configuration -> Constructor

 

Subclass inherits initialization sequence

Parent Static Properties -> parent class static block of code -> subclass Static Properties -> subclass static block of code -> parent class member variable -> parent class constructor code blocks -> parent class constructor -> sub-class member variables - > subclass constructor code blocks -> subclass Constructors

 

The difference between final, finally, finalize the

final

Modified Class: Class can not be inherited

Modifying variables: the basic data types of variables can not be reassigned, reference type variable can not point to other objects

Modification methods: Method can not be rewritten, i.e., the process need not be extended

finally

finally block will always be performed, it is usually recovered resources (databases off, the IO closed, closed networks, etc.)

finalize

Ensure the completion of the object a particular recycle bin before being garbage collected

 

Java exception classes relevant

Error Unchecked exceptions, system-level error, can not be recovered and prevention, such as system crashes, the virtual machine error, insufficient memory space
Exception Points RuntimeException (unchecked) and IOException (need to check), program-level errors, restore and prevention, create a class that inherits Exception are checked exceptions
throw A method for use in vivo, throwing an exception object name, can throw the Throwable any, need to be thrown by the method of in vivo processing of the statement or throws
throws Methods used in the name, with the exception name is expressed may throw exceptions, these exceptions do not necessarily occur by the caller method to handle exceptions

 

 

The difference between abstract classes and interfaces

interface

1, does not contain const member

2, are static abstract method, multiple inheritance

3, only public, no constructor, not the main function inoperable

4, the main role: the API definition and implementation of the purpose of separation

Abstract class

1, there may be an ordinary member variables

2, members of the method may also have abstract methods, single inheritance

3、public、protected、private都可以,有构造方法,有main函数

4、主要作用:代码重用

 

 

Guess you like

Origin www.cnblogs.com/poloyy/p/12116913.html