JAVA Interview Basics

Source: Internet
Author: User

A classic Java Foundation question
___________________________________________________________________________________________


1. Question: How is Java's "write Once, run everywhere" implemented?

Answer: Java programs are compiled into a class file consisting of bytecode that can be run on any platform, so Java is platform independent.

2. Question: Explain the function of each keyword in the declaration of public static void main (String args[])

Answer: The Public:main method is the first method that is called when the Java program is run, so it must be visible to the Java environment. So the visibility is set to Pulic.

The Static:java platform calls this method without creating an instance of the class, so this method must be declared as static.

The Void:main method does not return a value.
String is the type of the command-line input parameter, and args refers to the string array that the command line passes into.

3. Question: What happens if the static modifier of the main method is removed?

Answer: The program compiles normally. The runtime throws a Nosuchmethoderror exception.

4. How do I convert a string type to number type?

Answer: The valueof method of the integer class can turn a string into number. The following is a code example:
String numstring = "1000″;
int id=integer.valueof (numstring). Intvalue ();

5. Question: What is the difference between the while loop and the Do loop?

Answer: The while structure determines whether the next iteration should continue at the beginning of the loop. Do/while structure at the end of the loop to determine whether the next iteration will continue. The do structure executes at least one loop body.

6. Question: What is implicit type conversion?

Answer: Implicit type conversion is simply a type assignment to another type, without explicitly telling the compiler that a conversion has occurred. Not all types support implicit type conversions.

code example:

int i = 1000;
Long j = i; Implicit casting

7. Question: What is an explicit type conversion?

The answer: Explicit type conversions are explicitly telling the compiler to convert objects.

code example:

Long i = 700.20;
int j = (int) i; Explicit Casting

8. Question: What is a Java virtual machine?

Answer: A Java Virtual machine is a software system that can be ported to different hardware platforms.


9. Question: What is the parent class for all classes?

Answer: Object.

10. Question: What are the basic types of Java?

Answer: Byte,char, short, int, long, float, double, Boolean.

11. What is the difference between the question:& operator and the && operator?

Answer: When an & expression is evaluated, the two operands are evaluated,&& more like a shortcut to an operator. When an && expression evaluates, the first operand is evaluated first, and if it returns true, the second operand is evaluated. If the first operand is a value of Fale, the second operand is not evaluated.

12. Question: What happens if public static void is written as static public void?

Answer: The program compiles and runs normally.

13. Question, what is the difference between declaring a variable and defining a variable?

Answer: Declaring a variable we only provide the type and name of the variable, and it is not initialized. The definition consists of declaring and initializing a two-stage string s; just a variable declaration, string s = new String ("Bob"); or string s = "Bob"; is a variable definition.
14. Question: How do you understand variables?

Answer: A variable is a named area of memory for the program to access. Variables are used to store data, and as the program executes, the stored data may change.


15. Question: What is a numeric promotion?

Answer: Numeric promotion refers to the conversion of data from a smaller data type into a larger data type for integer or floating-point operations. During numeric promotion, the Byte,char,short value is converted to the int type. The int type may also be promoted to long when needed. Long and float are likely to be converted into double types.


16. Question: Can I allow multiple classes to have a main method in the program?

Answer: Yes. When the program runs, we specify the class name to run. The JVM will only look for the main method in the class you specify. Therefore, multiple classes have a Main method and there is no naming conflict problem.

17. Question: Can a class have more than one main method?

Answer: Yes, but only one main method has the following signature:

public static void Main (string[] args) {}
Otherwise, the program will not compile. The compiler warns you that the main method already exists.


18. Question: How does the JVM work under a simple introduction?

The answer: The JVM is an abstract computer, just like a real computer, that compiles. java files into a. class file (the. class file is a bytecode file), and then uses its interpreter to load the byte code.

JAVA Interview Basics

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.