Java _ 2_java

Source: Internet
Author: User

First, Let's explain why I learned Java. This is mainly because we need to use this equipment. There is a device on the site, ABB's board type meter, which uses the background of Java, using the Java Server and

The DSP chip is used for data collection and analysis. The DSP performs high-speed data collection and then uses Java for data analysis. So you need to learn this to understand DSP and Java communication and Win32

Platform communication related content.

[Java shell class]

I think this Java and C # are a bit similar. First, you need to define a class. Let's first look at this class.

 
1/* 2 this program test the basic data type 3 4 1, Boolean 5 2, byte 6 3, short 7 4, Int 8 5, long 9 6, float10 7, double11 8, char12 13 */14 15 16 17 public class inttest // Because Java is purely object-orientedProgramDesign Language, All executableCodeMust be in the class, 18 // so a class must be defined here. 19 // The class is used as a "Container" for loading "Program Logic" 20 21 {22 public static void main (string [] ARGs) // all functions in Java belong to a class, so the main method requires a "shell class"

We can see that this is different from C ++.

[Java boolean type]

In Java, a data type is provided to indicate logical results: Boolean

Public class inttest // Because Java is a pure object-oriented programming language, all executable code must be in the class, // a class must be defined here. // The class is used as a "Container" for loading "Program Logic" {public static void main (string [] ARGs) // all functions in Java belong to a class, therefore, the main method requires a "shell class" {// first test the boolean type boolean yesorno = true; If (yesorno) system. out. println ("yes ");

We can see that the boolean type is very similar to the Boolean Type in C, but the difference is that in C, "non-zero is true, and zero is equivalent to false ", in Java, this is not the case because JAVA does not support

Conversion between Boolean and other types. Note This. As shown in:

[JAVA byte type]

In Java, a single-byte data type is provided: byte, which is used to indicate that a small value is effective and saves memory space. However, it is not conducive to CPU processing.

// Test byte overflow = (byte) 300; system. Out. println (overflow); // in Java, the byte value ranges from-128 ~ 127 a total of 256 statuses will be intercepted at the same time // type cast, so here the output is 44 overflow = 300 & 0xff; system. out. println (overflow); // You Can See That during integer data conversion, the data can be processed according to the storage features, similar to the C language system. out. println ("the max value of byte is:" + 0x7f); system. out. println ("the min value of byte is:" + ~ 0x7f); // you can see that this is a bit special. A macro is provided in C to represent Max and // min values. Is there any in Java?

Through the test, we found that the value range of byte is :~ 0x7f-0x7f; in addition, the value can be intercepted in the same way as in C. I don't know what you think.

Forced type conversion, I feel that using "bitwise AND" can better reflect the computer system.

Here is a bit worth exploring. Why?-256 is ~ 0xff, and ~ 0x7f is-128? I feel a little strange at the moment. The execution result of the above program is as follows:

Here I know that the double type provides some constants: Double. positive_infinity, double. negative_infinity, and double. Nan to represent the maximum value.

Minimum and infinite values, but does byte support such class libraries?

[Java short type]

The short type is the same as the 16-Bit Signed short type in C. The value range is-327687 ~ 32767. as shown below:

 
// Test the short type short export testvar = 0x7fff; system. out. println ("the max value of short is:" + export testvar); system. out. println ("the min value of short is:" + ~ Using testvar );

The running result of this Code is shown in:

[Java int type]

The Int type is the same as the signed int type in C Language (32-bit int type), indicating that the value range is 0x80000000 ~ 0x7fffffff (Computer internal representation );

 
// Test the int type int inttestvar = 0x80000000; system. Out. println ("the max value of int is:" ++ ~ Inttestvar); system. Out. println ("the min value of int is:" + inttestvar );

Shows the running result:

 

[Java long type]

The long type is the same as the long int type in C language. The value range is 0x8000 0000 0000 ~ 0x7fff FFFF (Computer internal representation ).

 
// Test the long data type long longtestvar = 0x8000000000000000l; system. Out. println ("the max value of Long is:" + ~ Longtestvar); system. Out. println ("the min value of Long is:" + longtestvar );

Shows the running result:

The long data type must be described as follows: to represent a long integer, you must add an "L" after the number ".

[Java integer Summary]

Java does not have the concept of unsigned numbers. All Integer Data is signed. This is different from C/C ++.

By default, the value of an integer is of the int type. This is important, otherwise it is prone to errors, as shown in:

[Java double data and float data]

Float data occupies 4 bytes, while double data occupies 8 bytes. The float data type has 6 ~ 7-bit; double is 15-bit; if not specified, floating point

The numeric nominal value is double. If you want to represent the float floating-point numeric nominal value, you need to add f after the nominal value, for example, 3.1415926f.

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.