The accumulation of interview questions

Source: Internet
Author: User
Tags uuid

If it is a simple search problem, it is not necessary to list it. Slowly accumulate.

1. How to judge a number is a power of 2.

The individual believes that the number is converted into binary, sign bit is 0, the remaining part has and only the leftmost one is 1, the rest is 0, is the power of 2. The principle is to take two to the left into one.

2. Trap Interview question:

In Java, Throwable is an interface or an abstract class.

3. Javascript Topics

<! DOCTYPE html>
There are 1000 bottles of syrup, of which 999 are exactly the same, and 
only one bottle contains poison, but it cannot be distinguished in appearance. 
If the poison is given to a mouse, the mouse will suddenly die a week later, 
but not a single symptom. 
5. Java Data range

In Java, there is a number, such as 10 billion, that you can use int to store?
10 billion * 10 billion, what type can I use to store it?

In this way, the int type is 32 bits, 4 bytes, 2 of 10 times is 1024, about 1k,2^20 = 1M, about 1 million, 2^30= 1G, about 1 billion, so integers can only save about 4 billion digits, positive 22E, so 10 billion can be stored using long. You cannot use int to store it.
Long is 64 digits, because 32 bits are no more than 10 billion, so 64 bits can not be stored 10 billion * 10 billion, only special types, such as the K God BigInteger, or BigDecimal to store.

A test program:

public class Testintlong {
	/**
	 * Please refer to int storage 10 billion, long deposit 10 billion * 10 billion case
	/public static void Main (string[] A RGS) {
		int num1 = ten * 1000 * 1000 * 1000;
		Long num2 = 10L * 1000 * 1000 * * 1000 * 1000 (*), 1000 * 1000;
		Long num3 = * 1000 * 1000 * 1000 * 1000 * 1000L;
		Long num4 = 10L * 1000L * 1000L * 1000L * 10L * 1000L * 1000L * 1000L;
		System.out.println ("num1=" + num1);//num1=1410065408
		System.out.println ("num2=" + num2);//num2= 7766279631452241920
		System.out.println ("num3=" + num3);//num3=1569325056000
		System.out.println ("num4=" + num4);//num4=7766279631452241920
	}
}

6. Java Interview question: How to perform some actions in a interface

Package Com.test.test.java;
/**
 * Java interview question: How to execute some code in a interface?
 * * Public
interface Testinvocation {public
	static final Runnable Runnable 
		= new Runnable () {
		@Override c7/>public void Run () {
			System.out.println (
				"Like this, the class loading mechanism, of course, can also be the type of other classes."
			);}}
	; 

In addition, the default method is added to Java 8, specifically for this requirement.

7. How does the UUID key in MySQL become orderly?

Select Concat (Date_format (current_timestamp, '%y%m%d%h%i%s '), '-', UUID ());
The results returned are as follows:

Mysql> Select Concat (Date_format (current_timestamp, '%y%m%d%h%i%s '), '-', UUID ());
+----------------------------------------------------------------------+
| concat (Date_format current_ Timestamp, '%y%m%d%h%i%s '), '-', UUID () |
+----------------------------------------------------------------------+
| 20140705202902- F280257A-043F-11E4-989A-00163E0202CA                  |
+----------------------------------------------------------------------+
1 row in Set (0.00 sec)

8. Why is the standard in the JSON definition , the property name needs to be quoted , like the following name?

{' name ': ' Csdn ', ' Age ': 11}


9. About the JVM

There is a WAN (Lai) interview technique, you can ask the job seeker, what is the idea behind it, do you understand his principles, why do you do this, if you write yourself, how long do you want to do a basic version out?

What are the GC,
What are the differences in each JDK version,
which algorithms are better,
what is appropriate, what
is the idea of recycling,
How to achieve,
what are the advantages and disadvantages,
how you want to tune ...


10. Interview questions: Java, what's the problem with the following usage?

Date Nextmonth = new Date (new Date (). GetTime () + 30*24*60*60*1000);

Of course, this usage is very bad, plus one months should use the Calendar class, Calendar is Java Standard Tool class, under the Java.util package.

		Date today = new Date ();
		Calendar cal = Calendar.getinstance ();
		Cal.settime (today);
		Cal.add (Calendar.month, 1); Add one month
		cal.add (calendar.date,-1);//Minus day
		//
		DATE NEXTM = Cal.gettime ();
		System.out.println (NEXTM);

The more pits are here:

		Long n = 30*24*60*60*1000;
		Long nl = 30*24*60*60*1000l;
		System.out.println ("n=" +n);
		System.out.println ("nl=" +nl);
You can refer to the following output results:

n=-1702967296
nl=2592000000


Hint: How much value can the INT value drop?


11. For the instanceof of list, please say 123

Import java.util.ArrayList;
Import java.util.List;
/**
 *  What is the result of the following code execution (output)?
 */Public
class Testinstanceof {public
    static void Main (string[] args) {
        
        list<string> ListS = new Array List<string> ();
        list<testinstanceof> Listi = new arraylist<testinstanceof> ();
        What is the result of the following code execution (output)?
        if (ListS instanceof list<testinstanceof>) {
            System.out.println ("ListS instanceof list<testinstanceof >= "+true);
        } else {
            System.out.println ("ListS instanceof list<testinstanceof>=" +false);}}


12.




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.