Java Grammar Basics (Summary of classroom PPT)

Source: Internet
Author: User
Tags ming

One: Run the source code Enumtest.java, analyze the running results.

The code is as follows:

PublicClassenumtest {PublicStaticvoidMain (string[] args) {Size s=size.small; Size t=size.large; //s and T refer to the same object? System.out.println (s==t); //// is the original data type?  System.out.println (S.getclass (). isprimitive ()); // convert Size from string u=size.valueof ("SMALL" ); System.out.println (S==u); //true // list all its values for (Size value:Size.values ()) { System.out.println (value); }}} enum size{small,medium,large};         

Results:

The enumeration type (enumerated type) has long appeared in programming languages and is used to include a set of similar values into one type. The name of this enumeration type is defined as a unique type descriptor, which is similar to the definition of a constant. However, compared to constant types, enumeration types can provide a larger range of values for declared variables.

Two: Original code, anti-code, the difference between the complement and discrimination

The original code is the absolute value of the symbol bit plus the truth, that is, the first digit to represent the symbol, the remaining bits represent the values,
The inverse of a positive number is its own
Negative number of the inverse code is on the basis of its original code, the sign bit is unchanged, the remaining bits are reversed.
The complement is expressed in the following ways:
A positive complement is its own
The complement of a negative number is on the basis of its original code, the sign bit is unchanged, the rest of you take the counter, the last +1. (That is, on the basis of the anti-code +1)
Sample program:
public class QQ {/** * @param args */public static void main (string[] args) {//TODO auto-generated method stub  System . OUT.PRINTLN (0xFFFFFFFF);}}

Get the result as-1

Data in Java is represented by an inverse code.

Three: complete type conversion through wrapper classes of the original type

Source:

public class QQ {public    static void Main (String args[]) {        System.out.println ("0.05 + 0.01 =" + (0.05 + 0.01)); 
   system.out.println ("1.0-0.42 =" + (1.0-0.42));        SYSTEM.OUT.PRINTLN ("4.015 * =" + (4.015 *));        System.out.println ("123.3/100 =" + (123.3/100));}    }

四:Java变量遵循“同名变量的屏蔽原则”


Java variables are scoped. If two different scopes have the same name, no conflicts will arise.
To give a simple example: A class has a student called Xiao Ming, class two also has a student called Xiao Ming, in one class and the second class separate class, the name will not conflict.
Verification Code:
public class QQ {/** * @param args */private static int code=12;public static void main (string[] args) {//TODO Auto-gener Ated method Stubint code=-10; SYSTEM.OUT.PRINTLN (code);}}

Results:

五:为什么double类型的数值进行运算得不到“数学上精确”的结果?
This involves the conversion of binary and decimal.
n binary can be understood as: the power of the numerical x cardinality, for example, we are familiar with the decimal number 123.4=1x10²+2x10+3x (10 of the 0 power) +4x (10-1 power); the other binary is the same, such as the binary number 11.01=1x2+1x (2 0 Power) +0+1x ( 2-2 power) = 3.25 in decimal.
A value of type double takes 64bit, or 64 binary numbers, except that the highest bit represents the positive and negative sign, and the lowest bit is bound to have an error with the actual data (unless the actual data is exactly 2 of the n-th square).
VI: output format in Java
The source code is as follows:
public class QQ {/** * @param args */public static void main (string[] args) {//TODO auto-generated method Stubint X=100;i NT y=200; System.out.println ("x+y=" +x+y); System.out.println (x+y+ "=x+y");}}

Results:

Because +x+y indicates that only the values of X and Y are output, x+y represents the value of the output x+y.

Java Grammar Basics (Summary of classroom PPT)

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.