10 Java face questions and answers

Source: Internet
Author: User

1. What is a JVM? Why is Java called a cross-platform programming language?
Java virtual machines are virtual machines that can execute Java bytecode, and each Java source file is compiled into a bytecode file and then executed in the JVM. Java is designed to run on any platform without rewriting or recompiling on a different platform, thanks to the Java Virtual Machine (JVM), because the JVM knows very well the length of a particular instruction and the specificity of the underlying hardware platform.
2. What is the difference between JDK and JRE?
The Java Runtime Environment (Java Runtime enviroment) is the basic Java virtual machine that runs Java programs, including the browser plug-in that executes applets. The JDK (Java Development Kit) is designed to develop, compile, and execute Java applications, full-featured software development packages for Java, including JRE, compilers, and tools (such as JAVADOC and Java Debugger).
3.Java Object-oriented programming of several characteristics and specific characteristics?
Java object-oriented programming has its very obvious features, such as encapsulation, inheritance, polymorphism, and abstraction.
1) encapsulation, which provides an ability for objects to hide internal features and behaviors, each object provides some way for other objects to access and change their internal data. In Java, three access modifiers are available: public, private, and protected. Each modifier has different access rights, and this permission setting does not vary depending on the package, so you can view more details and examples of encapsulation by linking to the Java object-oriented tutorial (http://www.atstudy.com/course/180) for peak net.
2) polymorphism, which is the ability to present the same interface for different underlying data types, is a type whose operations can be applied to different types of values.
3) inheritance, provides a capability for an object to get fields and methods from a base class. Inheritance provides the reusability of code and adds additional functionality to existing classes without changing existing classes.
4) Abstraction is the process of separating ideas from specific instances and developing classes according to their respective functions rather than specific implementations. Java supports the creation and presence of abstract classes that expose interfaces, without including a concrete implementation of the method. The purpose of abstract methods is to leave the behavior of the class and the concrete implementation.
4. Can I access non-static variables in a static method?
The static variable in Java is owned by the corresponding class, and its value is the same for all instances of the class. The static variable is initialized when the JVM loads the class. If the code attempts to access a non-static variable and is not accessed through an instance of the class, the compiler will make an error because the non-static variables have not yet been created, and they are not associated with the instance.
5. What is the override (overwrite) and overload (overload) of methods in Java?
The overload of a method in Java occurs when two or more method names are identical in the same class, but the parameter list is different. On the other hand, the override of a method means that the child class redefined the same method in the parent class. The Override method must have a method name, a parameter list, and a return type that are identical. The Override method does not restrict access to the original method.
does 6.Java support multiple inheritance?
Java does not support multiple inheritance, and each class allows only one class to be inherited, but multiple interfaces can be implemented.
7. What is the difference between a process and a thread?
A process is the execution of a program (that is, a running program), whereas a thread is a separate execution sequence in the process. A process can contain many threads. Threads are sometimes referred to as lightweight processes.
8. What is the purpose of garbage collection in Java and when is it used?
Garbage collection is used to identify and discard objects that the program no longer needs in order to reclaim and reuse resources.
9. When is Finalize () called? What is the purpose of it?
The Finallize method is called by the GC (garbage collector) before releasing the object memory. It is generally recommended to release the resources held by the object in this method.
10. If a reference to an object is set to NULL, does the GC immediately release the object's memory?
No, this object will be recycled in the next GC cycle.

10 Java face questions and answers

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.