2 Java Basics

Source: Internet
Author: User
Tags binary to decimal

One, Java identifiers

/* Identifiers: Some of the names in Java programs can be customized, so these custom names are referred to as custom identifiers. Identifiers to note the details: 1. The constituent elements of an identifier are composed of letters (A-ZA-Z), Numbers (0-9), underscores (_), Dollar signs ($). 2. Identifiers cannot begin with a number. 3. Identifiers are strictly case-sensitive. 4. The length of the identifier is not limited in length. 5. The name of the identifier is generally meaningful (to make people see the meaning of the name) 6. keywords, reserved words cannot be used for custom identifiers. Specification for custom identifiers: 1. The first letter of the class name and interface list Word is capitalized, and the other words are lowercase. For example: Runtime.2.  The variable name and method name are all lowercase, the other words are capitalized, and the other lowercase. For example: Docook (); 3. Package name all words lowercase.  4. Constant all the words are capitalized, and the words are separated from the words using an underscore. For example: Up_direction judge the identifiers that are compliant: 12ABC_ illegal numbers can not start _12ABC legal $ab12# illegal #号不属于标识符组成元素. [Email protected] Illegal @ does not belong to the identifier component element. Keywords: keywords are identifiers that have special meanings in Java programs. Keywords are typically used to describe the structure of a program or to represent a data type. */class demo1{public static void Main (string[] args) {System.out.println ("Hello world!");}}


Second, Java annotations

/* Requirements: Write a Java program to simulate QQ landing. Note: Comments are instructions that use text to the program, and comments are written to programmers, and the compiler ignores the contents of the comments.   Categories of annotations: first: Single-line comments.   The second type of comment: Multiple lines of comment.    /* The contents of the note *//* Third: document comments. The contents of the/** comment *//* document comments are also a multiline comment. Note the details to be noted: 1. Single-line comments can be nested, and multiple lines of attention are not nested. Effect of annotations: 1. Use text to describe the program. 2. Debug the program. Compile time no problem, the implementation of the time did not achieve the desired effect */class Demo2 {/** night-bed before the moonlight, suspected ground. Jutou look at the screen and bow to the code. *//* This is a QQ program QQ program is to first enter the user name and password and then verify the user name and password */public static void main (string[] args) {System.out.println (" Please enter user name and password "); System.out.println ("Verify User name and password");  System.out.println ("AAA"); This sentence is used for testing, no tube System.out.println ("Show Friends List");}}


Third, document comments

/* software = data + instruction + documentation (user documentation + developer documentation) The difference between a document comment and a multiline comment: The difference between a multiline comment and a document comment: The contents of a multiline comment cannot be used to generate a developer document, and the content of a document comment can produce a developer document. Use the Javadoc development tool to generate a developer documentation. Javadoc tool use Format: javadoc-version-author-d the path to the document Java source files use the Javadoc tool to pay attention to the details: 1. If a class needs to use the Javadoc tool to generate a developer document for a software, the class must be decorated with public. 2. The contents of a document comment note are generally located above the class or method. Specifications for writing annotations: General single-line comments are located on the right side of the code, and multiline comments and document comments are generally written on top of the class or method. *//** This class is used to simulate the QQ software @author administrator@version 1.0*/public class Demo3 {/** operation flow is as follows: 1. First enter the user name Password 2. Verify username and password 3. Show Friends List */  public static void Main (string[] args) {System.out.println ("Please enter user name and password"); This sentence is used to enter the user name and password. System.out.println ("Verify User name and password"); System.out.println ("Show Friends List");}}


IV. constant and binary conversions


650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7E/AD/wKiom1cG5yyiSrUYAAB5oWvPgNU385.png "title=" The origin of the binary. png "alt=" Wkiom1cg5yyisruyaab5owvpgnu385.png "/>650) this.width=650; src=" http://s1.51cto.com/wyfs02/ M00/7e/a9/wkiol1cg5-ninw0eaacfursnnu8132.png "title=" the conversion between decimal, octal, and binary. png "alt=" Wkiol1cg5-ninw0eaacfursnnu8132.png "/>650) this.width=650;" Src= "http://s2.51cto.com/wyfs02/M01/7E/AD/ Wkiom1cg50jr24gyaabfyfkmojg106.png conversion between "title=" decimal and binary. png "alt=" Wkiom1cg50jr24gyaabfyfkmojg106.png "/>650" this.width=650; "src=" http://s5.51cto.com/wyfs02/M02/7E/AD/wKiom1cG513zkk19AABukdX-bQU515.png "title=" Hexadecimal and decimal, Conversion between binary. png "alt=" Wkiom1cg513zkk19aabukdx-bqu515.png "/>


/* Software  =  data +  Directive +  document constant:  constant is the amount of the program's value cannot change during operation. Category of constants: integer constant    10 12 decimal constant 3.14 Boolean constant     Boolean constant only two values:  true (correct).  false (Error) A character constant     character constant is a single character that is enclosed in single quotation marks. We call it the character constant. The string yield    string constant is a literal string constant that is referred to by using double quotation marks. The representation of integer constants: The representation of integers is mainly expressed in different binary (binary, octal, hexadecimal). Binary:  Decimal (0~9)     Week (seven  0~6),   hours (12 binary (0-11),  24 (0~23)): represents all values with a limited number symbol. The appearance of computers is to serve the human, then the real life of the human data used is basically a decimal data, then whether the computer can be stored in real life data? What kind of storage can you store it in? Binary origin. Computer records our real-life data are recorded using binary, then we need to know how to convert the decimal data into binary. Conversion between decimal and binary: decimal-to-binary method: Use decimal data to divide by 2 continuously until the quotient is 0. The remainder from bottom to top is the corresponding binary. 10 (decimal)-------->1010 (binary) binary to decimal: each bit of binary is multiplied by 2 N, N starts at 0, increments by 1 each time, and then the data of each part is added.  1110 (binary)  ---------> 14 (decimal) The disadvantage of binary system:  binary writing is too long, inconvenient for human memory. Binary data features:  consists of 0~1. Solution: A number is recorded per three bits. 1000 (decimal)------> 001,111,101,000 (binary)  = 1,7,5,0 an octal data is equivalent to three bits. Conversion between decimal and octal: decimal to octal: Use decimal data to divide by 8 continuously until the quotient is 0. The remainder from bottom to top is the corresponding octal system. 45 (decimal)------>  55  octal to decimal: Use each bit of octal to multiply by 8 N, n from 0, increment by 1 each time, then add the data of each part. 23 (octal)------>     (decimal) octal data features:  only 0~7 these eight characters. Hex Data:  0~9 , a (Ten) \b  (one), C (+), D (+),  e (+), F (+),  The four bits are a hexadecimal data. 16 binary data is composed of 0~9, a-f. Decimal is converted to 16: The decimal data is continuously divided by 16 until the quotient is 0. The remainder from the bottom up is the corresponding hexadecimal. 38 (decimal)---->26   (hexadecimal) hexadecimal to decimal: use hexadecimal to multiply each bit by 16 N, N to start at 0, increment 1 each time, and then add the data for each part. 34 (hex)-----> 52 (decimal) */class demo4{public static void main (String[] args) {/* System.out.println ( //), integer constant System.out.println (3.14),  //decimal constant System.out.println (false);  // Boolean constant System.out.println (' 1 ');  //character constant System.out.println ("Hello world");  //string constant If a data is not added to any of the identities, The default is the decimal data. */system.out.println (Ten);//  decimal System.out.println (0B10);  //binary  ,  If a data is to represent binary, Then add 0b to the front of the data. SYSTEM.OUT.PRINTLN (010);  //octal data,  octet data needs to start with 0 System.out.println (0x10);  //Hex Data,  Hex data needs to start with 0x}}


V. variables

/* There is a lot of data in real life that is often changed. such as:  weather  , mood  , time, stock market ... Variable: A variable is the amount of the value that can change during a program's run. A variable is a container for storing data. What characteristics of the container:    1.  capacity (size).     2.  store data in a certain format.     3.  name .     Declaration (definition) The format of a variable:     capacity     Variable name  =  data.   Naming conventions for variable names:  the first word lowercase, other words capitalized in the first letter, and other lowercase. Java indicates how large a variable's capacity is using a data type description. There are two main data types in Java   data types      basic data types      reference data types     Eight basic data types in Java data type of:     integer:         byte (bytes)        8 bit (bit)   1 bytes     2^8 = 256     -128~127 0 in Java is a positive         short (short integer)       16bit     2 bytes     2^16 = 65536         int (integral type)     &Nbsp;  32bit       3 bytes     2^32         long (Long integer type)      64bit      4 bytes    2^64 =  Note:  If an integer is not added to any of the identifiers, then the data of type int is the default. If you need to represent this data as a long type of data, you need to add the data followed by L to indicate that L is case-insensitive, but it is recommended to use uppercase. Doubt: the storage of integers can use four data types, then how to choose how to use it? The principle of choosing data type:  can be small if it can meet the demand. Save memory space. Data type of decimal:     float (single-precision float)     32bit  3 bytes       Accurate decimal digits are 7-bit     double (double-precision floating-point)     64bit  4 bytes       Accurate decimal Places 15-bit note:  If a decimal is not prefixed with any identity, then the decimal number defaults to the double type of data, and if you need to represent a float type, you need to add an F representation after the decimal. F is case-insensitive. A Boolean type:  Boolean type has only two values, true or FALSE.     boolean    1 byte or 4 bytes         If you use Boolean to declare a variable of a primitive type, then the variable is 4 bytes,     If you use Boolean to declare an array type, then the element of each array takes one byte.      character type:     char  2 bytes (16bit)      Eight basic data Types:      integer:byte short int long      decimal: float  double      Boolean: boolean     character: The data type of the  char string is: string   Reference data type, not part of the base data type. */class demo5{    public static void main (String[] args)       {        //requirements 1:  defines a variable to store the age of a normal person.          byte age = 120;  // A variable of type byte is declared, which is named age and stores 120 in the age variable.                 //changing the value of a variable          age = 121;                 //requirements 2:  defines a variable to store Guo Jing pocket money.         short money = 128;                 //requirements 3:  Define a variable to store Huang Rong money.         int bossMoney = 1000000000;                 //requirements 4:  Define a variable store Ke zhen evil boss          long  allMoney = 10000000000000000L;                 //Storing decimals          float f = 3.14f;         double d = 3.1415926537;        boolean b =  false;                         char c =  ' a ';//characters are also stored with integer type         String str =  " Hello world ";         system.out.println (str);  // You need to get the data stored by a variable, just use the variable name.     }}

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7E/A9/wKioL1cG58Dz5visAABD4yTrImk883.png "title=" How characters are stored. png "alt=" Wkiol1cg58dz5visaabd4ytrimk883.png "/>


VI. Declaration of variables

/* How to declare a variable:     the way a variable is declared:         data type   variable name;      How to declare variables two:  one-time declaration of multiple same type variables          data types    variable name 1 ,  variable 2 .... Note that the:1.  variable must be declared before being used. 2.  cannot declare a variable with the same name   in a scope. */class demo6  {    public static void main (String[]  args)      {        //int age =  12; //declaring a variable          int age ,height ;   //declares the variable                  //assigning values to variables         age = 10;         height = 175;        system.out.println ( Age);        &nbsP SYSTEM.OUT.PRINTLN (height);     }}


This article from "Small Fish Blog" blog, declined reprint!

2 Java Basics

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.