Java often test concept problems

Source: Internet
Author: User
Tags bitwise finally block inheritance logical operators stringbuffer
Java Basics:

1, Scope public,private,protected, and do not write when the difference
Answer:
The difference is as follows:
Scope Current class same package descendant class other package
Public√√√√
Protected√√√x
Friendly√√xx
Private√xxx
Default to friendly when not written
2, & and && differences
Answer:
& is the bitwise operator, which means that bitwise AND operation,&& are logical operators that represent logic and
8, Math.Round (11.5) and so how much? Math.Round (-11.5) equal to how much
Answer:
Math.Round (11.5) ==12; The Math.Round ( -11.5) ==-11;round method returns the long integer closest to the parameter, and the parameter plus 1/2 is then floor
9, short S1 = 1; S1 = s1 + 1; what's wrong? Short S1 = 1; S1 = 1; what's wrong?
Answer:
Short S1 = 1; S1 = s1 + 1; (The s1+1 operation result is int type, needs to cast type) short S1 = 1; S1 + + 1; (can compile correctly)
10, Java have goto
Answer:
Reserved words in Java that are not currently used in Java
11, does the array have length () This method? String there is no length () This method
Answer:
The array has no length () method, and has a property of length. String has the length () method
12, the difference between overload and override. Whether the overloaded method can change the type of the return value
Answer:
The overridden overriding and overloaded overloading of methods are different manifestations of Java polymorphism. Overriding overriding is a manifestation of polymorphism between parent classes and subclasses, and overload 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 (overriding). 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 (overloading). The overloaded method is to change the type of the return value
13, set elements can not be repeated, then what is the method to distinguish between repetition or not? Is it with = = or equals ()? What's the difference between them?
Answer:
The elements in set cannot be duplicated, so the iterator () method is used to distinguish between duplicates. Equals () is to interpret whether two sets are equal
The Equals () and = = methods Determine whether the reference value points to the same object equals () is overridden in the class in order to return true values when the contents and types of the two detached objects match.
14, give me one of your most common to runtime exception
Answer:
Common Run-time exceptions are the following arithmeticexception, Arraystoreexception, Bufferoverflowexception, Bufferunderflowexception, Cannotredoexception, Cannotundoexception, ClassCastException, Cmmexception, Concurrentmodificationexception, Domexception, Emptystackexception, IllegalArgumentException, Illegalmonitorstateexception, Illegalpathstateexception, IllegalStateException, Imagingopexception, Indexoutofboundsexception, MissingResourceException, Negativearraysizeexception, Nosuchelementexception, NullPointerException, Profiledataexception, ProviderException, Rasterformatexception, SecurityException, SystemException, Undeclaredthrowableexception, Unmodifiablesetexception, unsupportedoperationexception
15. What's the difference between error and exception?
Answer:
Error indicates that recovery is not an impossible but difficult situation with a serious problem. For example, memory overflow. It's impossible to expect a program to handle such a situation.
Exception represents a design or implementation problem. In other words, it means that if the program is working properly, it never happens.
16, List, Set, Map is inherited from the collection interface
Answer:
List,set is that map is not
17. What is the difference between abstract class and interface?
Answer:
A class that declares the existence of a method without implementing it is called an abstract class (abstract class), which is used to create a class that embodies certain basic behaviors and declares a method for that class, but it cannot implement the class in that class. Cannot create an instance of an abstract class. However, you can create a variable whose type is an abstract class and have it point to an instance of a specific subclass. Cannot have an abstract constructor or an abstract static method. Subclasses of an abstract class provide implementations for all abstract methods in their parent class, otherwise they are also abstract classes. Instead, implement the method in the subclass. Other classes that know their behavior can implement these methods in the class
Interface (interface) is a variant of an abstract class. In an interface, all methods are abstract. Multiple inheritance can be achieved by implementing such an interface. All the methods in the interface are abstract, and none have a program body. Interfaces can only define static final 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 to the program body) of all such interfaces. It can then invoke the method of the interface on any object of the class that implements the interface. 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 be in effect. A reference can be converted to an interface type or transformed from an interface type, and the instanceof operator can be used to determine whether a class of an object implements an interface
18. Abstract method can be static at the same time, whether it can be native at the same time is synchronized
Answer:
Are not

19, interface can inherit the interface? Does an abstract class implement (implements) interfaces? Whether an abstract class can inherit entity classes (concrete Class)
Answer:
Interfaces can inherit interfaces. Abstract classes can implement (implements) interfaces, and abstract classes can inherit entity classes, provided that an entity class must have a definite constructor
20. Whether the constructor constructor can be override
Answer:
Constructor constructor cannot be inherited, so overriding cannot be overridden, but can be overloaded overloading
21, whether you can inherit the string class
Answer:
The string class is a final class and therefore cannot be inherited
22, try {} There is a return statement, then immediately after this try in the finally {} code will not be executed, when executed, before return or after
Answer:
will be executed before return.
23, with the most efficient way to calculate 2 times 8 is equal to a few
Answer:
2 << 3
24, two object values are the same (x.equals (y) = = true), but can have different hash code, this sentence is not correct
Answer:
No, there's the same hash code.
25, when an object is passed as a parameter to a method, this method can change the properties of the object, and can return the result of the change, then whether this is a value pass or a reference pass
Answer:
is a value pass. The Java programming language has only values that pass parameters. When an object instance is passed to a method as a parameter, the value of the parameter is a reference to that object. The contents of an object can be changed in the method being invoked, but the reference to the object will never change
26. Whether the Swtich can function on a byte, whether it can function on a long, whether it can act on a string
Answer:
Witch (EXPR1), expr1 is an integer expression. Therefore, the arguments passed to the switch and case statements should be int, short, char, or byte. Long,string can't work on Swtich.
27, the difference between ArrayList and Vector, HashMap and Hashtable
Answer:
ArrayList and Vector are mainly from two aspects.
I. Synchronicity: vectors are thread-safe, that is, synchronous, while ArrayList is not secure, not synchronized.
Two. Data growth: When growth is needed, the vector defaults to the original one, while ArrayList is half the original.
On HashMap and Hashtable mainly from three aspects.
I. Historical reasons: Hashtable is based on the old dictionary class, HashMap is an implementation of the map interface introduced by Java 1.2
Two. Synchronicity: Hashtable is thread-safe, that is, synchronous, and HashMap is not secure, not synchronized.
Three. Value: Only HashMap can let you use NULL as the key or value of a table entry

28, char variable can be stored in a Chinese character?
Answer:
Is able to be defined as a Chinese, because Java is encoded in Unicode, one char occupies 16 bytes, so it is no problem to put a Chinese
29. What is GC? Why should I have a GC?
Answer:
GC is the meaning of garbage collection (Gabage Collection), memory processing is where programmers are prone to problems, forgetting or incorrect memory recycling can cause the program or system to be unstable or even crash, Java provides a GC feature that automatically monitors whether an object is out of scope to automatically reclaim memory, and the Java language does not provide a display operation to free allocated memory.
30, Float type float f=3.4 is correct?
Answer:
Not correct. Inaccurate precision, you should use coercion type conversion, as follows: float f= (float) 3.4
31. Introduce the collection FrameWork in Java (including how to write your own data structure)?
Answer:
The Collection framework is as follows:
Collection
├list
│├linkedlist
│├arraylist
│└vector
│└stack
└set
Map
├hashtable
├hashmap
└weakhashmap
Collection is the most basic set interface, and a collection represents a set of object, that is, the collection element (Elements)
Map provides a mapping of key to value
32, abstract class and interface.
Answer:
Abstract classes and interfaces are used for abstraction, but abstract classes (in Java) can have their own partial implementations, while interfaces are entirely an identity (with multiple inherited functionality).
The Java class implements the order to instantiate the method is realizes the Java.io.Serializable interface
Implementation comparison in collection framework to implement comparable interface and Comparator interface
33, the difference between string and StringBuffer.
Answer:
The length of a string is immutable, and the length of the StringBuffer is variable. If you often manipulate the contents of a string, especially if the content is to be modified, use StringBuffer, and if you end up with a string, use the StringBuffer ToString () method
34, talk about final, finally, finalize the difference
Answer:
final-modifier (keyword) If a class is declared final, it means that it cannot derive a new subclass and cannot be inherited as a parent class. Thus a class cannot be declared as abstract and declared final. Declaring a variable or method final can guarantee that they will not be changed in use. A variable declared as final must be given an initial value at the time of declaration, and can only be read and not modified in future references. A method that is declared final is also used only and cannot overload
Finally-provides a finally block to perform any cleanup operations when the exception is processed. If an exception is thrown, the matching catch clause executes, and then the control enters the finally block (if any)
finalize-method name. Java technology allows you to use the Finalize () method to do the necessary cleanup before the garbage collector clears the object out of memory. This method is invoked by the garbage collector on this object when it is determined that the object is not referenced. It is defined in the Object class, so all of the classes inherit it. Subclasses override the Finalize () method to defragment system resources or perform other cleanup work. The Finalize () method is invoked on this object before the garbage collector deletes the object.
35. What are the aspects of object-oriented features
Answer:
There are mainly the following four aspects:
1. Abstract:
Abstraction is to ignore those aspects of a topic that are not relevant to the current goal in order to pay more attention to aspects related to the current goal. Abstraction is not intended to understand all of the problems, but rather to select a subset of them for the time being without partial details. Abstraction consists of two aspects, one is process abstraction and the other is data abstraction.
2. Inheritance:
Inheritance is a hierarchical model of coupling classes, and allows and encourages class reuse, which provides a way to articulate common features. A new class of objects can derive from an existing class, a process called class inheritance. The new class inherits the attributes of the original class, which is called the derived class (subclass) of the original class, and the original class is called the base class (the parent Class) of the new class. A derived class can inherit methods and instance variables from its base class, and the class can modify or add new methods to make it more appropriate for special needs.
3. Package:
Encapsulation is the process and data surround, access to data only through the defined interface. Object-oriented computing begins with the basic concept that the real world can be depicted as a series of fully autonomous, encapsulated objects that access other objects through a protected interface.
4. Polymorphism:
Polymorphism refers to allowing objects of different classes to respond to the same message. Polymorphism consists of parametric polymorphism and inclusion polymorphism. Polymorphism language has the advantages of flexibility, abstraction, behavior sharing and code sharing, which solves the problem of application function with the same name.

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.