J2SE basics: 8. Common System Class 2: j2se Basics

Source: Internet
Author: User

J2SE basics: 8. Common System Class 2: j2se Basics
1: transformation between basic data and encapsulation types


A: Basic Data Type ---> encapsulation type (object type)
Boolean boolean_1 = new Boolean (true );
Byte ----> Byte
Short ----> Short
Char ----> Character
Int ---> Integer
Long --> Long
Float --> Float
Double --> Double
B: encapsulation type ---> basic type
Integer. intValue ---> int
Folat. floatValue ---> float
Double. doubleValue ---> Double


2: conversion between basic types and strings


Call the String. valueOf () method.
String str = String. valueOf (any data type );


3: Convert string to basic data type


Call the parse method of the encapsulation class.
Int I = Integer. parseInt ("100 ");
Double d = Double. parseDouble ("12.334 ");




4: some common Characeter methods:


Character mainly works with the String object to perform some simple verification on the String object.
String. chatAt (I );

Simple data verification

Java. util. regex package

Pattern: compile a regular expression.

Matcher: checks whether the string matches the regular expression.


5: The String object has the length method. The array has the length attribute.


Math object

1: generate random number

A: use Math object: Math. random (); to obtain A random number between 0 and 1. This random number is always less than 0 and less than 1 decimal number.

B: Use a Random object.


2: decimal operation
Math. round (): the decimal point is not retained, and the numeric value is rounded down.
12.65 ---> 13
Math. ceil (): retain the decimal place to obtain the ceiling closest to the number.
12.65 --> 13.0
Math. floor (): the floor with the nearest digit is retained.
12.65 --> 12.0






Date object

1: how to get the system time:
A: System. currentTimeMillis:
It indicates the number of milliseconds that have elapsed since January 1, lunar January 1970 yen.
B: java. util. Date ();
Subclass: java. SQL. Date: The year, month, and day when the Java program processes the Date fields in the database.

Java. SQL. Time: the Time, minute, and second used by Java programs to process the date fields in the database.

Java. SQL. TimeStamp: The year, month, hour, minute, and second used by Java programs to process date fields in the database.

C: Calendar class:
Calendar




Mutual conversion between the three objects.


Between Long and Date.

Long ---> Date
Long l = 20171110888578l;
Date date = new Date (l );


Date ---> Long
Date date = new Date ();
Long time_long = date. getTime ();


Conversion between Long and Calendar
Long ---> Calendar
Long long_time = 121110864656l;
Calendar calendar = Calendar. getInstance ();
Calendar. setTimeInMillis (long_time );
Calendar ---> Long
Calendar calendar = Calendar. getInstance ();
Long time_long = calendar. getTimeInMillis ();

Conversion between Date and Calendar
Date ---> Calendar
Calendar calendar = Calendar. getInstance ();
Calendar. setTime (new Date ());

Calendar ---> Date
Calendar calendar = Calendar. getInstance ();
Date date = calendar. getTime ();


Formatting time


Format ---> DateFormat ---> SimpleDateFormat ();


Convert date to string

Call SimpleDateFormat. format


String to date


Call SimpleDateFormat. parse.


Precise computing object
BigInteger: exact integer calculation

BigDecimal: exact decimal calculation.


Truncation and rounding.


Normal format
NumberFormat numberFormat = NumberFormat. getInstance ();


Percent format
NumberFormat numberFormat = NumberFormat. getPercentInstance ();


// Set the Maximum/minimum reserved integer bits.
NumberFormat. setMaximumIntegerDigits (4 );
NumberFormat. setMinimumIntegerDigits ();

// Set the Maximum/minimum number of digits after the decimal point
NumberFormat. setMaximumFractionDigits (2 );
NumberFormat. setMaximumFractionDigits ();
Loan currency format
NumberFormat numberFormat = NumberFormat. getCurrencyInstance ();




DecimalFormat
Number ---> string (rounding function)
DecimalFormat decimalFormat = new DecimalFormat (".##");
String result = decimalFormat. format (d );



The basis of J2EE is J2SE. Question: What is the basis of J2SE? For example, the form is not important.

Collection operations. (Very important !!!)
File IO operations. (Very important !!)
In addition, there are some common classes and methods (very important !! But it is mainly accumulated in work practices)
(For example, type conversion, date type, reflection, polymorphism, parsing configuration files, etc)
Thread. (Depending on the company's specific business to determine the importance, generally grasp the line)
Abnormal operations and custom exceptions. (The general requirements of companies are not too high)
In addition, database operations should also be mastered.
Java internal class (just understand the concept. It is an advanced usage and I feel that it is rarely used)

These are my work experiences.

What are J2SE basics?

1 Java Introduction 2 basic syntax 3 object-oriented 4 exception handling 5 arrays 6 common Class 7 container 8io stream 9 thread 10 network 11GUI
 

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.