In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what are the top ten interview questions in JAVA". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Is String the most basic data type?
A: NO. Java has a total of eight basic data types: byte, short, int, long, float, double, char, boolean; except the basic type (primitive type), the rest are reference types (reference type). The enumerated type introduced after Java 5 is also a special reference type.
- -
2. Does Java have goto?
A: no. The appendix to the book "The Java Programming Language" written according to James Gosling (the father of Java) gives a list of Java keywords, including goto and const, but these two keywords cannot be used at present, so they are called reserved words in some places, but the word reserved words should have a broader meaning, because programmers familiar with the C language know that. Words or combinations of words with special meaning used in the system class library are regarded as reserved words)
- -
3. The difference between & and &?
Answer: the & operator has two uses: (1) bitwise and; (2) logical and. The & & operator is a short circuit and operation. The difference between logic and short circuit is huge, although both require that the Boolean values at the left and right ends of the operator are both true. The value of the entire expression is true. The reason why it is called a short-circuit operation is that if the value of the expression on the left of & & is false, the expression on the right will be short-circuited directly and will not operate. In many cases, we may need to use & instead of &. For example, when verifying that the user login user name is not null and is not an empty string, it should be written as: username! = null &! username.equals (""). The order of the two cannot be exchanged, let alone the & operator, because if the first condition is not true, string equals comparison cannot be done at all, otherwise a NullPointerException exception will occur. Note: the same is true of the difference between logic or operator (|) and short circuit or operator (| |).
- -
4. Can switch act on byte, long and String?
Answer: before Java 5, in switch (expr), expr can only be byte, short, char, and int;. Enumerated types are introduced into Java, and expr can also be enum type. Since Java 7, expr can also be a string (String), but long integer (long) is not allowed in all current versions.
- -
5. Is there a length () method for the array? Is there a length () method for String?
Answer: the array has no length () method and has an attribute of length.
String has a length () method. In JavaScript, getting the length of a string is obtained through the length attribute, which is easily confused with Java.
- -
6. Can the constructor be rewritten (override)?
A: constructors cannot be inherited, so they cannot be overridden, but can be overloaded.
- -
7. Explain the difference between static variables and instance variables.
A: a static variable is a variable modified by the static modifier, also known as a class variable. It belongs to a class and does not belong to any object of the class. No matter how many objects a class creates, the static variable has only one copy in memory; the instance variable must depend on an instance. You need to create an object and then access it through the object. Static variables allow multiple objects to share memory.
- -
8. Can an inner class refer to a member of its containing class (external class)? Are there any restrictions?
Answer: an inner class object can access members of the external class object that created it, including private members.
- -
9. What are the uses of the final keyword in Java?
Answer: (1) modifier class: indicates that this class cannot be inherited
(2) Modification method: indicates that the method cannot be rewritten
(3) modifier variable: indicates that the variable can only be assigned once and the value cannot be modified (constant).
- -
10. Conversion between data types
How do I convert a string to a basic data type?
Answer: call the method parseXXX (String) or valueOf (String) in the wrapper class corresponding to the basic data type to return the corresponding basic data type.
How do I convert a basic data type to a string?
Answer: one way is to concatenate (+) the basic data type with an empty string (") to get its corresponding string; the other is to call the valueOf () method in the String class to return the corresponding string.
This is the end of the content of "what are the Top Ten interview questions for JAVA". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.