Java Foundation Questions (III.)

Source: Internet
Author: User

21, Static Nested class and Inner class are different.

The static Nested class is an inner class declared static (static), which can be instantiated without relying on an external class instance. The usual inner classes need to be instantiated after the external class is instanced.

22. What is the difference between dynamic include and static include in JSP?

Dynamic include uses Jsp:include action to implement <jsp:include page= "included.jsp" flush= "true"/> It always checks for changes in the included files, is suitable for containing dynamic pages, and can take parameters.

Static include is implemented with the include pseudo-code and will not check for changes in the included files, and is suitable for containing static pages <%@ include file= "included.htm"%>

23, when to use the Assert.

Assertion (assertion) is a common debugging method in software development, which is supported in many development languages. In the implementation, assertion is a statement in the program, which checks a Boolean expression, a correct program must ensure that the value of the Boolean expression is true, if the value is False, the program is already in an incorrect state, The system will give a warning or exit. In general, assertion is used to ensure the most basic and critical correctness of the program. Assertion inspection is usually turned on during development and testing. To improve performance, the assertion check is usually turned off after the software is released.

24. What is GC? Why do you have a GC?

GC is the meaning of garbage collection (Gabage Collection), memory processing is where programmers are prone to problems, forgetting or wrong memory recycling can cause program or system instability or even crashes, The GC functionality provided by Java can automatically monitor whether an object exceeds the scope to achieve the purpose of automatically reclaiming memory, and the Java language does not provide a way to release the displayed operation of the allocated memory.

25, short S1 = 1; S1 = s1 + 1; what's wrong? Short S1 = 1; S1 + = 1; what's wrong?

Short S1 = 1; S1 = s1 + 1; (S1+1 operation result is int type, need cast type)

Short S1 = 1; S1 + = 1; (can be compiled correctly)

26, Math.Round (11.5) how much? Math.Round (-11.5) how much?

Math.Round (11.5) ==12

Math.Round (-11.5) ==-11

The round method returns the longest integer closest to the parameter, and the parameter adds 1/2 to its floor.

27, String s = new string ("XYZ"), and several string Object created?

Two

28, Design 4 threads, of which two threads add 1 to J each time, and two threads to J for each reduction of 1 per second. Write the program.

The following program implements threads using an internal class, and does not consider order issues when adding or subtracting J.

public class threadtest1{

private int J;

public static void Main (String args[]) {

ThreadTest1 tt=new ThreadTest1 ();

Inc Inc=tt.new Inc ();

Dec dec=tt.new Dec ();

for (int i=0;i<2;i++) {

Thread T=new Thread (inc);

T.start ();

T=new Thread (DEC);

T.start ();

}

}

Private synchronized Void Inc () {

j + +;

System.out.println (Thread.CurrentThread (). GetName () + "-inc:" +j);

}

private synchronized void Dec () {

j--;

System.out.println (Thread.CurrentThread (). GetName () + "-dec:" +j);

}

Class INC implements runnable{

public void Run () {

for (int i=0;i<100;i++) {

Inc ();

}

}

}

Class Dec implements runnable{

public void Run () {

for (int i=0;i<100;i++) {

Dec ();

}

}

}

}

29. Does Java have goto?

Reserved words in Java are not currently used in Java.

30. 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.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java Foundation Questions (III.)

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.