20165231 2017-2018-2 "Java Programming" 2nd Week study Summary

Source: Internet
Author: User
Tags control characters java keywords

Objective

The second week is a formal study of Java programming. Before the Java is a blank, now is the first clue, know the basic Java program start, more than one class to run which, which is output printing statements and so on.

The Java code writer I'm using now is Atom an Atom Github open source text editor, built entirely using web technology (based on Node-webkit). Fast startup, with a lot of common functions of the plug-ins and themes, can be said to be Atom sufficient for the "half of the IDE."

Compared to Notepad and Linux system vim , and gedit so the editor Atom is very smart, different features different properties of the code color different to show the difference, and even can complement the code (but this function after the proficiency of later use, now is to practice more dozen code to write down the basic format and statement).

Atomcan also be the system to manage the entire large folder under the numerous folders and files, you can at the side of the sidebar at a glance in the Code folder under what folders and files, code Open switch is also very fast. Recommended, Windows subsystem is installed directly under Windows and then opens Atom open project in the C disk to find your own subsystem folder (in my own case C:\Users\wyhy-(computer owner user name, specifically find his own name) \appdata\local \packages\canonicalgrouplimited.ubuntuonwindows_79rhkp1fndgsc\localstate\rootfs\home\yhooyon (my Ubuntu system name, Specifically find their own) to find their own user folder to find the SRC folder to store the code to manage their own code.

Textbook Learning content summary identifiers and keyword identifiers

A valid sequence of characters used to identify the class name, variable name, method name, type name, array name, and file name is called an identifier, and the identifier is a name.

Java Rules for identifiers:

  • Identifiers consist of letters, numbers, underscores "_", dollar Sign "$", and the first character cannot be a number.
  • You cannot use Java keywords and reserved words as identifiers.
  • Identifiers do not have a length limit.
  • Identifiers are case sensitive.

    Keyword keywords are words that have a specific meaning and cannot be used as identifiers.
    Java50 a key word;
  • Abstract indicates that a class or member method has an abstraction attribute
  • Assert assertion, which is used for program debugging
  • One of the Boolean basic data types, Boolean type
  • Break jumps out of a block early
  • One of the byte base data types, byte type
  • Case is used in a switch statement to indicate one of the branches
  • Catch is used in exception handling to catch exceptions
  • Char one of the basic data types, character type
  • Class declares a category
  • CONST reserved keyword, no specific meaning
  • Continue back to the beginning of a block
  • Default defaults, for example, in a switch statement, indicating a default branch
  • Do used in the DO-WHILE loop structure
  • Double one of the basic data types, two-precision floating-point number types
  • else used in a conditional statement to indicate a branch when the condition is not true
  • Enum enum
  • Extends indicates that one type is a subtype of another type, where the common types have classes and interfaces
  • Final is used to describe the final attribute, indicating that a class cannot derive a subclass, or that a member method cannot be overridden, or that the value of a member field cannot be changed to define a constant
  • Finally, which is used to handle exception cases, to declare a block of statements that are essentially bound to be executed
  • One of the float base data types, single-precision floating-point number types
  • For a guide word for a looping structure
  • GOTO reserved keyword, no specific meaning
  • The guide word of the IF condition statement
  • Implements indicates that a class implements the given interface
  • Import indicates that you want to access the specified class or package
  • Instanceof used to test whether an object is an instance object of a specified type
  • One of the int basic data types, integer type
  • Interface interface
  • Long integer type one of the basic data types
  • Native is used to declare that a method is implemented by a computer-related language (such as the C/c++/fortran language).
  • New to create an instance object
  • Package Packages
  • Private access Control method: Private mode
  • Protected an Access control method: Protection mode
  • Public an access control method: Common mode
  • Return the data from the member method
  • Short, one of the basic data types
  • Static property is indicated by
  • STRICTFP used to declare fp_strict (single-precision or double-precision floating-point number) expressions following the IEEE 754 arithmetic specification
  • Super indicates the reference to the parent type of the current object or the constructor of the parent type
  • The guide word for the Switch branch statement structure
  • Synchronized indicates that a piece of code needs to be executed synchronously
  • This refers to a reference to the current instance object
  • Throw throws an exception
  • Throws declares all exceptions that need to be thrown in the currently defined member method
  • Transient declaring a member domain without serialization
  • Try a block that might throw an exception
  • Void declares that the current member method does not return a value
  • Volatile indicates that two or more variables must be changed in a synchronized manner
  • While is used in the loop structure

Basic types in Java
    • Integer: Can be subdivided into short (2 bytes), int (4 bytes), Long (8 bytes)
    • BYTE: Byte, if used to represent an integer, a byte can represent an integer of -128~127
    • Floating point number: Mainly used to store fractional values, can be divided into float (4 bytes) and double (8 bytes)
    • Characters: char, kanji, English characters are double-byte, java character encoding is Unicode
    • Logical Type: Boolean
Type conversions

Type many times the compilation does not pass, it may be that these details are not noticed. In Java, the variable type is very strict, in the case of unspecified, the integer is generally int type, the decimal is the default double type, if you do not pay particular attention to these are easy to err, for example: float PI = 3.14,3.14 default to double type, you can not assign a double type of decimal to float type, this will lose precision, compile error.

Input and output data input basic type data

Scanner is a new class that SDK1.5 adds, but uses this class to create an object.
Scanner reader=new Scanner (system.in);
The reader object then calls the following methods (functions) to read the various data types that the user entered at the command line:

next.Byte(),nextDouble(),nextFloat,nextInt(),nextLine(),nextLong(),nextShot() 

 

The above method will cause a blockage when executing, waiting for the user to enter the data return confirmation at the command line. For example, the value of 12.34,hasnextfloat () that advocates on keyboard input is true, and the value of Hasnextint () is false. Nextline () waits for the user to enter a line of text and enter, which gets a string type of data.

Output Basic type data

System.out.println () and System.out.print ()
You can enter the value of a string value, an expression, the difference is that the former output data after the line, the latter does not break the line. Allows you to use the collocated symbol + to output a variable, an expression, or a constant value with a string.
Format Control characters:

    • %d: output int type data
    • %c: Output Char type data
    • %f: Output floating-point type data with a decimal point of up to 6 digits.
    • %s: output String type data.
    • %MD: Output int type data in M column
    • %M.NF: Output floating-point type data is in M-column and the decimal point remains n-bit.

      Operator
    • The characteristic of,&& in the logical operator is that if the left of && is false, the logical judgment of the return result is false regardless of the right truth.
      The Same, | | is characterized by the fact that if | | On the left is true, the logical judgment of the return result is true regardless of the right truth. This, to a certain extent, can improve the efficiency of code compilation and execution.
    • In the increment, decrement operator, it is important to note whether the operator is placed on the left or right side of the variable, if the operator is on the left side of the variable, then the variable value is changed before the operation, if the operator is to the right of the variable, then the first operation and then the corresponding addition and subtraction of the variable.

      Statement

      If...else Conditional type

      It is important to note that the executed statement is enclosed in curly braces, otherwise, the default is to only execute the first sentence after if.

Switch conditional type

switch有点像多个分支的if语句,但在某些情况下,用switch可以提高代码的效率,书本上也有相应的例子,不用进入每个if语句去判断,可以通过待判断的值直接进入相应的case,只是注意switch一般都会配以break一起使用,编写代码时不能忘记这一点。

While loop

当型循环:while(条件式){描述句},先判断条件式的布尔类型,如果成立,则执行描述句。直到型循环:do{描述句}while(条件式);,特点是先执行一遍描述句,再判断条件,如果条件成立就再执行一遍描述句,直到条件不成立为止。需要注意的是:while的两种类型的区别,在写法上,注意当型while后没有分号,第二种有分号。break continuebreak:结束当前循环。continue: 跳过当前循环一次。break、continue还可以和标签一起配套使用。break与标签配套时,则结束该标签包含的所有语句;continue与标签配套时,则跳过该标签包含的所有语句。
Problems in teaching materials learning and the solving process

On println print printf the difference with

    • print--is a function that returns a value that can have only one argument, displays its arguments in the command window, and positions the output cursor after the last character displayed.

    • The only difference between println--and print is the println output, which displays its parameters in the command window and adds a newline character at the end, positioning the output cursor at the beginning of the next line.
    • printf--function, the text format after the output, the direct call system calls for IO, he is non-buffered.

Code Hosting

Sentiment

The most important thing to learn a program language is more practice, first of all, even if you do not understand the code, can only look at other people's code to play, see more gradually will understand, at least understand the basic framework of the language, how to start, how to describe, what is the routine. After that, the program will be able to fully understand the meaning of the code.

Learning progress Bar
Code lines (new/cumulative) Blog volume (new/cumulative) Learning Time (new/cumulative) important growth
Goal 5000 rows 30 Articles 400 hours
First week 200/200 1/4 10/10
Second week 300/500 1/5 10/20
Third week
Week Four
    • Planned study time: 10 hours

    • Actual learning time: 10 hours

    • Improved situation:

Take a look at the Java Practice Tutorial Learning Video

Resources
    • Java Learning Notes (8th Edition)

    • Java Learning Note (8th Edition) Learning Guide
    • The difference between print, println, and printf

20165231 2017-2018-2 "Java Programming" 2nd Week study Summary

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.