Basic JAVA library usage, basic java

Source: Internet
Author: User

Basic JAVA library usage, basic java

Double-click SHIFT in Idea to search for [Eclipse also has]. This is very important. You can find the existing classes of engines in the current project and do not invent the wheel by yourself.

Various Util types are first found in the basic library and open source Library

Base64 encoding

Guava: com. google. common. io. BaseEncoding

Commons-codec: org. apache. commons. codec. binary. Base64

Various digest algorithms are available

[WARNING]/opt/work/2014/work/centos2017/webman/src/main/java/cn/csbit/util/License. java: [370,41] sun. misc. BASE64Encoder is an internal dedicated API and may be deleted in future releases.

[WARNING]/opt/work/2014/work/centos2017/webman/src/main/java/cn/csbit/core/report/vo/ReportVo. java

Date

Commons-lang

Org. apache. commons. lang. SerializationUtils

Org. apache. commons. lang. time

DateFormatUtils DateUtils

Cn. csbit. core. util. DateUtil

String processing

Org. apache. commons. codec. binary

Org. apache. commons. lang StringUtils

Files

The classes added by the new JDK version to facilitate file operations already exist.

Commons-io

Processing of org. apache. commons. io FilenameUtils file names

Disk Space status of FileSystemUtils

Digital Conversion

Ints Longs Shorts UnsignedInts

Com. google. common. primitives

@ GwtIncompatible ("Doesn\'T work")

Public static byte[] ToByteArray (IntValue ){

Return new byte[] {(Byte) (Value> 24 ),(Byte) (Value> 16 ),(Byte) (Value> 8 ),(Byte) Value };

}

@ GwtIncompatible ("Doesn\'T work")

Public static intFromByteArray (Byte[] Bytes ){

Preconditions. checkArgument (bytes. length> = 4,"Array too small: % s <% s",NewObject [] {Integer. valueOf (bytes. length), Integer. valueOf (4 )});

ReturnFromBytes (bytes [0], bytes [1], bytes [2], bytes [3]);

}

Public static byte[] Bytes tobytes (ShortNumber ){

IntTemp = number;

Byte[] B =New byte[2];

For(IntI = 0; I <B.Length; I ++ ){

B [I] =NewInteger (temp & 0xff). byteValue ();//Save the bitwise In the bitwise

Temp = temp> 8;//Move to the right8Bit

}

ReturnB;

}

Public static byte[] ToByteArray (IntValue ){

Byte[] Array =New byte[4];

For(IntI = 0; I <4; I ++ ){

Array [I] = (Byte) (Value >>( 8 * I) & 0XFF );

}

ReturnArray;

}

NumberUtil common-lang is similar

IP address

# Include <arpa/inet. h>

Uint32_t htonl (uint32_t hostlong );

Uint16_t htons (uint16_t hostshort );

Uint32_t ntohl (uint32_t netlong );

Uint16_t ntohs (uint16_t netshort );

ByteBuffer B = ByteBuffer. allocate (4 );

B. order (ByteBuffer. LITTEN_ENDIAN );

B. putIn (100 );

B. array (); // you can obtain the byte array.

Com.google.common.net. InetAddresses

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.