10 Java Interview Questions and Answers, java Interview Questions and answers

Source: Internet
Author: User

10 Java Interview Questions and Answers, java Interview Questions and answers

1. What is JVM? Why is Java A cross-platform programming language?
Java Virtual Machine (Java Virtual Machine) is a Virtual Machine that can execute Java bytecode. Each Java source file is compiled into a bytecode file and then executed in JVM. Java is designed to run on any platform without rewriting or re-compiling on different platforms, thanks to the Java Virtual Machine (JVM ), because JVM understands the length of specific commands and the particularity of the underlying hardware platform.
2. What is the difference between JDK and JRE?
Java Runtime Enviroment is the basic Java Virtual Machine for running Java programs, including browser plug-ins for executing applet. JDK (Java Development Kit) is a full-featured Java software Development Kit for developing, compiling, and executing Java applications, including JRE, compilers, and tools (such as JavaDoc and Java Debugger ).
3. How many features and specific features of Java object-oriented programming?
Java object-oriented programming has obvious features, such as encapsulation, inheritance, polymorphism and abstraction.
1) Encapsulation: provides the ability to hide internal characteristics and behaviors of objects. Each object provides some methods. Other objects can access and change their internal data. In Java, three access modifiers are provided: public, private, and protected. Each modifier sets different access permissions, this permission setting does not vary because of the package, you can access the Java object-oriented tutorial (http://www.atstudy.com/course/180) for bowei peak network through the link) view more details and instances.
2) polymorphism is a capability to present the same interface for different basic data types. polymorphism is a type of operation that can be applied to different types of values.
3) Inheritance provides an object's ability to obtain fields and methods from the base class. inheritance provides code reusability and adds additional functions to existing classes without changing existing classes.
4) Abstraction refers to the process of separating ideas from specific instances and developing them based on their respective functions rather than specific implementations. java supports creating and exposing abstract classes of interfaces, without the specific implementation of methods. The purpose of the abstract method is to separate the class behavior from the specific implementation.
4. can I access non-static variables in static methods?
The static variable in Java belongs to the corresponding class, and its value is the same for all instances of the class. Static variables are initialized when the JVM loads classes. If the code tries to access non-static variables and does not access them through the instance of the class, the compiler reports an error because these non-static variables have not been created yet, and they are not associated with the instance.
5. In Java, What Are methods Override (overwrite) and Overload (Overload )?
In Java, the condition that the method overload occurs is that two or more methods in the same class have identical names, but the parameter list is different. On the other hand, the override of a method means that the subclass redefines the same method in the parent class. The method of Override must have the same method name, parameter list, and return type. The Override method does not limit the access permission of the original method.
6. Does Java support multi-inheritance?
Java does not support multi-inheritance. Each class can only inherit one class, 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). However, a thread is an independent execution sequence in the process. A process can contain many threads. A thread is sometimes called a lightweight process.
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 are no longer needed by programs, so as to recycle and reuse resources.
9. When will finalize () be called? What is its purpose?
The finallize method is called by gc (Garbage Collector) before the object memory is released. We recommend that you release the resources held by the object in this method.
10. If an object's reference is set to null, Will gc immediately release the object's memory?
No, this object will be recycled in the next gc loop.

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.