Java a little bit of content

Source: Internet
Author: User

1.JAVA What is the basic data type string is not the base data type

The Java language provides eight basic types:

Six types of numbers (four integers, two floating-point)

BYTE type byte 8-bit short 16-bit integer int 32-bit long 64-bit

Single-precision float 32-bit double 64-bit

A character type

Character Char 8 bit

There is also a Boolean type.

Boolean: Boolean 8 bits can store "True" and "false"

String str1 = "x";

String str2 = "x";

String str3 = new String ("X");

The string itself is an object rather than a base data type, and the variable name of string is a reference to the string class.

When the fame str1, because there is not equal to the "X" object, so created a new object;

In the name of the str2, because of an object equal to "X", the system will take its value out directly to STR2, so the str1 and str2 variable names are references to "X" objects.

Of course, the new String () will actually be a fresh object.

2. Usage of "= =" and "Equals"! (Will be more understanding of what is said above)

= = The comparison of objects seems to be the comparison of addresses

Comparison of equals object values

So str1 = = STR2 returns TRUE,STR1 = = Str3 returns false, Str1.equals (STR3) returns True.

3. Conversion between data types
(1), how to convert numeric characters to numbers (integer,double)
(2), how to convert a number to a character

int I=integer.parseint ("5");
Float F=float.parsefloat ("5.0");
String s50=float.tostring (5.0);
4.java get month day hour minutes
Calendar cal=calendar.getinstance ();
Cal.settime (New Date ());
int Year=cal.get (calendar.year);
int Month=cal.get (calendar.month) +1;
int Date=cal.get (calendar.date);
int Hour=cal.get (calendar.hour);
int Minute=cal.get (calendar.minute);
int Second=cal.get (Calendar.second);
int Millisecond=cal.get (Calendar.millisecond);

5. What is an exception and what are the two methods of exception handling?

An exception is an abnormal phenomenon that occurs during a program's operation. For example, user input errors, divisor is zero, files that need to be processed do not exist, array subscript is out of bounds, etc.

There are two ways to handle exception handling: The first is to use the try...catch...finally structure to capture and handle exceptions, and the second clock to throw exceptions by throws and throw.

6. What is a flow? Depending on the direction of the flow, which two streams can be divided into?

The input/output of Java is handled in a streaming manner, and the stream is a data sequence that flows through the input and output operations of the computer.

Depending on the direction of the stream, the stream can be divided into an input stream and an output stream.

Java a little bit of content

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.