Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

2021 version of JAVA top ten interview questions and answers


May 31, 2021 Article blog



1. Is String the most basic data type?

A: NO. J ava has a total of eight basic data types: byte, short, int, long, float, double, charlean, boolean;

-----------------------------------------------------------------------------------------------------------------------------------------

2. Does Java have a goto?

A: No. ( According to an appendix to The Java Programming Language, written by James Gosling,) there is a list of Java keywords with goto and const, but these two are currently unusable keywords, so some places call it a reserved word, which should actually have a broader meaning, as programmers familiar with the C language know, W ords or combinations of words of special meaning used in the system class library are considered reserved words)

-----------------------------------------------------------------------------------------------------------------------------------------

The difference between 3, and ?

There are two uses for the operator: (1) bit by bit and (2) logic and . T he operator is short-circuited with the operation. T he difference between logic and short circuits is huge, although both require that the Boolean values at the left and right ends of the operator are true values for the entire expression. T he reason for this is that if the value of the expression on the left is false, the expression on the right will be shorted directly and will not be evaluated. M any times we may need to use , for example, when verifying that the user login determines that the user name is not null and is not an empty string, it should be written as: username! . . . F ailure to do so results in a NullPointerException exception. N ote: Logic or operators (|) and short circuits or operators (|| T he same is true of the difference.

-----------------------------------------------------------------------------------------------------------------------------------------

4, switch can work on byte, can it work on long, can it work on String?

A: In Java 5, expr could only be byte, short, char, int;

-----------------------------------------------------------------------------------------------------------------------------------------

5. Is there a legth() method for arrays? D oes String have a leength() method?

A: The array does not have a leggth() method, and it has a legth attribute.

String has a leggth() method. I n JavaScript, the length of the obtained string is obtained through the legth property, which is easily confused with Java.

-----------------------------------------------------------------------------------------------------------------------------------------

6. Can the constructor be overridden?

A: The constructor cannot be inherited, so it cannot be overridden, but it can be overloaded.

-----------------------------------------------------------------------------------------------------------------------------------------

7, expound the difference between static variables and instance variables.

A: A static variable is a variable modified by a static modifier, also known as a class variable, which belongs to a class, does not belong to any object of a class, a class no matter how many objects are created, static variables have and only one copy in memory; S tatic variables can be implemented to allow multiple objects to share memory.

-----------------------------------------------------------------------------------------------------------------------------------------

8. Can an internal class reference a member of its containing class (external class)? A re there any restrictions?

A: An internal class object can access members of the external class object that created it, including private members.

-----------------------------------------------------------------------------------------------------------------------------------------

9. What is the use of the final keyword in Java?

A: (1) Decoration class: indicates that the class cannot be inherited;

(2) Modification method: means that the method cannot be overridden;

(3) Modify variable: indicates that the value cannot be modified (constant) after the variable can only be assigned once.

-----------------------------------------------------------------------------------------------------------------------------------------

10, the conversion between data types

How do I convert a string to a basic data type?

A: Call the method parseXXX (String) or valueOf (String) in the wrapper class for the base data type to return the corresponding base data type.

How do I convert a basic data type to a string?

A: One way is to connect the base data type to an empty string (")" to get its corresponding string, and the other is to call the valueOf() method in the String class to return the corresponding string.

Related reading recommendations:

What do you need to learn to develop java web?

What's good about the Java language? Why so many people choose Java back-end development

What language is javascript? What does it do?