Day02-java Basic

Source: Internet
Author: User
Tags null null readable variable scope

 the basic framework of Java
    • 3w:what how Why

    • What: What is a thing, what is the function of it?

    • How: What to do? How functionality is implemented

Read source code (JDK)--Learn a lot, elegant programming skills based on why: Design (why others want to use such a design to achieve such a function)-based on how> > (designers, architects)

Description: Reading code is much more difficult than learning code!

Idea Create new Project-create class file
    • Classes in Java syntax are decorated with public:

    1. The class name of the file name and public decoration must be the same

    2. A Java file that has and can have only one class that is modified by public

    3. There can be multiple Java classes, except that these Java classes cannot be modified by public

    4. Javac the compilation and execution unit, is the class is not a file

Key Words
    • Overview: Words (names) that are given a specific meaning by the Java language

    • Features: The letters that make up the keywords are all lowercase

    • Keyword considerations: Goto and Const exist as reserved characters and are not currently used

There are only 49 keywords listed in PPT in total in Java

keyword considerations:
    • Goto and const exist as reserved words, not currently applicable

    • High-level Notepad like editplus,notepad++, highlighting for keywords

Java Syntax Rules If a Java file has a class that is public-decorated
    1. The name of the Java file must be exactly the same as the public class that is publicly decorated

    2. There must be only one class in a Java file that is modified by public

    3. But there can be multiple Java classes, which cannot be modified by public

    4. Javac the compilation and execution units are classes rather than files

identifier (name of your own)
  • Meaning: A sequence of characters used to name a class, interface, method, variable, etc.

  • Composition rule:

    • 1. English uppercase and lowercase letters

    • 2. numeric characters

    • 3. $ and _

  • Precautions

    • 1. Cannot start with a number

    • 2. Cannot be a keyword in Java

    • 3. Case sensitive

in the actual development

The names of classes and interfaces, variables and methods, packages, constants, in order to make our code more readable: There are conventions for naming rules

1. Classes and Interfaces:
    • One word: The first letter of the word is capitalized, and the remaining characters are lowercase.

    • Multiple words: The first letter of each word is capitalized, the remaining characters are lowercase. To make the code more readable. public class Javasign/public Class Helloworld/getelementbyid

2. Names of variables and methods:
    • One word: all lowercase (main,get,set,a)

    • Multiple words: First letter lowercase, remaining words capitalized (Tostring,getclass)

3. Package:

Role: To organize Java classes, avoid naming conflicts

    • One word: all lowercase. (Javabasic)

    • Multiple words: Domain reversal form: com.cskaoyan.www

      IP address-domain name is unique in the network

      Domain name: Not really only one domain name

4. Constants:
    • One word: All letters capitalized, for example: Pi,max,min

    • Multiple words: All letters are capitalized, but the words are concatenated with each other, for example: Max_value,min_value,student_age

Notes
    1. Overview: Text used to interpret the description program

2. Classification

    • Single-line Comment://Comment text

    • Multiline Comment:/* Comment Text */

    • Document comments:/** Note Text * * When creating JDK documents, let the compiler ignore the text that the comment symbol refers to, and the text is only for our developers to read

3. Application

    • Write the comments first, then write the code

    • The first step, complete the XXX function//easy to debug

4. Benefits of annotations

1. Grooming Ideas

2. troubleshooting, reading the code, judging the procedure in the code, and whether it is consistent with the description of the annotation (logic)

This is a single-line comment
?
/*
Multi-line comments
*/
?

This is a document comment
*/

ConstantsOverview

The amount of changes that will not occur during program execution

Constant Classification
  • Literal Constants
      • String constants: "Hello World"

      • Numeric constants: 34 59

      • Decimal constants: All decimals: 0.2.0.1

      • Character constants: Constant ' A ', ' B ', enclosed in single quotes '

    When characters and strings are stored, the values that represent the character or sequence of characters are stored; Each character has a corresponding value.

    Single character with ", >=2 characters with" ".

    ASCII Code table

    ' 0 ' 1 '
    code table ASCII
    character value
    ' A ' ' B ' C ' All-in-all
    $
    ' a ' B ' C ' 98
      • Boolean constant: True False

      • Null NULL constant: Object-oriented

  • Custom Constants (object-oriented)
binary number Binary
    1. Value range (0 and 1), base 2

    2. Turn decimal 110 = 1 * 2^2 + 1 * 2^1 + 1*2^0 =7

    3. Each digit represents the actual value =x*2^n-1

octal
    1. Value range (0-7), base 8

    2. Turn decimal 567 = 5 * 8^2 + 6 * 8^1 + 7*8^0 =

    3. Each digit represents the actual value =x*8^n-1

decimal

1. Made up of 0~9. Integers are decimal by default

hexadecimal
    1. Range of values (0-9 abcdef), Radix 16

    2. Turn decimal c3= 12 * 16^1 + 2 * 16^0

    3. Each digit represents the actual value =x*16^n-1

conversions between different binaries
  • decimal binary, octal, hex

    • In addition to the full remainder (12) The first step 12% 2 + 0

    • ? Step 6 2 more 0

    • ? Third Step 3 2 + 1

    • Fourth Step 1 2 + 1

    • so (all) = (1100) ~10~

  • Binary turn octal, hex

    • 1100 0010 is converted to octal, three-bit binary can represent a range of 0-7, just an octal value range, if it is a decimal, the decimal point to the left or right full 0??。

    (011) (000) (010) =302

    • Binary hexadecimal, right-to-left, one group per four bits (1100) (0010) =C2

Constants (different representations of the binary)
 
//1100 decimal:
System. out. println ( "1100");
//1100 binary:
system. Out. println ( "0b1100");
//1100 octal:
system. Out. println ( "01100")
// 1100 of 16 binary:
system. Out. println ( "0x1100")

Constants (Symbolic data notation)

Within the computer, there are 3 notation numbers: The original code, the inverse code, and the complement .

All data is performed in the complement.

Symbol bits do not need to be calculated separately and can be directly and numerically involved in the operation

Positive and negative numbers

One binary to indicate positive or negative, 0 positive, 1 negative

  • Original code: Numeric value with sign bit 1100: positive 0000 1100 = +1100

  • ? Negative 1000 1100 indicates-1100

  • Anti-code: Positive inverse code is the same as the original code, negative number of the inverse code to its original code is bit-wise (1 is 0,0 1), but the sign bit except.

  • Complement: The complement of positive is the same as the original code, the complement of negative is in its inverse code of the bottom +1.

  • The original code and its corresponding complement of the relationship: the original code and complement is some kind of complementary relationship.

    • The original code is known to complement, and the complement is known to seek the original code. ////////////////

    • 0000 0000 is 0

    • 1000 0000 Yes-0 anti-code: 1111 1111 complement: 0000 0000 (Anti-code + 1, carry, reserved eight-bit)

variables

Variable definition Format (fixed format):

Data type variable name = initial value (literal constant)

int getValue = 10;

    • Overview

      • The amount of value that can change within a range during the execution of a program.

      • Different data types, assigning different memory spaces to variables.

    • Initialization of variables: assigning values to variables

    • Variable scope: cannot have duplicate names within the same scope (main function curly braces).

Data Type

The Java language is a strongly typed language that defines specific data types for each type of data, and allocates memory space of different sizes in memory. (Very strict on the data type)

category1. Basic Data Types

Each type occupies a different space, and the range of data represented is not the same.

    • Numeric type

      • Integer type (byte (-128-127) (one byte), short (2), int (4), Long (8))

      • Floating-point type (flout,double)

    • Character type (char)

    • Boolean Type (Boolean)

Integer default: int (e.g. 10) decimal default: double (e.g. 0.0)

Such as:? Flout C = 0.1 pair: Flout C = 0.1f

2. Reference data Types
    • Classes (Class)

    • Interface (interface)

    • Array ([])

Type Conversions
  • Boolean types cannot be converted to other data types

  • Default conversions (small type conversions to large types) (large range types cannot be placed in small ranges)

    • Byte,short,char->int->long->float->double

    • Byte,short,char do not convert to each other, they participate in the operation first converted to the int type.

      • Char types can be added based on ASCII conversions and int types

  • Coercion type conversions (large type to small type)

    • Target type variable name = (target type) (data to be converted);

  • Short B = 100;

    BYTE AA = (byte) (b+1);

    0 1000 0010

    //

    Byte bb = (byte) 130//out of range, intercept limited number of bits

Day02-java Basic

Related Article

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.