Java Programmer Interview Book (Basic Grammar section)

Source: Internet
Author: User

This is my note on the third edition of Oulich, the Java Programmer's Interview cookbook. This is the basic grammar section.


ClassLoader primarily serves the request of a class, when a class is required by the JVM, it requires the class according to the name, and then returns the class object of ClassLoader by ClassLoader.


In Java, characters exist in only one form, which is Unicode. Everything inside the JVM is represented by Unicode, and the output to the outside (the junction of the JVM and OS is the various input/output streams) is converted to other forms of encoding.


Java uses the mechanism of intermediate cache variables, so j=j++ can be replaced by the following notation:

Temp=j;

j=j+1;

J=temp;


Float Z = 1.0 compilation cannot be passed. Because 1.0 is a double type, it takes 1.0f to pass.

You can use wrapper classes for basic types of casts. For example:

float f1=100.00f;

Float f2=new Float (F1);

Double D1=f2.doublevalue ();

S+1 is an int and cannot be directly assigned to short.


The main method must be public, but you can throw exceptions and declare parameters.


When using the three-mesh operator, Java performs an automatic type conversion for the precision type.


&, | and &&, | | The important difference is that the former is a non-short-circuit operation and the latter is a short circuit.

<<: Left shift operator, num << 1, equals num multiplied by 2

>>: Right shift operator, NUM >> 1, equivalent num divided by 2

>>>: Unsigned Right shift, ignore sign bit, empty 0

>> 32 equals >>0


If there are multiple catch blocks, only one of the exception classes is matched and the catch block code is executed.

The finally structure is executed before return.

Java I/O (slightly)

Determines whether a number is a 2 order square: minus 1 to execute the "and" action

The For loop may not include {}, but is limited to executing statements.


Finding prime numbers by using the filter method (slightly)


A program can recommend garbage collection execution, but it is not guaranteed to be enforced.


Typical memory leak causes: Global collections, caches, ClassLoader reside in memory


The Clone method is defined in object, but the clone method can be called only if the Clonable interface is implemented, or an exception is thrown.


Wait () is the method defined in the object class, and sleep is not.


What is the difference between a Java inner class and a C + + nested class?

C + +: Although a nested class is defined inside a encapsulated class, it is a separate class that is essentially unrelated to the encapsulated class. Its members are not part of the encapsulation class, and similarly, the members of the encapsulated class do not belong to that nested class. The appearance of a nested class simply tells the wrapper class that there is one such type member for its use.

Java: A static nested class is similar to a C + + nested class, where you can access the static members of the encapsulated class directly, but if you want to access a non-static member, you will use an object that encapsulates the class as a carrier. Non-static nested classes allow us to directly access all members of the encapsulated class, whether static or non-static.



650) this.width=650; "src=" http://img1.imgtn.bdimg.com/it/u=635038340,2506132235&fm=21&gp=0.jpg "alt=" u= 635038340,2506132235&fm=21&gp=0.jpg "/>


Map.entryset () returns EntrySet, the order is random.


What's the difference between HashMap and Hashtable?

Hastmap is an interface that is a sub-interface of the map interface, an object that maps keys to values, where the keys and values are objects and cannot contain duplicate keys, but can contain duplicate values. HashMap allows null key and null value, while Hashtable is not allowed.

HashMap is a lightweight implementation of Hashtable (non-thread-safe implementation).


Constructors are not overridden in Java, and constructors for subclasses are automatically called first by the constructor of the parent class.


There is a default copy constructor, but only bit replication is provided.


Overloads and overrides are different:

Overloading (Overload): For Methods of a class (including methods inherited from a parent class), , The parameter list is different

Override: Also called rewriting, which overrides a method of a parent class in a subclass when some methods in the parent class do not meet the requirements. When a method in a parent class is overwritten, the method in the parent class cannot be called unless the Super keyword is used.

Static methods cannot be overwritten.


When you create a new subclass object, the XXX method is called in the constructor method of the parent class, and the XXX method is overridden in the subclass, and the XXX method of the subclass is called directly in the parent class.


Anonymous inner classes cannot inherit other classes, but they can implement interfaces.

Abstract classes cannot be final.












Java Programmer Interview Book (Basic Grammar section)

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.