Java written test question 009

Source: Internet
Author: User
Tags date now


1 , Char can a type store a Chinese character? Why

Answer: Yes. A char is two bytes, and a Chinese is two bytes.

2 , switch SELECT statement can function in string "string", which is the ability to write: switch ( )

answer: No, can only handle Int,byte,short,char , (in fact, it can only handle int, three other types are available Promotion to the int type) cannot be processed sring .

3 , Keywords Final individually modifying a class, a method, a variable, what does each function

Answer: Final a decorated class cannot be inherited

fianl the adornment method cannot be overridden in a subclass

Final modifier variables, called constants, do not change values after initialization.

1, briefly describe the similarities and differences between synchronized and Java.util.concurrent.locks.Lock?
Answer:
Main similarities: Lock is able to accomplish the main differences in all the functions implemented by synchronized: Lock has more precise line semantics and better performance than synchronized. The synchronized automatically releases the lock, and lock must require the programmer to release it manually, and must be released in the finally clause.

2. How to format the date
Answer:
Date Now=new date ();
SimpleDateFormat sdf=new SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss");
String Formatnow=sdf.format (now);
Variable Formatnow is a well-formed date.

3. Convert character "12345" to long type
Solution: String s= "12345";
Long num=long.valueof (s). Longvalue ();

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

Java written test question 009

Related Article

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.