100 Java Surface Questions collection and collation and reference answers

Source: Internet
Author: User
Tags array length finally block garbage collection how to prevent sql injection square root string format file transfer protocol multiple inheritance in java

Not accumulate Kuibu not even thousands of miles, here will continue to collect and update the Java Foundation related questions, currently has collected 100 questions.

1. What is the B/s structure? What is the C/s architecture
    1. b/S (browser/server), browser/server program

    2. c/S (client/server), client/server, desktop applications

2. What do you know about network protocols?

HTTP: Hypertext Transfer Protocol
FTP: File Transfer Protocol
SMPT: Simple Mail protocol
TELNET: Remote terminal protocol
POP3: Mail Read protocol

What are the development platforms for 3.Java?
Java SE: Mainly used in the client development Java EE: Mainly used in Web application development Java ME: Mainly used in embedded application development
4. What is a JVM? What does a Java virtual machine include?

Jvm:java virtual machines, using hardware or software means to implement virtual computers, Java Virtual machines include: registers, stacks, processors

Does 5.Java require developers to recycle memory waste?

Most of the cases are not needed. Java provides a system-level thread to track memory allocations, and memory areas that are no longer used will be automatically recycled

6. What is a JDK? What is a JRE?

Jdk:java Development Kit:java Developer Kit, the environment that developers need to install

Jre:java Runtime Environment:java running environment, Java program needs to install the environment to run

7. What is a data structure?

How the computer saves and organizes the data

What are the 8.JAVA data structures?
Linear table (ArrayList) linked list (LinkedList) stack (stack) queue (queue) graph (map) tree (tree)
9. What is OOP?

Object-Oriented Programming

10. What is object-oriented?

All things in the world can be regarded as an object. Each object consists of dynamic behavior and static properties, which constitute an object.

11. What is the relationship between classes and objects?

A class is an abstraction of an object that is a concrete class, a template for an object, an instance of a class.

There are several data types in 12.Java
Xxx:byte,short,int,long floating-point type: float,double character type: Char Boolean: Boolean
13. What is implicit conversion and what is an explicit conversion

A display transformation is a type-strong, forcing a large type of data to be assigned to a small type of data; Implicit conversions are a wide range of variables that accept small-scale data; Implicit and explicit conversions are essentially automatic type conversions and forced type conversions.

Can the 14.Char type be converted to int type? Can be converted to a string type, can be converted into a double type

Char is also a special type in Java, its int value starting from 1, a total of 2 16 data; The Char<int<long<float<double;char type can be implicitly converted to the int,double type. But it cannot be implicitly converted to a string, and a strong turn is required if the char type is converted to the Byte,short type.

15. What is unboxing?
Unpacking: Turning the package type into a basic data type boxing: Turning the basic data type into a wrapper type
What are the packing classes in 16.Java?
Byte:Byteshort:Shortint:Integerlong:Longfloat:Floatdouble:Doublechar:Characterboolean:Boolean
17. What is included in a Java class?

Properties, methods, inner classes, construction methods, code blocks.

18. For example: if (a+1.0=4.0), so do it?

Not good, because the computer in the floating-point data operation, there will be errors, as far as possible in the Boolean expression does not use floating-point data (If,while,switch to determine the condition does not use floating-point type)

19. How do you solve the problem of errors in floating-point data operations?

Operation of floating-point data using the BigDecimal class

The difference between 20.++i and i++
++i: Assign first, then calculate i++: Calculate first, then assign the value
21. What are the structure of the program?
Sequential structure selection structure cycle structure
22. How are there several ways to instantiate an array?

Static instantiation: When an array is created, the elements in the array are specified,

Int[] A=new int[]{1,3,3}

Dynamic instantiation: When an array is instantiated, only the extent of the array is specified, and all elements in the array are the default values of the array type

Various data defaults in 23.Java
Byte,short,int,long default is both 0Boolean default value is the default value of Falsechar type is ' float ' with double type default is 0.0 object type default value is null
What are the 24.Java popular packages?
Java.langJava.ioJava.sqlJava.utilJava.awtJava.netJava.math
What is the top 25.Java parent class?

Object

What are the common methods of the 26.Object class?
Equalshashcodetostringwaitnotifyclonegetclass
Is there a pointer in 27.java?

There are pointers, but hidden, and developers cannot manipulate pointers directly by the JVM to manipulate pointers

is the value pass reference pass in 28.java?

In theory, Java is a reference pass, and for the base data type, the pass is a copy of the value, not the value itself. For object types, passing is a reference to an object, and when a method operates on an action parameter, the object that the reference is directed to is actually manipulated.

29. Suppose that the variable of an instantiated array is treated as a method parameter, and the elements within the array are changed when the method executes, does the array element change outside the method?

Changed because the pass is a reference to the object, the object to which the reference is directed

30. After instantiating an array, can you change the length of the array?

No, once an array is instantiated, its length is fixed.

31. Suppose there are 5 elements in the array, what if the arrays are reversed?

Creates a new array that iterates through each element from the back to the front, placing the extracted elements sequentially into the new array

32. Participate in the actual parameter

Formal parameters, which are all called "formal arguments," are parameters used when defining method names and method bodies, for receiving the actual values that are passed in when the method is called, and the actual parameters, which are all called "actual arguments," and are the real values that are passed to the method when the method is called.

33. Can the construction method be explicitly called?

You cannot construct a method as a normal method call, but it is called by the system only when the object is created.

34. Can the construction method be rewritten? Can it be overloaded?

Can be overridden, or can be overloaded

35. What is method overloading?

The overload of a method is to allow more than one method of the same name to exist in the same class, as long as they have a different number of arguments or types. In this case, the method is called overloaded, and this process is called the overload of the method (override)

36. What is the difference between an inner class and a static inner class?

The static inner class is independent of the outer class, and the variables, methods in the outer class cannot be accessed directly in the static inner class. If you want to access it, you have to new an object of the external class, using the new object to access it. But can directly access static variables, call static methods;

The ordinary inner class exists as a member of the outer class, and the external class property can be accessed directly in the ordinary inner class, calling the method of the outer class.

If an external class is to access the properties of an inner class or invoke a method of an inner class, you must create an object of an inner class that uses that object to access the property or invoke the method.

If other classes want to access the properties of ordinary inner classes or invoke methods of ordinary inner classes, you must create an object of the ordinary inner class in the outer class as an attribute, and the other class can invoke the method of the ordinary inner class or access the properties of the ordinary inner class through this property

If other classes want to access the properties of a static inner class or invoke a method of a static inner class, create a static inner class object directly.

What is the role of 37.Static keywords?

Static can modify inner classes, methods, variables, code blocks

Static-modified classes are statically internal classes

Static methods are static methods that indicate that the method belongs to the current class, but not to an object, and that it cannot be overridden, and can be invoked directly using the class name. The this or Super keyword cannot be used in the static method.

The static modifier variable is either a statically variable or a class variable, and the static variable is shared by all instances and is not dependent on the object. Static variables have only one copy in memory, and when the JVM loads the class, it allocates only one memory at a time.

Static-decorated blocks of code are called Block blocks, which are usually used for program optimization. Code in a static code block executes only once when the entire class is loaded. Static code blocks can have more than one, and if there are multiple, execute sequentially in order.

The role of 38.Final in Java
Final can modify the class, modify the method, and modify the variable. The decorated class is called the final class. The class cannot be inherited. The modified method cannot be overridden. The modified variable is called a constant, the constant must be initialized, and once initialized, the value of the constant cannot be changed.
What class is used for manipulating strings in 39.Java?

String,stringbuffer,stringbuilder

What's the difference between 40.stringbuffer,stringbuilder?

Both StringBuffer and StringBuilder inherit the Abstractstringbulder class, and Abtractstringbuilder implements the Charsequence interface, and two classes are used for string manipulation.

The efficiency is higher than string when you modify the delete substitution.

StringBuffer is thread-safe and StringBuilder is non-thread safe. So StringBuilder is more efficient than stringbuffer, and most of StringBuffer's methods are added synchronized keywords.

41.String str= "AAA", like string Str=new string ("AAA")?
Not the same. Because memory allocations are different in the same way. First, the "AAA" created is a constant, and the JVM allocates it in a constant pool. The second is to create an object that the JVM assigns its value to in heap memory.
42.String str= "AA", String s= "BB", string aa=aa+s; How many objects have you created?

A total of two references, three objects. Because both "AA" and "BB" are constants, the value of the constant cannot be changed, and when the string concatenation is performed, a new constant is created that is "aabbb" and has to be stored in a constant pool.

43. What are the common methods for the math class in Java?
Pow (): Power Operation sqrt (): square root round (): Rounding abs (): Seeking absolute value random (): Generates a 0-1 stochastic number, including 0 excluding 1
What are the common methods of 44.String classes?
CharAt: Returns the character at the specified index indexof (): Returns the index of the specified character replace (): string replacement trim (): Remove both ends of the string split (): Splits the string, returns a segmented string array getbytes () : Returns a string of byte type array length (): Returns the string toLowerCase (): Converts the string to lowercase touppercase (): Converts the string to uppercase characters substring (): Intercepts the string format () : format string Equals (): string comparison
45. Determine if two objects are the same, can you compare them using Equlas?

No. Equlas are mostly used to make string comparisons, and to determine the basic data type or object type, you need to use = =

What is the difference between 46.== and Equlas?

= = To determine whether the basic data type values are equal, or to determine whether the two objects point to the same memory address, that is to say whether two objects are the same object, Equlas is usually used to do string comparisons.

47. How do I reverse a string?

The reverse method of StringBuilder or StringBuffer

48. What are the characteristics of object-oriented languages?

Encapsulation, inheritance, polymorphism

Whether inheritance in 49.Java is single or multi-inheritance

There are both single and multiple inheritance in Java. There can be only one parent class for Java classes, and for interfaces it is possible to inherit multiple interfaces at the same time

50. What is rewriting? What is overloading?

Overloading and rewriting are all manifestations of Java polymorphism.

Overloading is called override, which behaves in polymorphic form in the same class. When multiple methods of the same name appear in a class, but the number of arguments differs from the parameter type, the method overload is independent of the return value

Rewriting is called overwrite, which is the representation of polymorphism in a character class. When a subclass appears the same way as the parent class, this is the method override. When a method is overridden, the return value of the subclass must be consistent with the parent class. If the parent class method throws an exception, the method that the subclass overrides throws an exception type that cannot be less than the exception type thrown by the parent class.

51. Can the construction method be overloaded? Can you rewrite it?

Can be overloaded and must be overridden

52. If the parent class has only a constructor method, does the subclass have to override the constructor of the parent class?

Must override

53. When you create a subclass object, does the parent class construct the method?

will be executed. When you create a subclass object and call the subclass constructor method, the subclass constructor method calls the parent class's constructor by default.

54. What is a parent class reference to a subclass object?

is a special form of representation of Java polymorphism. Create a parent class reference, and let the reference point to the object of a child class

55. When the parent class references a child class object, the subclass overrides the parent class method and property, and when the property is accessed, whose property is accessed? Whose method is called when the method is called?

Subclasses override the parent class methods and properties, access the properties of the parent class, and call the methods of the subclass

What does 56.Super and this mean?
Super represents the parent class object of the current class this represents the object of the current class
57. What are the abstract keywords?

Abstract

58. Should abstract classes have abstract methods?

Not necessary. Abstract classes can have no abstract methods.

59. If there is an abstract method in a class, then this must be an abstract class?

Classes that contain abstract methods must be abstract classes

60. Can an abstract class use final decoration?

No. The definition of an abstract class is for others to inherit, and the final decorated class means that the class cannot be inherited, contrary to the idea of an abstract class.

61. What is the difference between an ordinary class and an abstract class?
Ordinary classes cannot contain abstract methods, abstract classes can contain abstract methods abstract classes cannot be instantiated directly, ordinary classes can be instantiated directly
62. What is an interface?

An interface is a statement of some function that is provided externally, and is a special Java class

63.JAVA Why do I need an interface?

Interface compensates for the drawbacks of Java single inheritance

64. What are the features of the interface?
All methods in an interface that declare all public static final modifiers are abstract method interfaces are interfaces that do not have a constructor method, and cannot instantiate interfaces directly can inherit multiple
65. What is the difference between an interface and an abstract class?
Abstract class has a constructor method, the interface is not constructed method abstract class can only be single-inheritance, the interface can inherit the abstract class may have a common method, all the methods in the interface are abstract method interface properties are public static final decoration, and the abstract is not
What are the two types of anomalies in 66.Java?
Compile-time exception run-time exception
67. Say a few common compile-time exception classes?
NullPointerException: null pointer exception arrayindexoutofboundsexception: array subscript out-of-bounds NumberFormatException: Numeric conversion exception illegalargumentexception: Parameter mismatch Exception Instantiationexception: Object initialization Exception ArithmeticException: Arithmetic exception
68. What are the handling mechanisms for exceptions?

Exception catch: Try...catch...finally, Exception thrown: throws.

69. How to customize an exception

Inherit an exception class, usually Rumtimeexception or exception

70. If an exception occurs when an exception is caught, does the return statement outside the try.catch.finally block execute?

Executes, if there is finally, is executed after finally, if no finally is executed after the catch

Does 71.try.catch.finally have to exist?

Try block must exist, catch and finally can not exist, but not at the same time does not exist

The difference between 72.Thow and THORWS
Throw is written in the code block, the throw is followed by a specific exception instance throw is written in front of the method, followed by the exception class throws, the exception class can appear multiple
What is the difference between 73.Error and exception?

Both error and exception are part of the Java error handling mechanism and inherit the Throwable class.

Exception represents an exception that can be captured by the program or optimized to avoid.

Error indicates a system error and cannot be handled by the program.

74. Does using log4j have any effect on the program?

Yes, log4j is used for logging, logging some key sensitive information, usually logging to a local file or database. Recording in a local file, there are frequent IO operations that can consume some system resources. Logging in the database, the database tables are frequently manipulated, and have a certain impact on system performance. But for program security and data recovery or bug tracking, this resource consumption can be affordable.

How many levels does the 75.log4j log have?

From low to High: Debug, info, Wran, error

76. In addition to using new to create objects, what methods can I use to create objects?

Java Reflection

77.Java is it high efficiency to create objects or create objects from new?

Creating objects with new is more efficient. By reflection, find class resources, use the class loader to create, the process is more cumbersome, so less efficient

How many in the 78.Java collection frame?

Coillection, Map.

What are the set frames under the 79.Collection interface?

List: Linear table, set: Unordered collection.

What are the features of the 80.List interface?

Sequential storage, can have duplicate values.

What are the features of the 81.Set interface?

No storage, no duplicate values.

What is the difference between 82.ArrayList and LinkedList?
Both ArrayList and LinkedList implement the list interface. ArrayList is a linear table, the bottom layer is implemented using an array, it is more efficient at the end of inserting and accessing data, linked is a doubly linked list, he is more efficient in intermediate or head insertion, and is less efficient when accessing data
What's the difference between 83.Array and ArrayList?

Both arrays and ArrayList are collections of data that are used for storage. The ArrayList is implemented using arrays, but the ArrayList array is encapsulated and expanded, with many features that are not available in native arrays. We can understand that ArrayList is an upgraded version of the array.

What are the characteristics of 84.MAP
Storing data elements in a key-value order is not necessary. Duplicate keys are not allowed
Steps for 85.JDBC operation
Load database driver class Open database connection Execute SQL statement process return result close resource
86. How to prevent SQL injection from occurring when using JDBC.

Use the PreparedStatement class instead of the statement class

87. How to invoke a stored procedure within JDBC

Using CallableStatement

88. Are you aware of connection pooling and what are the benefits of using connection pooling?

Database connections are very resource-intensive and affect the performance metrics of the program. Connection pooling is used to allocate, manage, and release database connections, allowing applications to reuse the same database connection instead of creating a new database connection each time. Improve program performance by freeing database connections that are idle for long periods of time to avoid connection misses caused by creating too many connections.

89. What are the data source technologies that you know about? What are the benefits of using a data source?

Dbcp,c3p0 and so on, with the most or c3p0, because c3p0 than Dbcp more stable, secure, through the form of configuration files to maintain database information, rather than hard-coded. When the database information of the connection changes, it does not need to change the program code to realize the update of the database information.

What are the two types of IO streams for 90.Java?

According to the function to divide

Input stream, output stream

According to the type of

Byte stream, character stream
91. What are the common IO classes?
Filefileinputsteam,fileoutputstreambufferinputstream,bufferedoutputsreamprintwritefilereader, Filewriterbufferreader,bufferedwriterobjectinputstream,objectoutputsream
92. The difference between a byte stream and a stream of characters
Input output data in bytes, byte stream input and output data in characters according to 8-bit transmission, character stream according to 16-bit transmission
93.final, Finalize (), finally the nature of different
    1. Final is the key word;

    2. Finalize () as the method;

    3. Finally is the chunk flag, which is used in a try statement;

Role
    1. Final is the keyword used to identify constants, and the final identified keywords are stored in a constant pool (where the concrete usage of final constants is described below);

    2. The Finalize () method is defined in object to be invoked by the JVM when the object "disappears" for garbage collection of objects, similar to a destructor in C + +, which frees up resources used by objects (such as i/0 operations) when the user is customized;

    3. finally{} is used to identify a block of code, with try{}, regardless of whether the code in the try is finished or not executed (meaning there is an exception), the code block of the program will be done;

94. What are the differences between abstract classes and interfaces?

Abstract class:

    1. Abstract methods, only the concept of behavior, no specific behavior implementation. With the abstract keyword modifier, there is no method body. Subclasses must override these abstract methods.

    2. The class that contains the abstract method must be an abstract class.

    3. Abstract classes can only be inherited, and a class can inherit only one abstract class.

Interface:

    1. All the methods are abstract, and the genera are constants.

    2. You cannot instantiate, you can define variables.

    3. An interface variable can refer to an instance of a specific implementation class

    4. Interfaces can only be implemented, a concrete class implements an interface, and all of the abstract methods must be implemented

    5. Multiple implementations between interfaces

    6. A specific class can implement multiple interfaces to achieve multiple inheritance phenomena

95. Methods for Thread synchronization
    1. Wait (): Let the thread wait. Stores a thread in a thread pool.

    2. Notify (): Wakes the waiting thread. The first one in the thread pool is usually awakened. Let the awakened thread be in a temporary blocking state.

    3. Notifyall (): Wakes up all the waiting threads. Wakes all threads in the thread pool.

96. Thread-to-process differences

A process is an independent unit of system resource allocation and scheduling, and threads are the basic unit of CPU dispatch and dispatch.

Relationship of process and thread:

    1. A thread can belong to only one process, while a process may have multiple threads, but at least one thread.

    2. A resource is assigned to a process, and all the threads of the same process share all the resources of that process.

    3. Threads need to be synchronized during execution. Synchronization is achieved between threads of different processes using the means of message communication.

    4. A thread is an execution unit within a process and a scheduler within a process.

The difference between a thread and a process:

    1. Dispatch: A thread acts as the basic unit of dispatch and allocation, and processes as the basic unit of resources.

    2. Concurrency: Not only can concurrent execution between processes, but also concurrent execution between multiple threads of the same process.

    3. Owning a resource: a process is an independent unit that owns resources, and threads do not own system resources, but can access resources that belong to the process.

    4. System overhead: When creating or revoking a process, the system is significantly larger than the cost of creating or revoking a thread, because the system allocates and reclaims resources for it. However, the process has a separate address space, and after the process crashes, it does not affect other processes in protected mode, and the thread is just a different execution path in a process. Thread has its own stack and local variables, but there is no separate address space between the threads, a thread dead is equal to the entire process dead, so the multi-process program is more robust than multithreaded programs, but in the process of switching, the cost of large resources, the efficiency is worse.

The difference between 97.& and &&

& is a bitwise operator. && is a Boolean logical operator, and the contents of the preceding false with & processed in the logical judgment are still to be processed, and the subsequent contents are no longer processed with the && processing preceding false.

98. Overloading and rewriting
    1. Overload is overloaded, overriding overrides and overloads for overriding methods are different manifestations of Java polymorphism. Overrides are a representation of polymorphism between a parent class and a subclass, and overloading is a representation of polymorphism in a class.

    2. If you define a method in a subclass that has the same name and parameters as its parent, we say that the method is overridden (override). When an object of a subclass uses this method, the definition in the subclass is called, and for it the definition in the parent class is "masked".

    3. If more than one method with the same name is defined in a class, they either have a different number of arguments or have different parameter types, which is called a method overload (overload).
      The overloaded method is a type that can change the return value.

99. If the object's reference is set to NULL, will the garbage collector immediately release the memory occupied by the object?

No, in the next garbage collection cycle, this object will be recoverable.

100. What is the difference between a serial (serial) collector and a throughput (throughput) collector?

The throughput collector uses a parallel version of the new generation garbage collector, which is used for medium-sized and large-scale data applications. The serial collector is sufficient for most small applications, which require about 100M of memory on modern processors.


I have a public number that often shares some of the dry stuff related to Java technology, and if you like my share, you can use the search for "Java leader" or "Javatuanzhang" for attention.

100 Java Surface Questions collection and collation and reference answers

Related Article

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.