As a junior students, will soon go to internship, but always feel that they even a beginner novice is inferior, hey. Found himself even the threshold of the programmer has not entered, a little sad, but sad useless, hard forward is what we should do now.
Here are some of the Java-based questions I have previously extracted from the Internet at school. Just as usual review, deepen their knowledge level, no other use.
Say Arraylist,vector, LinkedList's storage performance and features
Both ArrayList and vectors use arrays to store data, which is larger than the actual stored data in order to add and insert elements, both of which allow the element to be indexed directly by ordinal, but the insertion element involves memory operations such as array element movement, so the index data is fast and the data is inserted slowly. Vector because of the use of the Synchronized method (thread-safe), usually performance is worse than ArrayList, and LinkedList using a doubly linked list for storage, index data by ordinal need to be forward or backward traversal, but when inserting data only need to record the item before and after items can be , so the insertion speed is faster.
Does Java have a goto?
Reserved words in Java are not currently used in Java.
Start a thread with run () or start ()?
Starting a thread is calling the start () method so that the virtual processor represented by the thread is in a running state, which means it can be dispatched and executed by the JVM. This does not mean that the thread will run immediately. The run () method can produce a flag that must be exited to stop a thread.
When a thread enters one of the object's synchronized methods, does the other thread have access to other methods of this object?
No, an synchronized method of an object can only be accessed by one thread.
Please say the thread synchronization method you know.
Wait (): causes a thread to be in a wait state and releases the lock of the object it holds.
Sleep (): Makes a running thread sleep, is a static method that calls this method to catch the interruptedexception exception.
Notify (): Wakes up a waiting thread, noting that when this method is called, it does not actually wake up a waiting state thread, but is determined by the JVM to wake up which thread, and not by priority.
Allnotity (): Wakes all the threads that are in the waiting state, noting that they do not give all the wake-up threads an object lock, but instead let them compete.
What are the collection classes you know? The Main method?
The most common collection classes are List and Map. The specific implementation of the list includes ArrayList and vectors, which are variable-sized lists that are more appropriate for building, storing, and manipulating any type of object. List is useful for cases where elements are accessed by numeric indexes.
MAP provides a more general method of storing elements. The Map collection class is used to store element pairs (called "Keys" and "values"), where each key is mapped to a value.
Describe the mechanism by which the JVM loads the class file?
The loading of classes in the JVM is implemented by ClassLoader and its subclasses, and Java ClassLoader is an important Java Runtime system component. It is responsible for locating and loading classes of class files at run time.
Can I store a Chinese character in a char variable?
Can be defined as a Chinese, because in Java encoding in Unicode, a char accounted for 16 bytes, so put a Chinese is no problem
There are several ways to implement multithreading, what is it? How are there several implementations of synchronization?
There are two ways to implement multithreading, namely, inheriting the thread class and implementing the Runnable interface.
There are two implementations of synchronization, namely Synchronized,wait and notify
The basic concepts of threads, the basic state of threads, and the relationship between states
A thread is an execution unit that executes a program's code during the execution of a program, and each program has at least one thread, the program itself.
There are four types of threads in Java: Run, ready, suspend, end.
The life cycle of the servlet
The Web container loads the servlet, beginning with the life cycle. The servlet is initialized by calling the servlet's init () method. By invoking the service () method implementation, different do*** () methods are called depending on the request. To end the service, the Web container invokes the servlet's Destroy () method.
The difference between abstract and interface
In the Java language, abstract classes and interface are the two mechanisms that support the definition of an abstraction class.
You cannot create an instance of an abstract class, but you can create a variable whose type is an abstract class that points to an instance of a specific subclass.
Cannot have abstract constructors or abstract static methods.
The subclasses of the abstract class provide implementations for all abstract methods in their parent class, or they are abstract classes.
An interface (interface) is a variant of an abstract class.
In an interface, all methods are abstract and public. Multiple inheritance can be obtained by implementing such an interface.
None of the methods in the interface have a program body. An interface can only define Staticfinal member variables.
The implementation of an interface is similar to a subclass, except that the implementation class cannot inherit the behavior from the interface definition.
When a class implements a special interface, it defines the method (which is given by the program body) to all such interfaces. It can then invoke the interface's method on any object that implements the interface's class.
Because of an abstract class, it allows you to use the interface name as the type of the reference variable. The usual dynamic binder will take effect.
A reference can be converted to an interface type or converted from an interface type, and the instanceof operator can be used to determine whether the class of an object implements an interface.
Interfaces can inherit interfaces. Abstract classes can implement (implements) interfaces, and abstract classes can inherit entity classes, but only if the entity classes must have explicit constructors. The interface is more concerned with "what functions can be achieved", regardless of "how it is achieved".
1. The same point
A. Both are abstract classes and cannot be instantiated.
B. Interface implementations of classes and subclasses of Abstrctclass must implement an abstract method that has already been declared.
2. Different points
A. Interface need to be implemented, to use implements, and AbstractClass need to inherit, to use extends.
B. A class can implement multiple interface, but a class may inherit only one abstract class.
C. Interface emphasizes the realization of a particular feature, while AbstractClass emphasizes its affiliation.
D. Although the subclasses of the interface implementation class and the Abstrctclass must implement the corresponding abstract methods, the implementations are in different forms. Each method in interface is an abstract method, all just declared (declaration, no method body), the implementation class must be implemented. AbstractClass subclasses can be implemented selectively.
This option has a two-point implication:
one is that not all methods in the Abastract class are abstract, only those whose crown has an abstract are abstracted, and subclasses must be implemented. For those that do not have an abstract method, the method body must be defined in the ABSTRCT class.
The second is that when the subclass of abstract class inherits it, it can either inherit directly from the non-abstract method or overwrite it, but the abstract method can be implemented by choice, or it can be implemented by declaring its method abstract, without implementing it and leaving it to its subclasses, but this class must also be declared as an abstract class. Abstract classes, and of course, cannot be instantiated.
E. Abstract class is an intermediary between interface and class.
interface are completely abstract, can only declare methods, and can only declare pulic methods, cannot declare private and protected methods, cannot define method bodies, and cannot declare instance variables. However, interface can declare constant variables, and this example is not hard to find in the JDK. But putting constant variable in interface violates its purpose of being an interface, and it confuses the different value of interface and class. If you really need it, you can put it in the appropriate AbstractClass or class.
abstract class plays a connecting role in interface and class. On the one hand, abstract class is abstract and can be used to declare abstractions to standardize the functions that subclasses must implement, on the other hand, it can define the default method body for the subclasses to use or overwrite directly. In addition, it can define its own instance variables for use by subclasses through inheritance.
Applications for 3.interface
A. Classes and classes require a specific interface to reconcile, rather than how they are implemented.
B. As an identity that is capable of implementing a specific function, it can also be a purely identifying interface method that does not exist.
C. The need to treat a set of classes as a single
Some previously reserved Java face questions