Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the Java test questions?

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what are the Java test questions". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the Java test questions"?

Topic 1: float a = 0.125f; double b = 0.125d; System.out.println ((a-b) = = 0.00.What is the output of the code?

A. True

B. False

Topic 2: double c = 0.8; double d = 0.7; double e = 0.6; is c Mel d equal to d Mel e?

A. True

B. False

Topic 3: what is the result of System.out.println (1.0 / 0)?

a. Throw an exception

B. Infinity

C. NaN

Topic 4: what is the result of System.out.println (0 / 0 / 0)?

a. Throw an exception

B. Infinity

C. NaN

D. 1.0

Topic 5: what is the difference between > > and > >?

a. There is no difference between any integer

b. There must be no difference between negative integers

c. Floating point numbers can be operated > >, but not >.

d. There must be no difference between positive integers

Topic 6: a class has two overloaded methods: void f (String s) and void f (Integer I). Which method will be called by f (null)?

a. The former

b. The latter

c. Random call

d. Compilation error

Topic 7: a class has two overloaded methods: void g (double d) and void g (Integer I). Which method will be called by g (1)?

a. The former

b. The latter

c. Random call

d. Compilation error

Topic 8: String a = null; switch (a) which item in case matches?

A. Null

B. "null"

c. Does not match anything, but does not throw an exception

d. Throw an exception directly

Topic 9: String get (String string, T t) {return string;} this method:

a. Compilation error, first String from left to right

b. Compilation error, T

c. Compilation error, at Alibaba

d. Compile correctly

Topic 10: the initial capacity of HashMap is 10000, that is, new HashMap (10000). When you put 10000 elements, how many times do you need resize (the initialization does not count)?

A. 1 time

B. 2 times

C. 3 times

D. 0 times

Answer:

Topic 1: float a = 0.125f; double b = 0.125d; System.out.println ((a-b) = = 0.00.What is the output of the code?

A. True

B. False

Explanation: first of all, the floating point number is composed of symbol bits, exponential bits and significant numbers, while 0.125f and 0.125d can be accurately expressed, there is no precision loss, so a-b==0.0.

Topic 2: double c = 0.8; double d = 0.7; double e = 0.6; is c Mel d equal to d Mel e?

A. True

B. False

Explanation: similar to the fraction 1Accord 3 in the decimal system, which is an infinite cyclic number, it cannot be accurately expressed, and some values in the same floating-point number cannot be accurately expressed.

System.out.println (0.8-0.7); / / output 0.100000000000009

System.out.println (0.7-0.6); / / output 0.099999999999998

Topic 3: what is the result of System.out.println (1.0 / 0)?

a. Throw an exception

B. Infinity

C. NaN

Explanation: in an integer operation, the divisor cannot be 0, otherwise the exception will run directly. But in floating-point operation, the concept of infinity is introduced. You can take a look at the definition of the source code Double. Public static final double POSITIVE_INFINITY = 1 / 0. 0.

Topic 4: what is the result of System.out.println (0 / 0 / 0)?

a. Throw an exception

B. Infinity

C. NaN

D. 1.0

Explanation: java source code, Double packaging class, public static final double NaN = 0.0d / 0.010 nan means non-numeric, it is not equal to any value, or even equal to itself.

Topic 5: what is the difference between > > and > >?

a. There is no difference between any integer

b. There must be no difference between negative integers

c. Floating point numbers can be operated > >, but not >.

d. There must be no difference between positive integers

Explanation: >

Topic 6: a class has two overloaded methods: void f (String s) and void f (Integer I). Which method will be called by f (null)?

a. The former

b. The latter

c. Random call

d. Compilation error

Explanation: 1) exact matching-> 2) basic data types (automatically converted to a larger range)-> 3) Packaging classes (automatic unpacking and packing)-> 4) upward transformation of subclasses-> 5) variable parameter matching. The subclass is transformed upwards, and the parent of both is the object class (the default type of null is object), so it matches both, and the compiler reports Ambiguous method call. Both error

Topic 7: a class has two overloaded methods: void g (double d) and void g (Integer I). Which method will be called by g (1)?

a. The former

b. The latter

c. Random call

d. Compilation error

Explanation: 1) exact matching-> 2) basic data types (automatically converted to a larger range)-> 3) Packaging classes (automatic unpacking and packing)-> 4) subclasses upward transformation matching-> 5) variable parameter matching. This topic is on to the second step of matching.

Topic 8: String a = null; switch (a) which item in case matches?

A. Null

B. "null"

c. Does not match anything, but does not throw an exception

d. Throw an exception directly

Explanation: in the judgment of the designers of the Java programming language, this makes more sense than silently skipping the entire switch statement, because the code written will never be executed if you use null as the switch tag.

Topic 9: String get (String string, T t) {return string;} this method:

a. Compilation error, first String from left to right

b. Compilation error, T

c. Compilation error, at Alibaba

d. Compile correctly

Explanation: each element in angle brackets refers to an unknown type, and only has the ability to execute the Object method at the definition. During compilation, all generic information is erased. After compilation, the two parameters of get () are Object, and the return value is also Object.

Topic 10: the initial capacity of HashMap is 10000, that is, new HashMap (10000). When you put 10000 elements, how many times do you need resize (the initialization does not count)?

A. 1 time

B. 2 times

C. 3 times

D. 0 times

Explanation: larger than 10000, and the nth power of the nearest 2 is 16384, and the default load factor is 0.75, 16384, 0.75 = 12288 > 10000, so there is no need for capacity expansion.

Thank you for your reading, the above is the content of "what are the Java test questions?" after the study of this article, I believe you have a deeper understanding of what the Java test questions have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report