In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "what are the common data types of Java". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what are the common data types of Java"?
Catalogue
1. What is Java
2. Why does someone always say that Java is the best language
3. A simple main function
4. Run the Java program
5. Attention problems in Java writing.
6. Data types and operators
6.1 variables and types
6.2 Integer variables (emphasis)
6.3 long integer variable
6.4 double precision floating point variable
6.5 single precision floating point variable
6.6 character type variable
6.7 byte type variable
6.8 short integer variable
1. What is Java
Java is an excellent programming language, which has pleasing syntax and easy to understand semantics. Not only that, Java is also a technical system formed by a series of computer software and specifications, which provides a complete supporting environment for software development and cross-platform deployment, and is widely used in embedded systems, mobile terminals, enterprise servers, mainframes and other occasions.
2. Why does someone always say that Java is the best language
For one thing, the syntax is relatively simple, and developers who have studied computer programming can get started quickly.
Second, it has strong competitiveness in several fields, such as server-side programming, high-performance network programs, enterprise software transaction processing, distributed computing, Android mobile application development and so on.
Java ecology is very complete.
3. A simple main function public class HelloWorld {public static void main (String [] args) {/ / fixed writing of main function in System.out.printfln ("hello"); / / print function}}
Public: access modifier qualifier, which will be described in more detail after the completion of classes and objects in future learning.
The access modifier qualifier also includes private and protected
Class: used to define a class, which will be described in detail after a later study of classes and objects.
HelloWorld: the name of the class
Function is also called method
String [] args: array of formal parameters
4. Run the Java program
Java is a semi-compiled and semi-interpreted language. First, the source file is compiled by the javac compiler, and the generated .class file is a platform-independent, JVM-oriented file composed of bytecode. Finally, start the java virtual machine to run the .class file, and JVM converts the bytecode into a form that the platform can understand.
JRE (Java Runtime Environment): the Java runtime environment, which contains the JVM,Java basic class library. Is the required environment for writing programs in the Java language.
JDK (Java Development Kit): Java development kit for Java programmers, including JRE, but also includes the compiler javac and its own debugging tools Jconsole, jstack and so on.
The Java program needs to go through two stages: compiling and running.
Compiling: javac command
Run: java command
5. Attention problems in Java writing.
Every time you finish writing the code, remember to save ctr+s, and after each save, you must recompile.
If the class is public-decorated, the class name needs to be the same as the file name.
Not a file corresponds to a bytecode, but a class corresponds to a bytecode. The advantage of this is that which class is used to load which class, rather than all of it.
Public class HelloWorld {public static void main (String [] args) {/ / Runtime command line parameter for (int item0uti 2 ^ 31-1)
Public class HelloWorld {public static void main (String [] args) {int aq10; System.out.println (Integer.MAX_VALUE); / / is the plus version of int System.out.println (Integer.MIN_VALUE);}}
Variable naming: the hump is made up of numbers, letters, underscores, and dollar signs, but cannot start with a number
6.3 long integer variable
Basic grammatical format:
Long variable name = initial value
Code example:
Public class HelloWorld {public static void main (String [] args) {long int astat10L; System.out.println (Long.MAX_VALUE); System.out.println (Long.MIN_VALUE);}}
The long type occupies 8 bytes in Java, which represents a data range of-2 ^ 63-> 2 ^ 63-1.
There is no long long type in Java
6.4 double precision floating point variable
Basic grammatical format:
Double num = 1. 0
Code example:
Double num = 1.0 _ system. Out.println (num)
Note 1:
Int a = 1 position int b = 2 x system. Out.println (a / b)
Execution result:
0
In Java, the value of int divided by int is still int (the decimal part is discarded directly)
If you want to get 0.5, you need to use the double type to calculate
Double a = 1.0 position double b = 2.0 switch system. Out.println (a / b); / / execution result 0.5
Note 2:
Double num = 1.1terSystem.out.println (num * num); / / execution result 1.21000000000002
Although the double in Java is also 8 bytes, the memory layout of floating-point numbers is very different from that of integers, and the data range can not be expressed simply in the form of 2 ^ n.
The memory layout of Java's double type conforms to the IEEE 754 standard (like C language). If you try to use limited memory space to represent possibly infinite decimals, there is bound to be a certain precision error.
6.5 single precision floating point variable
Basic grammatical format:
Float variable name = initial value
Code example:
Float num = 1.0f / write 1.0F can also be System.out.println (num)
The float type of Java accounts for 4 bytes, which also complies with the IEEE 754 standard. Due to the small range of data precision, double is generally preferred for floating-point numbers used in engineering, and float is not recommended.
6.6 character type variable
Basic grammatical format:
Char variable name = initial value
Code example:
Char ch ='A'
A character in a computer is essentially an integer. ASCII is used to represent characters in C language, while Unicode is used to represent characters in Java. Therefore, a character occupies two bytes, indicating a greater variety of characters, including Chinese.
Use one character to represent a Chinese character:
Char ch = 'heh'; System.out.println (ch)
Sometimes there will be errors, so we can add the-encodingUTF-8 option when executing javac.
Javac-encoding UTF-8 Test.java
In Java, numeric types have a range of values, so do not exceed that range when storing data.
6.7 byte type variable
Basic grammatical format:
Byte variable name = initial value
Code example:
Byte value = 0scape system. Out.println (value)
The byte type also represents an integer, accounting for only one byte, indicating a small range (- 128-> + 127).
6.8 short integer variable
Basic grammatical format:
Short variable name = initial value
Code example:
Short value = 0scape system. Out.println (value)
Short occupies two bytes and represents a data range of-32768-> + 32767.
The scope of this representation is relatively small and is generally not recommended.
At this point, I believe you have a deeper understanding of "what are the common data types of Java?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.