201777010217- Jinyun Xin "object-oriented programming (Java)" the second week of learning summary

project content
This work belongs courses https://www.cnblogs.com/nwnu-daizh/
Where this requirement in the job https://www.cnblogs.com/nwnu-daizh/p/11475377.html
Job learning objectives
  • To learn and master the Java Application Program Structure;
  • Learn and master data types and variables Java language;
  • Learn to use Java operator construction of various types of expression;
  • Java Application control input and output technology;
  • Master the Java process control technology (branch, loop);
  • Math master class, String class usage

Part I: similarities and differences between Java and C combined with relatively basic grammar, summarizes theoretical knowledge this week  

3.1 Basics

3.1.1 Identifier

Identifier 0 identified by letters, underscores, dollar signs and numbers, and the first symbol is not a number. Identifier may be used: class name, object name, variable name, a method name, array name, file name, etc.

3.1.2 Keyword

Keyword is Java some words in the language has been given a specific meaning. Common are: class , public , the try , the catch , IF , float , Import , void and so on. Keyword is not a variable name.

3.1.3 Notes

n // comments by the contents // have been the end of this line.

n-/ * and * / define a comment block.

n / ** start * / End Note this method can be used to automatically generate the document.

3.2 Data Types

integer ( int, Short, Long byte )

floating point type ( a float , Double )

character type ( char ) 

Boolean type ( Boolean )

3.3 Variables and Constants

3.3.1 Variables

The variable name must be a letter or a number composed by beginning with the letter sequence, all the characters in the variables are meaningful, and case-sensitive, then declare a variable, the variable assignment statement must explicitly initialized. In java does not distinguish between declarations and defined variables.

Note: After a variable declaration must be explicitly initialized by assignment to it - Never use an uninitialized variable values ; the Java can not in the same scope to declare two variables of the same name.

3.3.2 Constant

In Java , use the keyword final to indicate constants. General constant names are capitalized. Such as: Final Double CM_PER_INCH = 2.54 ; 

keyword final representation can only assign a value to a variable, its value once set, it can not be changed. 

In Java , the often want a constant multiple methods can be used in a class, we called these constants class constants. You can use the keyword static final declaration of a class constants ( class Constants ).

3.4 Operators

3.4.1 conditions operators

It includes arithmetic operators, and operator increment decrement operators, relational operators, Logical and Bitwise operators.

3.4.2 Java provides special operators

New operators and Instenceof , the former operator used to create objects, or to return a Boolean value that indicates whether an object is an instance of a particular class or its subclasses.

3.4.3 operator precedence and associativity

3.4.4 mathematical functions and constants

Mathematical function contained in the Math class, there is provided a power function , trigonometric , exponential, and its inverse function like.

3.4.5 Java also provides two constants

——Math.PI, Math.E.

3.5 Type Conversion

3.5.1 cast syntax

 ( Target type) variable name

3.5.2 Conversion principle

Two operands is a double type, the other will be converted into double type ;

Two operands is a float type, the other will be converted into float type ;

Two operands is a long type, the other will be converted into long type ;

Otherwise, both operands are converted into int type.

 

 

3.6 String

n Java string are Unicode sequence of characters, which is the basic data structure of the organization of the character, similar to the use of an array of characters. There are built-in string type, standard Java provides a library of Java predefined class String . In Java , the string is treated as objects to deal with.

strings need to use the program can be divided into two categories: modifications and variations do not immutable string after creating the String class; do allow modifications and variations to build a string after you create StringBuilder class.

string constants : Use "" defined string. Java automatically generates a string of constant String object class, it can be initialized directly String object.

3.7 Input Output

When the input through the console, a need to construct Scanner object and the " standard input stream " the System.in association.

use of System.out.print (x) the value of x is output to the console, the command will be x corresponding to the type of data allowed maximum non- 0 digits printout x .

3.8 Control Process

in {} enclose some statements constitute a statement.

control statement (program control flow is determined by these languages) IF , Switch , for , the while , do the while-

3.9 Large value

If the basic data of the integer and floating point type can not achieve the required accuracy, may be used java.math package two classes, a BigInteger and the BigDecimal . These two classes can be operated for any length of digital  BigInteger class implements arbitrary-precision integer arithmetic ,  the BigDecimal achieve arbitrary-precision floating-point arithmetic .

3.10 Array

array is a data structure that is an ordered set of data, the data type of each element of the array is the same. 

Array Declaration  

One-dimensional array format:       array element type array name []; array element type []   array name;     // recommended            

Two-dimensional array format:       array element type array name [] []; array element type [] []    array name;     // recommended          

Wherein the data type can be a java any type, including basic and complex types , it can also be used to declare an array of defined classes;

Create an array after array declaration, use the new operator to assign memory space, you must specify the length of the array when allocating memory space. Name Array = new  array element type [ number ] .    

 

Part II: Experimental part

Experiment name: Experiment two Java basic programming ( 1 )

1.  Purpose:

( 1 ) become more familiar with the command line and IDE two modes java basic steps of the program development;

( 2 ) master the Eclipse import under integrated development environment for Java process source code;

( 3 ) grasp the Java data types of the program basic language constructs, variables, operators, various types of expression, the input and output, the basic syntax of flow control;

( 4 ) master the Math class, String class, the StringBuilder usage class.

3. Experimental procedure and content:

Experiment a peer review procedure

Experimental results are shown two runs:

Third experiment result of the program as shown:

Experiment 4 program run results shown in Figure:

Guess you like

Origin www.cnblogs.com/1377x/p/11494502.html