Java must brush 100 questions __java

Source: Internet
Author: User
Tags access properties finally block garbage collection sql injection square root file transfer protocol multiple inheritance in java stringbuffer
1. What is b/s structure. What is c/s architecture

b/S (browser/server), browser/server program
c/S (client/server), client/server, desktop application 2. What 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 3.Java has those development platforms.

JAVA SE: Primarily used in client-side development
JAVA EE: Primarily used in Web application development
JAVA ME: Primarily used in embedded application development 4. What is a JVM. What the Java virtual machine includes.

Jvm:java virtual machines, using hardware or software means to achieve virtual computers, Java Virtual machines include: registers, stacks, processor 5.Java whether developers need to recycle memory garbage.

Most of the cases are not needed. Java provides a system-level thread to track memory allocations, and memory areas that are no longer in use are automatically recycled 6. What is a JDK? What is a JRE?

Jdk:java Development Kit:java Development Kit is the environment that developers need to install
Jre:java Runtime Environment:java running environment, Java program to run the environment required to install 7. What is a data structure.

The computer saves, organizes the data the way 8.Java the data structure has those.

Linear table (ArrayList)
Linked list (LinkedList)
Stacks (Stack)
Queues (queue)
Map (map)
Tree (Trees) 9. What is OOP?

Object-oriented Programming 10. What is Object oriented.

Everything in the world can be seen as an object. Each object consists of dynamic behavior and static properties, which form an object. 11. What is the relationship between a class and an object?

Classes are objects that are abstract, objects are specific to classes, classes are templates of objects, objects are instances of the class, 12.Java have several data types

Shaping: Byte,short,int,long
Floating-point type: float,double
Character type: Char
Boolean: Boolean 13. What is an implicit conversion and what is an explicit conversion

Display conversions are type-strong, forcing a large type of data to be assigned to a small type of data; an implicit conversion is a large range of variables that can accept a small range of data; Implicit and explicit conversions are actually automatic type conversions and coercion type conversions. 14.Char type can be converted to int type. Can be converted to a string type, can be turned into double type

Char is also a special type in Java, with an int value starting at 1, a total of 2 16-time data; Char 15. What is a disassembly box.

Unpacking: Converting a wrapper type to a basic data type
Boxing: Converting basic data types to packaging type 16.Java are those.

Byte:byte
Short:short
Int:integer
Long:long
Float:float
Double:double
Char:character
Boolean:boolean 17. Contains those contents in a Java class.

property, method, inner class, construction method, code block. 18. For example: if (a+1.0=4.0), do it well.

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 in the judge condition does not use floating-point type) 19. How do you solve the problem of errors in floating-point data operations?

The difference between the operation of floating-point data using the BigDecimal class 20.++i and the i++

++i: First assign value, then calculate
i++: Calculate first, then assign the value 21. The structure of the program has those.

Sequential structure
Select structure
Loop structure 22. There are several ways to instantiate an array.

Static instantiation: The element in the array was specified when the array was created.
Int[] A=new int[]{1,3,3}
Dynamic instantiation: When an array is instantiated, only the extent of the array is specified, and all the elements in the array are the default values of the array type, which are all data defaults in the 23.Java

Byte,short,int,long default is all 0 Boolean the default value is False char type is "
The default value for float and double type is 0.0 object types, which are null 24.Java commonly used packages.

Java.lang
java.io
java.sql
Java.util
java.awt
java.net
Java.math 25.Java is the most top-level parent class.

the Object 26.Object class commonly used methods have those.

Equals
Hashcode
Tostring
Wait
Notify
Clone
There is no pointer in the GetClass 27.java.

There is a pointer, but hidden, the developer cannot manipulate the pointer directly, and the JVM is manipulating the value delivery reference pass in pointer 28.java.

In theory, Java is a reference pass, and for basic data types, passing is a copy of the value, not the value itself. For object types, passing is a reference to an object that, when manipulated by a method, actually operates on the object to which the reference refers. 29. Assuming that the variables of the instantiated array are treated as method parameters and the elements within the array are changed when the method is executed, does the array element change outside the method?

Changed, because passing is a reference to an object, which refers to the object 30 of the reference . Can you change the length of the array after instantiating the array?

No, once an array is instantiated, its length is fixed at 31. Suppose there are 5 elements in the array, and what to do if the arrays are reversed.

Creates a new array, loops through each element from the back to the front, and puts the retrieved elements into the new array in order 32. Form participates in the argument

Formal parameters: All called "formal arguments" are parameters used when defining method names and method bodies to receive the actual values passed in when the method is invoked; arguments: all called "actual parameters", the actual values that are passed to the method when the method is invoked. 33. The construction method can not be called explicitly.

A method cannot be constructed as a normal method call, and it will only be invoked by the system when the object is created 34. Can the construction method be overridden. Can overload.

You can override it, or you can overload 35. What is a method overload.

The overload of a method allows more than one method of the same name to exist in the same class, as long as the number or type of arguments is different. In this case, the method is called overloaded, and this process is called the overload of the method (override)
36. The difference between internal classes and static internal classes.
The static inner class is independent of the outer class, and cannot directly access the variables and methods in the outer class in the static inner class. If you want to access it, you must new object of an external class, and use the new object to access it. But it can directly access static variables and invoke static methods.
The ordinary inner class exists as a member of the outer class, and the external class property can be directly accessed in the ordinary inner class, calling the method of the outer class.
If the outer class wants to access the properties of the inner class or call methods of the inner class, you must create an object of an inner class that accesses the property or invokes the method.
If other classes want to access the properties of a normal inner class or call a method of a normal inner class, you must create an object of the ordinary inner class as a property in the outer class, in which the same class can invoke methods of ordinary inner classes or access properties of ordinary inner classes
If other classes want to access the properties of a static inner class or call a method of a static inner class, create a static inner class object directly. 37.Static keywords have any effect.

Static can modify internal classes, methods, variables, code blocks
Static-decorated classes are statically inner classes
The static-decorated method, which means that the method belongs to the current class, not to an object, and cannot be overridden by a static method, 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 static variable or a class variable, which is shared by all instances and does not depend on the object. Static variables have only one copy in memory, and when the JVM loads the class, only one memory is allocated statically.
The static-decorated code block is called a code block, which is usually used for program optimization. Code in a static code block is executed only once when the entire class is loaded. A static code block can have multiple, if there are multiple, executed sequentially. The role of 38.Final in Java

Final can modify classes, modify methods, and modify variables.
The decorated class is called the final class. The class cannot be inherited.
The decorated method cannot be overridden.
The modified variable is called a constant, and the constant must be initialized, and once initialized, the value of the constant cannot be changed. which class is used in the operation string in 39.Java.

What is the difference between String,stringbuffer,stringbuilder 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.
You are more efficient than string when you make a string concatenation modification to remove a replacement.
StringBuffer is thread-safe and StringBuilder is not thread-safe. So StringBuilder is more efficient than StringBuffer, and StringBuffer methods mostly add the Synchronized keyword 41.String str= "AAA", with String str=new String ("AAA").

Not the same. Because memory allocation is not the same way.
First, the "AAA" created is a constant, and the JVM assigns it to a constant pool.
The second creates an object in which the JVM assigns its value to heap memory. 42.String str= "AA", String s= "BB", string Aa=aa+s; A few objects were created.

A total of two references, three objects. Because "AA" and "BB" are constants, the value of a constant cannot be changed, and when the string concatenation is performed, a new constant is created "aabbb", which is stored in a constant pool. 43. There are common methods for following the math class in Java.

Pow (): Power operation
Sqrt (): square root
Round (): Rounding
Abs (): To find absolute value
Random (): Generates a random number of 0-1, including 0 common methods that do not include 1 44.String classes.

CharAt: Returns the character at the specified index
IndexOf (): Returns the index of the specified character
Replace (): string substitution
Trim (): Remove whitespace from both ends of the string
Split (): Splits a string, returns an array of separated strings
GetBytes (): Returns an array of byte types for a string
Length (): Returns string lengths
toLowerCase (): Converts a string to a lowercase letter
toUpperCase (): Converts a string to uppercase characters
SUBSTRING (): intercepting string
Format (): Formatting strings
Equals (): string comparison 45. Determine if two objects are the same, can you use Equlas comparison?

No. Equlas are mostly used to do string comparisons, to determine the basic data type or object type, you need to use = = 46.== and equlas what is the difference.

= = You can determine whether the basic data type values are equal, or whether two objects point to the same memory address, that is, to determine whether two objects are the same object, Equlas is usually used for string comparisons. 47. How to reverse the string.

StringBuilder or StringBuffer reverse method 48. Object-oriented languages have those characteristics.

Whether inheritance in encapsulation, inheritance, polymorphic 49.Java is a single inheritance or multiple inheritance

There are both single inheritance and multiple inheritance in Java. There can be only one parent class for a Java class, and for an interface you can inherit multiple interfaces 50 at the same time. what is an override. What is overload.

Overloads and overrides are all expressions of Java polymorphism.
Overloading is called override, the expression of polymorphism in the same class. When multiple methods with 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
Rewrite called overwrite, is the representation of polymorphism in character classes. This is the method override when the subclass appears the same way as the parent class. Method overrides, the return value of a subclass must be the same as the parent class. If the parent class method throws an exception, the subclass overrides a method that throws an exception type that cannot be less than the exception type thrown by the parent class. 51. Whether the construction method can be overloaded. Can rewrite.

Can be overloaded, you must override 52. If the parent class has only a parameter construct method, then the subclass must override the constructor method of the parent class.

You must rewrite 53. When you create a subclass object, the constructor for the parent class executes.

Will execute. When you create a subclass object and call the subclass constructor method, the subclass constructor invokes the constructor method of the parent class by default. 54. What is the parent class reference to the child class object.

Java polymorphism is a special form of expression. Creates a parent class reference that points to object 55 of a subclass . When the parent class references a subclass object, the subclass overrides the parent class method and property, and whose property is accessed when the property is accessed. Whose method is invoked when the method is invoked.

Subclasses override the parent class methods and properties, accessing the properties of the parent class, and calling the method 56.Super of the subclass and what this represents.

Super represents the parent class object of the current class
This represents the object of the current class 57. What is the keyword of the abstract?

Abstract 58. Do you have to have an abstract method?

Not necessarily. Abstract classes can have no abstract method. 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. Abstract classes can use final adornments.

No. The definition of an abstract class is for others to inherit, and the final modifier class means that the class cannot be inherited, and the idea of an abstract class violates 61. What is the difference between a common class and an abstract class?

Ordinary classes cannot contain abstract methods, and abstract classes can contain abstract methods
Abstract classes cannot be instantiated directly, and ordinary classes can instantiate 62 directly. What is an interface.

An interface is a declaration of some function provided by something, a special Java class 63.JAVA Why an interface is required.

Interface makes up for the drawbacks of Java single inheritance 64. What is the feature of the interface.

Constants declared in an interface that are all public static final adornments
All methods in an interface are abstract methods
Interface is not constructed.
Interface is not directly instantiated
Interfaces can inherit more than 65. What is the difference between an interface and an abstract class?

Abstract class has construction method, interface has no construction method
Abstract classes can only be inherited only, and interfaces may inherit more than one
Abstract classes can have normal methods, and all the methods in an interface are abstract methods
The properties of the interface are both public and final decorated, and the abstract is not what the exception in 66.Java is divided into.

Compile-time exceptions
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 anomaly 68. There are several mechanisms for handling exceptions.

Exception capture: try...catch...finally, exception thrown: throws. 69. How to customize an exception

Inherits an exception class, usually rumtimeexception or exception 70. If an exception occurs when an exception is caught, then the return statement outside the try.catch.finally block is executed.

Will execute, if there is finally, executed after finally, if not finally, executed after the catch 71.try.catch.finally must exist.

The try block must exist, catch and finally can not exist, but not at the same time there is no difference between 72.Thow and Thorws

Throw written in a block of code, throw followed by a specific exception instance
Throw written in front of the method, throws followed by the exception class, the exception class can be multiple 73.Error and exception differences.

Both error and exception are part of the Java error-handling mechanism and inherit the Throwable class.
Exception represents an exception that can be caught by a program or optimized to avoid.
Error indicates a system error and cannot be handled incorrectly by the program. 74. Does the use of log4j affect the program?

Yes, log4j is used for logging, recording key-sensitive information, usually logging to a local file or database. Logged in a local file, there will be frequent IO operations that can consume some system resources. Records in the database, the database table will be frequently manipulated, also has a certain impact on system performance. But for program security and data recovery or bug tracking, this resource consumption can be sustained. There are several levels of the 75.log4j log.

From low to High: Debug, info, Wran, error 76. In addition to using new to create objects, you can also use the method to create objects.

Java Reflection 77.Java reflection creates objects efficiently or creates objects through new.

Creating objects through new is more efficient. Through reflection, first find the lookup class resources, the use of the class loader to create, the process is more cumbersome, so the efficiency of the lower 78.Java set a few of the framework.

Coillection, Map. There are those set frames under the 79.Collection interface.

List: Linear table, set: Unordered collection. What is the characteristic of 80.List interface.

Sequential storage, can have duplicate values. What is the characteristic of 81.Set interface

No storage, no duplicate values. What is the difference between 82.ArrayList and LinkedList?

ArrayList and LinkedList both implement the list interface.
ArrayList is a linear table, the bottom is implemented using arrays, it is more efficient at the end of inserting and accessing data,
Linked is a two-way linked list, he is more efficient when inserting in the middle or inserting the head, while accessing the data is less efficient 83.Array and ArrayList.

Array and ArrayList are collections that are used to store data. The ArrayList base is implemented using arrays, but the ArrayList arrays are encapsulated and functionally extensible, with a number of features that are not available in the native array. We can understand that ArrayList is an upgraded version of array. What are the characteristics of 84.MAP?

Storing data in key value pairs
It is not necessary to store elements sequentially
Steps to not allow duplicate key 85.JDBC operations

Loading a database-driven class
Open a database connection
Execute SQL statement
Processing return results
Close Resource 86. How to prevent the problem of SQL injection when using JDBC.

Use the PreparedStatement class instead of the statement class 87. How to invoke a stored procedure within JDBC

Use CallableStatement 88. What are the benefits of using connection pooling if you understand connection pooling?

Database connections are very resource-consuming 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, rather than creating a new database connection each time. By releasing a database connection that is idle for a long time, you can avoid the problem of missing connections due to the creation of too many connections, which improves program performance. 89. The data source technology that you know has those. What is the benefit of using a data source.

Dbcp,c3p0 and so on, with the most or C3P0, because the c3p0 than Dbcp more stable, secure; Maintain database information in the form of a configuration file, rather than through hard coding. When the connected database information changes, no need to change the program code to implement the database information update. the 90.Java IO stream is divided into two types.

To divide by function
Input streams (inputs), output streams (outputs)
To be divided by type
BYTE Stream 91. Common IO classes have those.

File
Fileinputsteam,fileoutputstream
Bufferinputstream,bufferedoutputsream
Printwrite
Filereader,filewriter
Bufferreader,bufferedwriter
Objectinputstream,objectoutputsream 92. The difference between the byte stream and the character streams

Input output data in bytes, byte stream is transmitted in 8 bits
Input output data in characters, character streams are transmitted in 16-bit 93.final, Finalize (), finally

Different in nature
Final is the key word;
Finalize () as a method;
Finally, the block flag is used in the try statement;
Role
Final is the keyword used to identify constants, and the final identified keywords are stored in a constant pool (where the final constants are described below);
The Finalize () method is defined in object to be invoked by the JVM when the object "disappears" for garbage collection of the object, similar to a destructor in C + +, used to free the resources occupied by the object (for example, for i/0 operations) when the user is customized;
finally{} is used to identify a block of code that is compatible with try{}, regardless of whether the code in a try is finished or not executed (this refers to an exception), the program in the code block is bound to occur; 94. What is the difference between an abstract class and an interface?

Abstract class:
Abstract methods, only the concept of behavior, there is no specific behavior to achieve. The abstract keyword is decorated with no method body. Subclasses must override these abstract methods.
The class that contains the abstract method must be an abstract class.
An abstract class can only be inherited, and a class can inherit only one abstract class.
Interface:
All methods are abstract, and genera are constant.
Cannot be instantiated, you can define variables.
Interface variables can refer to instances of specific implementation classes
Interfaces can only be implemented, a specific class implements the interface, and all abstract methods must be implemented
Interfaces can be implemented more than
A specific class can implement multiple interfaces to achieve multiple inheritance 95. Method of Thread synchronization

Wait (): Keep thread waiting. Store threads in a thread pool.
Notify (): Wakes the thread that is waiting. Usually wakes up the first one in the thread pool. Leave the awakened thread in a temporary blocking state.
Notifyall (): Wakes up all waiting threads. Wakes all threads in the thread pool. 96. The difference between threads and processes

Process is a system of resource allocation and scheduling of a separate unit, the thread is CPU scheduling and allocation of the basic unit
Process and thread relationships:
A thread can belong to only one process, and a process may have multiple threads, but at least one thread.
A resource is assigned to a process, and all the threads of the same process share all the resources of that process.
Threads need to collaborate in synchronization during execution. Synchronization can be achieved by using message communication between threads of different processes.
A thread is a unit of execution within a process and a scheduled entity within a process.
The difference between a thread and a process:
Dispatch: A thread as the basic unit of dispatch and allocation, as the basic unit of a resource.
Concurrency: Not only can concurrent execution between processes, but also can be executed concurrently between multiple threads of the same process.
Owning a resource: a process is a stand-alone unit that owns resources, and threads do not own system resources, but they can access resources that are subordinate to the process.
Overhead: When creating or undoing 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 when 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, one thread dead is equal to the entire process dead, so the process of multiple processes than multithreaded program is robust, but in the process of switching, the resource consumption is greater, efficiency is worse. the difference between 97.& and &&

& is a bitwise operator. && is a Boolean logical operator, which is still to be processed in the case of a logical judgment, preceded by a false in &, with the preceding of && processing as false. 98. Overloading and rewriting

Overload is overloaded, override overrides and overloads for overriding methods are different manifestations of Java polymorphism. Overriding is a manifestation of polymorphism between a parent class and a subclass, and overloading is an expression of polymorphism in a class.
If you define a method in a subclass with the same name and parameters as its parent class, we say that the method is overridden (Override). When an object of a subclass uses this method, the definition in the subclass is invoked, and the definition in the parent class is "masked".
If multiple methods with the same name are defined in a class, either with a different number of parameters or with different parameter types, they are called overloads of the Method (overload).
The overloaded method is the type that can change the return value. 99. If the object's reference is set to NULL, the garbage collector immediately frees the memory occupied by the object.

No, in the next garbage collection cycle, this object will be recyclable. 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-scale and large-scale data applications. The serial collector is sufficient for most small applications (about 100M of memory on a modern processor).

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.