Java Data types

Source: Internet
Author: User

A Java program is made up of one class.
Each program is finished with;
After the Java file is saved, enter the javac+ file name in the command console. Java generates a bytecode file (a file ending in a. Class) and then enters the java+ file name to run the result
There can be more than one class in a file, there are several classes in the source file, and several. class files are generated after compilation, and only one class in a source file can be declared public
public class name {}; Class, note: The class name declared as public class must be identical to the file name!
public static void Main (string[] args) {} This method is called the Main method, which is the entry of the program
System.out.println (); Output Statement Ln is the meaning of line break
System.out.print (); Output statement with no newline.
The core of the Java language:
Jdk:java Development Kits Development environment (developer-oriented)
Jre:java Runtime Environment Run-time environment (on server)
Identifiers: Identifiers (class names, method names, variable names, and so on) where you can name them
Naming rules for identifiers: (must be followed)
Consists of 26 letters in the case, 0-9,_ or $.
Numbers can not start
You cannot use keywords or reserved words, and the length is unlimited.
Identifiers cannot contain spaces.
The concept of variables:
A storage area in memory.
The zone consists of its own name (variable name) and type (data type)
Each variable in Java must be declared first and then used
Data in this region can vary from one type to the same range
Variable definition format in Java: data type variable name = initialization value. Example: int a=5;
A variable defined in a method cannot be called directly outside the method. Direct call reporting compilation errors
Categories of variables: basic data types, reference data types
Integer byte ( -128~127) int shot long
Define a long variable, it is worth the end to add L (case can be)
Floating-point defines the type of float after which you want to add an F (case can be)
Character type = Two bytes: Char defines the character type to be added "can only represent one character (English, Chinese, punctuation, etc.) an escape character (for example: ' \ t ' ' ln ') is also a character that can be received in Char
String: string definition strings to be added ""
Boolean type: can only be evaluated as true or FALSE. Cannot take value to null
Operations between variables (not considered Boolean left: char byte short int long float double)
1. Automatic type conversion
Small capacity is automatically converted to a large data type when the data type is small and the capacity is large.
Char, Byte, short== "int==" long== "float===double
It is important to note that the default result is int when the operation is done between Char, Byre, and short
2. Forced type conversion:
The large conversion of the capacity to the small capacity is with coercion type conversion: ()
Problem of forcing type conversion: loss of precision.
The operation between the string and the base type: Only the JOIN operation: +. The resulting result is still a string

Java Data types

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.