Interview question number 0 1-05
Q: What happens if the main method is declared private?
Answer: it can be compiled normally, but the runtime will prompt "main method is not public".
Question: What is the difference between passing a reference and passing a value in Java?
A: Reference refers to passing the address instead of the value itself, and the passed value is a copy of the passed value.
Q: If you want to override the equals method of an object, what else should you consider?
Answer: hashCode.
Question: How is Java's "write once, run everywhere" realized?
Answer: Java programs will be compiled into class files composed of bytecode, which can run on any platform, so Java is platform-independent.
Question: Explain the function of each keyword in the public static void main (String Args []) statement.
A: The public: main method is the first method called by a Java program at runtime, so it must be visible to the Java environment. So the visibility is set to public.
Static: The Java platform will not create an instance of this class when calling this method, so this method must be declared as static.
Void: main method has no return value.
String is the parameter type passed in from the command line, and args refers to the string array passed in from the command line.
Interview Question 06 -65438 +00
Q: What is the difference between = = and =
Answer: = = Compare whether two objects are the same object in memory, that is, whether the storage locations in memory are the same. Two String objects store the same value, but they may be stored in different locations in memory.
= = Compare references, and the equals method compares contents. The public boolean equals(Object obj) method is provided by the Object object and can be overridden by subclasses. The default implementation returns true only when the object is compared with itself, in which case, and = = are equivalent. Strings, bitsets, dates and files all override the equals method. For two string objects, equal values mean that they contain the same character sequence. For wrapper classes of basic types, equal values mean that the corresponding basic types have the same value.
Question: What happens if the static modifier of the main method is removed?
A: The program can be compiled normally. Runtime throws a NoSuchMethodError exception.
Q: Why is the oracle type4 driver called a thin driver?
A: oracle provides a class 4 JDBC driver called a thin driver. The driver includes a TCP/IP Net8 implementation completely implemented by oracle itself in Java, so it is platform-independent, can be downloaded by the browser at runtime, and does not depend on any client's oracle implementation. The client connection string uses the address port of TCP/IP instead of the tnsname of the database name.
Q: Introduce the finalize method.
Answer: finally: constant declaration. Finally: handle exceptions. Finalize: Help with garbage collection.
By default, variables declared in an interface are final variables. The last class cannot inherit, that is, it has no subclasses. This is done for security reasons of basic types such as strings and integers. This also makes the compiler do some optimization, making it easier to ensure thread safety. The final method cannot be overridden. The value of the final variable cannot be changed. The finalize () method is called before the object is destroyed and recycled. Finally, it is usually used for exception handling, and it will be executed whether an exception is thrown or not. For example, closing a connection is usually done in a finally block.
Question: What is Java API?
Answer: Java API is a collection of a large number of software components that provide a lot of useful functions, such as GUI components.
Interview question number 1 1- 15
Question: What is the GregorianCalendar class?
Answer: GregorianCalendar provides the support of western traditional calendars.
Q: what is the ResourceBundle class?
A: The ResourceBundle is used to store the resources in the specified language environment, and the application can load these resources according to the language environment at runtime, thus providing the presentation in different languages.
Question: Why are there no global variables in Java?
Answer: Global variables are globally visible, and Java does not support globally visible variables, because global variables violate the principle of reference transparency. Global variables caused namespace conflicts.
Question: How do I convert a string type to a number type?
A: the valueOf method of the Integer class can convert strings into numbers. The following is a code example:
Q: what is the SimpleTimeZone class?
A: SimpleTimeZone provides Gregorian date support.
Interview questionno. 16-20
Question: What's the difference between a while loop and a do loop?
A: The while structure determines whether the next iteration should continue at the beginning of the loop. The do/while structure is located at the end of the loop and is used to determine whether to continue the next iteration. Do structure will execute the loop body at least once.
Q: What is the Locale class?
A: The Locale class is used to dynamically adjust the output of the program according to the language environment.
Q: What is the principle of object-oriented programming?
A: There are three main points: polymorphism, inheritance and encapsulation.
Q: Introduce the principle of inheritance.
A: Inheritance enables one object to obtain the properties of another object. Using inheritance can make the tested function reusable and can be modified at one time, and all inherited places will take effect at the same time.
Q: What is implicit type conversion?
A: Implicit type conversion is simply assigning one type to another without explicitly telling the compiler that conversion has occurred. Not all types support implicit type conversion.
Code example:
Interview question 2 1-25
Question: is sizeof a keyword for Java?
Answer: No.
Q: What is a native method?
A: The native method is a method implemented by non-Java code.
Question: In System.out.println (), what are System, out and println respectively?
A: System is a predefined final class provided by the system, out is a PrintStream object, and println is an overloaded method in the out object.
Q: What are encapsulation, inheritance and polymorphism?
Answer: Simply put, polymorphism refers to multiple realizations of a name. Polymorphism enables an entity to implement different operations in a common way. The specific operation is determined by the actual implementation.
Polymorphism has three manifestations in Java: method overloading is realized by inheritance, and method rewriting is realized by Java interface.
Q: What is explicit type conversion?
A: Explicit type conversion explicitly tells the compiler to convert the object.
Code example:
Interview questions 26-30
Question: What is a Java virtual machine?
A: Java virtual machine is a software system that can be transplanted to different hardware platforms.
Question: What is type down conversion?
Answer: Downward conversion refers to the conversion from a general type to a specific type, which goes down in the inheritance structure.
Question: What is the access modifier of Java?
A: Access modifiers are keywords that indicate the access types of class members. Use these keywords to restrict access to methods or variables of a program. They include:
Public: all classes can access protected: all subclasses in the same package can access private: only the class can access default: all classes and subclasses in the same package can access it.
Question: What is the parent class of all classes?
Answer: Objection
Question: What are the basic types of Java?
Answer: byte, char, short, int, long, float, double, Boolean.
Interview question number 3 1-40
Q: What are the characteristics of static types?
Answer: Static variables are bound to classes, not instance objects of classes. Every instance object * * * enjoys the same static variables. In other words, a class has only one static variable, no matter how many objects it has. Class variables or static variables are declared by the keyword static. Class variables are usually used as constants. Static variables are usually accessed by the class name. This variable will be created when the program runs and will not be destroyed until the program ends. The range of class variables is the same as that of instance variables. Its initial value is the same as that of the member variable. When a variable is uninitialized, it will have a default value according to its data type. Similarly, a static method belongs to a class, not a class object, and its call does not act on the class object, nor does it need to create any class instance. The static method itself is final, because rewriting only happens on class instances. Static methods are bound to classes, not objects. As long as the original method is not declared as final, the static method of the parent class will be masked by the static method of the subclass. Non-static methods cannot override static methods, that is, they cannot be changed to instance methods in subclasses.
Non-static variables have a separate value on each object instance.
Question:&; Operator and &;; & What's the difference between operators?
A: When a &;; When evaluating the & expression, both operands will be evaluated. & It's more like a shortcut for an operator. Be a&; & When evaluating an expression, the first operand is calculated first, and if it returns true, the second operand is calculated. If the value of the first operand is fale, the second operand will not be evaluated.
Question: How does Java handle the overflow and underflow of integers?
Answer: Java stores the corresponding low-order bytes in the calculation results into the corresponding values according to the size of the type.
Question: what happens when public static void is written as static public void?
A: The program compiles and runs normally.
Q: What is the difference between declaring variables and defining variables?
Answer: To declare a variable, we only provide the type and name of the variable, but we have not initialized it. Definition includes two stages: declaration and initialization. Just a variable declaration, strings s = new string ("Bob"); Or String s = "bob, this is a variable definition.
Interview question no 4 1-45
Q: What type of parameter passing does Java support?
Answer: Java parameters are all passed values. For an object, the value passed is a reference to the object, that is, both the original reference and the copy of the parameter reference point to the same object.
Q: What is the principle of object encapsulation?
A: Encapsulation is to bind the data and the code that operates the data to an independent unit. This ensures the security of data and prevents the abuse of external code. Objects allow programs and data to be encapsulated to reduce potential interference. Another understanding of encapsulation is as a protective layer for data and code to prevent the code outside the protective layer from being randomly accessed.
Question: How to understand variables?
A: Variables are named memory areas accessed by programs. Variables are used to store data, and the stored data may change with the execution of the program.
Q: How much has the value increased?
A: Numerical promotion refers to converting data from a smaller data type to a larger data type for integer or floating-point operations. In the process of numerical promotion, byte, char and short values will be converted into int types. If necessary, the int type can also be promoted to the long type. Long and float can be converted to double types.
Question: What is the type conversion of Java?
A: Converting from one data type to another is called type conversion. Java has two types of conversion, one is explicit type conversion and the other is implicit type conversion.
Interview questions 46-50
Question: Among the parameters of the main method, what is the first parameter of the string array?
A: The array is empty and has no elements. Unlike C or C++, by default, the first element is the program name. If the command line does not provide any parameters, the string array in the main method is empty, but not null.
Question: How to judge whether an array is null or empty?
Answer: the value of array.length is output. If it is 0, the array is empty. If it is empty, a null pointer exception will be thrown.
Question: Can multiple classes be allowed to have the main method at the same time in the program?
Answer: Yes. When the program runs, we will specify the name of the running class. The JVM will only look for the main method in the class you specify. Therefore, when multiple classes have the main method, there will be no naming conflict.
Q: When are static variables loaded? Compile-time or runtime? When does the static code block load?
A: Static variables are created when the class loader loads the class into the JVM, regardless of whether the object is created or not. Allocate memory space when loading static variables. The code of a static code block will only be executed once when the class is initialized for the first time. A class can have multiple static code blocks, which are not members of the class, have no return value, and cannot be called directly. Static code blocks cannot contain this or super, which are usually used to initialize static variables.
Question: Can a class have multiple main methods?
A: Yes, but only one main method can have the following signature:
Otherwise, the program will not compile. The compiler will warn you that the main method already exists.
Interview question number 5 1-60
Q: How does the JVM work?
Answer: JVM is an abstract computer. Just like real computers, they compile first. The java file is converted into a. class file (a. class file is a bytecode file), and then the bytecode is loaded with its interpreter.
Question: What happens if the values of two variables are exchanged in situ?
Answer: first add two values to the first variable, and then subtract the result from the second variable to the second variable. Subtract the second variable from the first variable and assign the value to the first variable. The code is as follows:
You can also use XOR to exchange. The first method may also lead to overflow. The XOR method is as follows: int a=5, b =10; a = a+b; b = a-b; a = a-b;
Q: What is the encapsulation of data?
A: One way to encapsulate data is to create set and get methods in the class to access the data variables of the object. Generally speaking, variables are private, while get and set methods are public. Encapsulation can also be used for data verification when storing data, or calculating data, or for introspection (such as using javabean in struts). Encapsulating data and functions into an independent structure is called data encapsulation. Encapsulation is actually encapsulating data and associated operation methods into an independent unit, so that data can be accessed by using these associated methods. Encapsulation provides data security, which is actually a way to hide data.
Question: What is the reflection API? How is it achieved?
Answer: Reflection refers to the function of viewing the status and characteristics of a class at runtime and managing it dynamically. These functions are provided through the reflection API of some built-in classes, such as classes, methods, fields, constructors and so on. Use example: use the getName method of Java reflection API to get the class name.
Question: Does the JVM maintain its own cache, allocate objects in the heap, the heap of the operating system or the heap managed by the JVM itself? Why?
Answer: Yes, the JVM manages the cache itself. It creates objects in the heap and then references them in the stack.
Interview question number 6 1-66
Question: What is virtual memory?
Answer: Virtual memory is also called extended memory, but there is no real physical memory.
Question: Can a method be both static and synchronous?
Answer: Yes. If you do this, the JVM will get the lock of the instance of java.lang.Class associated with the object. Doing so is equivalent to:
Question: What's the difference between String and StringTokenizer?
A: StringTokenizer is a tool class used to split strings.
Question: What are the characteristics of transient variables?
A: Transient variables are not serialized. For example, when a class that implements the Serializable interface is serialized as an ObjectStream, a variable of type transient will not be written into the stream, and when deserialized, the value of the corresponding variable is null.
Question: Which containers use the border layout as the default layout?
Answer: window, frame, dialog box.
Q: What is synchronization?
Answer: Synchronization is used to control the access of multiple threads to the shared resource, so as to ensure that only one thread can access this resource at the same time. In a multithreaded program with asynchronous protection, when one thread modifies a shared variable, another thread may also use or update its value. Synchronization avoids the generation of dirty data.
The above answers are reproduced from the official WeChat account circle for job hunting, where there are more job interviews, so Cheng should learn ~