Preface
I am a disorderly flying the rookie, write the article is now to record their own study, and easy to view later, look forward to the future through their own efforts to obtain a little success, and then write my study experience summary articles.
---WH
First, what is a virtual machine? Why is Java called a "platform-agnostic programming language"?
Answer yourself:
The virtual machine is used to compile our written Java program, our program Xxx.java first compiled into Xxx.class this is a byte-code file,
The virtual machine parses our bytecode file to form the code known to the bottom of the computer, so we don't need to know if our Java program is going to run on the computer, because the virtual machine has done this for us, and on any platform, the virtual machine can do that. So Java is called a platform-agnostic programming language.
Reference Answer:
A Java Virtual machine is a virtual machine process that can execute Java bytecode. The Java source file is compiled into a bytecode file that can be executed by the Java virtual machine.
Java is designed to allow applications to run on arbitrary platforms without requiring programmers to rewrite or recompile each platform individually. The Java Virtual machine makes this possible because it knows the instruction length and other features of the underlying hardware platform.
Self-evaluation: the concept of vague, not clear because his head is not thinking clearly,
1. The virtual machine does not compile. Java becomes a. Class bytecode file, this is done by the compiler, there are many kinds of compilers.
2, the virtual machine to do, the bytecode file to parse into a machine code file, that is, 0101 this, in order to let the computer know the meaning of the code, is because the virtual machine did this thing, so to run on each platform.
Better way to explain:
Virtual machine is able to identify the Java source files compiled by the bytecode file, and the bytecode file to form a machine code, so that the computer recognition, because the virtual machine know some of the characteristics of the computer, to help us to change the bytecode to the computer recognition of the code, so it is not related to the platform, we only care about the Java source file writing.
Ii. What is the difference between JDK and JRE?
Answer yourself:
JDK = JRE + runtime, which means that the JDK contains the JRE
The JDK is the Java running environment, Java running, depends on the existence of JDK,
Reference Answer:
The Java Runtime Environment (JRE) is the Java virtual machine that will execute the Java program. It also contains the browser plug-in needed to execute the applet. The Java Development Kit (JDK) is a complete Java software development package that includes a JRE, a compiler, and other tools (such as the Javadoc,java debugger) that enable developers to develop, compile, and execute Java applications.
Self-evaluation: vague concept, do not clear the relationship between the two.
1. Jdk:java Developer ' s kit Java Development Kit,
2, Jre:java Run environment Java operating environment,
3, the JRE includes: Java runtime depends on the class library (such as String class, and so many classes, all belong to the JRE), the JVM (virtual machine) and other things
4, JDK includes: JRE and compiler, some other tools (debugger) and so on. The goal is for developers to develop, compile, and execute Java applications.
Better way to explain:
The JDK includes the JRE and some tools (compilers, debuggers) to enable developers to develop, compile, and run Java programs, while the JRE has important JVMs (Java virtual machines), some running libraries, and so on.
Third, what does the "static" keyword mean? Is it possible to overwrite (override) a private or static method in Java?
Answer yourself:
Static: Statically, capable of acting on properties, methods,
Acting on a property, meaning that there is only one copy in the class, unique, that each object can share it, and that the property can be called directly from the class
function on the method, the method can be called directly by the class,
Note: Static methods cannot invoke methods or properties that are statically decorated, not static methods without restrictions.
Can not be said to overwrite the method of the private decoration, because the premise of the overwrite must have the inheritance relationship, the scope of private only for this class is visible, its own subclass also hide it, can write the same method, but that is not covered
Nor can you rewrite the static method, feeling like this, the reason is not known.
Reference Answer:
The "static" keyword indicates that a member variable or a member method can be accessed without an instance variable of the class to which it belongs.
The static method in Java cannot be overridden because method overrides are dynamically bound based on the runtime, while the static method is statically bound at compile time. The static method is not relevant to any instances of the class, so it is conceptually not applicable.
Self-evaluation: half the right answer. Static modifier member variable and decoration method The answer is bad, but the latter question is a bit doubtful.
1. Static modified member variables and methods
2. Modify member variables: an instance of the entire class shares this property, which can be called directly through the class
3, modify the method: The class can call the method directly, static methods can only invoke static modified variables and methods in the class. Instead of static methods there is no limit,
4, note: Static modified member variables or methods, followed by the loading of the class loaded into memory, so the class can directly invoke these decorated properties and methods, and static methods can only invoke static modified properties and methods for this reason, static properties and methods before non-static properties and methods loaded , so the static method calls the property, non-static has not finished loading it, and when the non-static call static, there is no such concern.
5, overwrite, that is, the precondition is to inherit, the parent class with private decoration method, the sub-class are not visible, inherit, so there is no so-called rewrite
6. The static method cannot be overridden because static is statically bound at compile time, and the override of the method is dynamically bound based on the runtime, and the static method has no relation to the instance of the class.
7. Some related problems of runtime bindings are thrown. can only query the slightly. (*)
Runtime binding is also called dynamic binding: If there are inheritance, overrides, and parent objects pointing to the subclass instances, this results in polymorphism and at run time it is possible to know which child class the parent object is pointing to. For example: b b = a A (); At run time, you will know that B contains the address of instance a.
Binding to a static binding at compile time: it is loaded into memory during compilation, including Private, static, final modified variables and methods, and constructors, urban static bindings
Iv. is it possible to access non-static variables in a static environment?
Answer yourself:
The answer is yes, you can not, in fact, in the previous question to know, because static is loaded with the class, when the non-static variable is not loaded into memory, then static can not access non-static variables
Reference Answer:
The static variable belongs to the class in Java, and it has the same value in all instances. Static variables are initialized when the class is airborne into Java virtual. If your code tries to access a non-static variable without an instance, the compiler will give an error because the variables have not been created yet and are not associated with any instances.
Self-evaluation:
The question should be understood. Remember that static is loaded with the load of the class and takes precedence over non-static variables.
V. What types of data are supported by Java? What is auto-unboxing?
Answer yourself:
Reference data types and non-reference data types
Non-reference data types (eight types): integer: Byte, short, int, long, float: float, double, character: Char, Boolean: Boolean
Reference data type: Object, String,
Auto-boxing: refers to int--Integer double--double here can not say why, unfamiliar.
Reference Answer:
• Basic data types:
Integer value: Byte,short,int,long,
Character type: Char
Floating-point type: float,double
Boolean Type: Boolean
integer default int, decimal type double by default. The float and long types must be suffixed. • Reference data type: first know that a string is a reference type is not a base type, a variable that refers to a type declaration means that the variable is actually stored in memory as a reference address, and the entity is in the heap. Reference types include classes, interfaces, arrays, and so on. The string class is also final decorated. The wrapper class is a reference type, • Auto boxing and unpacking are conversions between the base type and the reference type, and as for why to convert, since the base type is converted to a reference type, the new object can be In order to invoke the wrapper class in the encapsulated method to convert between the basic type or ToString (of course, with the name of the class directly can also be used to see that the method is static), and if you want to store the base type in the collection, the generic qualified type can only be the corresponding wrapper type.
Self-evaluation: The basic data type is still known, the reference type interpretation should explain the essence. In the automatic boxing, the head only heard the noun, vaguely remember to read before, see is not to say
1, basic data type: Four class eight kinds
2, reference data type: The essence is to store the address in the heap, and in the stack there is a variable name pointing to the address in the heap, so that is the reference data type, String, array, collection, etc. are.
3. Auto Boxing: Convert int base data type to reference data type Integer,int has wrapper class Integer double has wrapper class double Boolean--Boolean uses up to two of the preceding, After the jdk1.5, there is automatic boxing function, that is, we do not need to manually, when necessary, will be automatically converted to the wrapper class to use some methods in the wrapper class,
4, why need packaging class? For example, a problem occurs when an int wants to convert to a string directly, so you need to first convert int to integer and then tostring:
5, when will be automatically boxed? For example, 1: boxing, such as int, if the parameter of a place needs to fill in an integer, you pass int to it, it automatically generates an integer to pass through. Conversely, the Integer variable int, is the automatic unpacking; for example 2:integer i = 100; This time also finished automatic boxing, 100 is only an int type, the bottom layer will automatically convert int in order to wrap the class integer.
Java Test face Test (i)