Java Programmer Interview Pen question two __java

Source: Internet
Author: User
Tags exception handling garbage collection inheritance thread class
40. Can the constructor constructor be override? Constructor constructor cannot be inherited, so overriding cannot be overridden, but can be overloaded overloading.

41. Can I inherit the String class? The string class is a final class and therefore cannot be inherited.

42, whether Swtich can function on a byte, whether it can function on a long, whether it can act on a string? Switch (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 not act on Swtich.

43, try {} There is a return statement, then immediately after this try in the finally {} code will be executed, when executed, before return or after?

44, programming Questions: The most efficient way to calculate the 2 times 8 is equal to a few? 2 << 3

45, two object values are the same (x.equals (y) = = true), but can have different hash code, this sentence is correct? No, there is the same hash code.

46, when an object is passed as a parameter to a method, this method can change the object's properties, and can return the result of the change, then here is the value of the pass or reference pass? 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.

47. When a thread enters an synchronized method of an object, can other threads enter other methods of this object?
No, one synchronized method of an object can only be accessed by one thread.

48, Programming Questions: Write a singleton out.
The main purpose of Singleton mode is to ensure that only one instance of a class classes exists in a Java application. The general singleton pattern usually has several forms: the first form: the definition of a class, its constructor is private, and it has a static private class variable that is instantiated when the class is initialized. Gets a reference to it through a public getinstance method, and then calls the method in it. public class Singleton {private Singleton () {} private static Singleton instance = new Singleton (), public static Singleton   GetInstance () {return instance; The second form: public class Singleton {private static Singleton instance = NULL; public static synchronized Singleton Ance () {if (instance==null) instance=new Singleton ();
return instance; Other forms: Defines a class whose constructors are private and all methods are static. The first form is generally considered to be more secure.

49, Java interface and C + + virtual class of the same and different places.
Because Java does not support multiple inheritance, and it is possible for a class or object to use a method or property that is separate within several classes or objects, the existing single inheritance mechanism cannot satisfy the requirement. Interfaces have a higher flexibility than inheritance because there is no implementation code in the interface. When a class implements an interface, the class implements all the methods and attributes in the interface, and the properties within the interface are public static under the default state, all by default. A class can implement multiple interfaces.

50. The simple principle and application of exception handling mechanism in Java.
When a Java program violates the semantic rules of Java, the Java Virtual machine represents the error that occurred as an exception. The violation of the semantic rules consists of 2 cases. One is the semantic check built into the Java class library. For example, an array subscript is thrown out of bounds, and a nullpointerexception is raised when an object that accesses null indexoutofboundsexception. Another scenario is that Java allows programmers to extend this semantic check, and programmers can create their own exceptions and freely choose when to throw an exception with the Throw keyword. All exceptions are java.lang.Thowable subclasses.

51, the advantages and principles of garbage collection. and consider 2 kinds of recycling mechanisms.
A notable feature of the Java language is the introduction of a garbage collection mechanism that solves the problem of the most troublesome memory management problems of C + + programmers, making it unnecessary for Java programmers to consider memory management when writing programs. Because there is a garbage collection mechanism, objects in Java no longer have the concept of scope, only references to objects have scope. Garbage collection can effectively prevent memory leaks and effectively use memory that can be used. The garbage collector is usually run as a separate low-level thread, unpredictable in the case of dead or long time unused objects in the heap to clear and recycle, the programmer can not call the garbage collector in real time to garbage collection of an object or all objects. The recycle mechanism has generational replication garbage collection and tag garbage collection, incremental garbage collection

52, please say you know the method of thread synchronization.
Wait (): causes a thread to be in a waiting state and releases lock on the object held. Sleep (): causes a running thread to be asleep, a static method that calls this method to catch interruptedexception exceptions. Notify (): Wakes up a waiting-state thread, noting that when this method is invoked, it is not possible to awaken a thread of the waiting state exactly, but rather by the JVM determining which thread to wake, and not by priority. Allnotity (): Wakes all threads that are in the waiting state, noting that it is not a lock for all awakened threads to an object, but rather a competition for them.

53. What are the collection classes you know? Main methods. The most commonly used collection classes are List and Map. The specific implementations of list include ArrayList and vectors, which are variable sized lists that are more suitable for building, storing, and manipulating the list of elements of any type of object. The List applies to situations where an element is accessed by a numeric index. MAP provides a more general method of element storage. The Map collection class is used to store element pairs (called "Keys" and "values"), where each key maps to a value.

54. Describe the principle mechanism of the JVM loading class file? The loading of classes in the JVM is implemented by ClassLoader and its subclasses, and the Java ClassLoader is an important Java Run-time system component. It is responsible for finding and loading classes of class files at run time.

55, char variable can be stored in a Chinese character?
Can be defined as a Chinese, because the Java encoding in Unicode, a char accounted for 16 bytes, so put a Chinese is no problem

56, multithreading there are several ways to achieve, what is it? There are several ways to achieve synchronization.
There are two ways to implement multithreading, which are inheriting the thread class and realizing the runnable interface, there are two kinds of synchronization implementation, namely Synchronized,wait and notify

57, JSP built-in objects and methods.
Request represents a HttpServletRequest object. It contains information about browser requests and provides several useful methods for obtaining cookies, headers, and session data, response represents the HttpServletResponse object, and provides several settings for sending back The way the browser responds (cookies, headers, etc.)
An Out object is an instance of Javax.jsp.JspWriter and provides several methods that you can use to echo the output to the browser. PageContext represents a Javax.servlet.jsp.PageContext object. It is an API for easy access to a wide range of namespaces, servlet-related objects, and a way of wrapping common servlet-related functionality. The session represents a requested Javax.servlet.http.HttpSession object. Session can store the user's state information Applicaton represents a Javax.servle.ServletContext object. This helps to find information about the servlet engine and servlet environment, which represents a Javax.servlet.ServletConfig object. This object is used to access the initialization parameters of the servlet instance. Page represents a servlet instance that is generated from this page

58, the basic concept of the thread, the basic state of the thread and the relationship between the state thread refers to the execution of the program, can execute the program code of an execution unit, each program has at least one thread, that is, the program itself. The threads in Java have four states: Run, ready, suspend, end.

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.