201871010118- Tang Jingbo "object-oriented programming (Java)" the second week of learning summary

Bowen beginning of the text format: (3 points)

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

1. adapt the teacher teaching, learning can be completed this week, according to independent study theoretical knowledge requirements;

2. Master Java Application Program Structure;

3. Master and variable data types Java language;

4. Java operators learn to use various types of expressions configuration;

The input and output control Java Application Technology;

6. grasp the Java process control technology (branch, loop); (Key)

7. grasp Math class, String class usage. (difficulty)

Essay Bowen body content include:

Part I: similarities and differences between Java and C combined with relatively basic grammar summarizes theoretical knowledge (30 points) this week

 1, the identifier:

 C available identifier number, uppercase and lowercase letters, underline, not begin with a number;

Java available identifiers besides the 3 C's, one more with a dollar sign ($), the same can not start with a number.

 2, Keywords:

C keywords have: auto break case char const continue default do double else and so on;

There are Java keywords: abstract boolean break byte case catch char class continue and so on;   

 3, the data type:

Data type in C are:

1) Basic Type: Integer (basic integer int, short int short [int] Long and long [int] signed and type [signed], unsigned unsigned), char [signed / unsigned] char , float (single-precision float, double, double, and long double long double), enumerated type

2) structure types: an array type, type of structure, union type

3) pointer type

4) Air Type

Note that the various types of ships Number of Bytes:

int: 2 bytes

short: 2 bytes

long: 4 bytes

char: 1 byte

float: 4 bytes

double: 8 bytes

Java data types:

1) Basic type: char (char), number (integer (byte byte, short integer short, int int, long integer long), float (single-precision float, double double )), Boolean (boolean (true or false))

2) complex type: class, interface, array

Note that the various types of storage Number of Bytes:

byte: 1 byte

short: 2 bytes

int: 4 bytes

long: 8 bytes

char: 2 bytes (Unicode encoded)

float: 4 bytes

double: 8 bytes

 4, constants and variables

1) Constant

Same integer constants defined in Java and C, in addition to long data in its outer end by l or L, other types of values ​​are displayed directly. C, thereafter adding the unsigned constants u or U. For different binary, decimal digit can not directly show the highest 0, octal begin with 0, hexadecimal begin with 0x or 0X.

For floating-point type, C and Java are only using decimal notation. And using decimal exponent, e exponent notation separated by a decimal or between and E index. Note that the Java single precision required to add f or F, after double D to add or d to show distinction.

Character constants are in single quotation marks or escape a single character string representation. Special attention, C represents only the ASCII code for character of Unicode characters from 0 to 255, Java byte in the storage unit 2 may represent special characters, indication when unicode encoding \ u plus four hexadecimal string.

Boolean type only in Java only, need special attention.

Java keyword final modification of the constants, once the assignment can not be changed; C keywords can not be said change is const, it modifies variables (note that the variable, not a constant) must be defined at the time of initial value, while a #define macro constants have no type.

2) variable

Java and C define substantially the same variables, namely:

Variable name Data type [Initial value = variable];

Variable initial value can not be assigned, but Java long integer and floating-point number to add the corresponding identification flag (e.g., l, f).

Special Note: Due to the different compilers, C declare variables to be placed before the executable statements, otherwise compile errors may occur.

 5, logical operators and bitwise operators

C in both Java and logical operators &&, || ,! Three kinds of meaning and the same, except that the result is 0 C in operation and non-0, Java can only be ture or false. Java exist also &, |, ^ (XOR), and & &&, | and || difference is that the former and the latter non-shortcut operator is a shortcut operator, i.e., & done both before and after judgment, the former is not false && behind the judge, | do both before and after judgment, not behind former || true judgment. ^ Represents both the same to be false.

In both Java and C bitwise operators are: &, |, ^, ~ (negation), << (shift left), >> (shift right), substantially the same meaning. A right shift operation in view of the negative C differ in different systems (which may also be a logical shift right arithmetic shift right), while in Java >> represents the arithmetic right shift, i.e., the sign bit MSB filled. Java logical shift right (unsigned right shift) >>> operator is using the right complement, add high 0.

6, array

C array definition is as follows:

Type specifier array name [constant expressions];

Initialization may be performed simultaneously with the definition, such as: int a [10] = {0,1,2,3,4,5,6,7,8,9}; constants in the square brackets may be omitted.

Java array is defined in two ways:

Data type array name []; or data type [] array name;

Definition and initialization can be performed simultaneously, such as: int [] a = {0,1,2,3,4,5,6,7,8,9};

Note that if the array in Java is not initialized when defined, during the initialization of the need to allocate memory, namely:

= New array name Data type [Constant Expressions];

Memory allocation may be performed simultaneously in the definition:

Data type array name [] = new data type [Constant Expressions];

C and Java do not support variable-length arrays, array name references all the time [index]. The difference is: Java subscript range of 0 to the array length - 1, not in the array subscript range will be thrown out of bounds exception, the effective range is 0 ~ C array length - 1, but beyond this boundary subscript without error.

Multi-dimensional array, the array elements are arranged in rows.

Another point to note: C defined in the array are not initialized the array element value is unpredictable, but in Java allocates memory array is not initialized with a default value.

 7, classes, fields, methods and global variables, functions

 1) Class C is not in, Java classes are defined as follows:

 [Modifier] class class name [extends parent class name] [the implements interface name]

Where modifier can be one or more of the following access modifiers:

 abstract: an abstract class.

 final: The final class.

 public: public class.

 2) Domain (member variables) and global variables analogy:

 Java domain is defined as follows:

 [Modifiers] type member variable name;

 Optional modifier one or more keywords:

 public: public members.

 protected: This class or other classes and subclasses of the class of other packages of the same package can be accessed.

 private: private members.

 final: constant, can not be changed after OK.

 static: Static variables.

 transient: Temporary variables.

 volatile: backup variables.

 Various types of member variables initialized by default:

Integer variable: 0

Float variable: 0.0

Boolean variables: false

Character variables: space

Class variables: null

C global variables defined in the same general variables:

[Storage Class] Column Data Type variable table;

Optional storage class in which:

auto: automatic variables, when the storage class is not affirm the implicit default value.

static: Static variables.

register: register variables.

extern: external variables.

3) methods and functions analogy:

The method defined in Java follows:

[Modifier] return type method name ([parameters listed])

Alternatively one or more of the following modifiers:

public: public methods.

protected: This class or other classes and subclasses of the class of other packages of the same package can be accessed.

private: private methods.

abstract: an abstract method, only the first method is no method body.

static: static methods.

Optional storage class:

extern: external function.

static: static function.

Part II: Experimental part

Experiment name: Experiment two basic Java programming (1)

1. Purpose:

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

(2) master the process of importing Java source code under the Eclipse integrated development environment;

(3) Data structure of the Java language type master basic programs, variables, operators, various types of expression, the input and output, the basic syntax of flow control;

(4) master the use of the Math class, String class, StringBuilder class.

3. Experimental procedure and content:

Experiment 1 peer review procedure (10 minutes)

By peer assessment program found that students are not particularly clear on the program structure and syntax of the application, after also need to continue to work hard.

Experiment 2 (5 minutes)

java applications written contains the following code fragment, the value of the output string class object s3.

code show as below

package first1;

public class first1 {
public static void main(String[] args){
String s1="Hellow!";
String s2="World";
String s3=s1+s2;
System.out.println(s3);
}
}

Results are as follows

 

 

Experiment 3 (5 minutes)

Change Experiment 2 s1, s2, s3 for the StringBuilder class object observation result of the program and 2 with the experimental results, and to understand the differences String class object StringBuilder class object.

code show as below

package first1;

public class Welcome {

public static void main(String[] args) {
// TODO Auto-generated method stub
StringBuilder s1=new StringBuilder("Hello!");
StringBuilder s2=new StringBuilder("World");
StringBuilder builder=new StringBuilder();
builder.append(s1);
builder.append(s2);
System.out.println(builder);

}

}

Results are as follows

 

 

 

Experiment 4 (5 minutes)

The following commissioning procedures at the command line, understanding the use of java application command line arguments.

code show as below:

package project1;
 
public  class  Message {
 
     public  static  void  main(String[] args) {
         if  (args[0]. equals ( "-h" )) System. out .print(  "Hello" );
         else  if (args[0]. equals "-g" )) System. out .print( "goodbye," );
       for ( int  i=1;i<args.length;i++)
         System. out .print( " " +args[i]);
       System. out .println( "!" );
     }
 
}

Run as follows:

Experiment 5 to import Java (5 minutes)

Chapter 3 sample introduction step procedure InputTest.java Eclipse environment:

(1) New java project

2) Select File-> import-> File ystem-> Next, open the File Import window below, click on Browse to select the top import source, select it, click on Browse to select the lower import source location for the new project InputTest / src location, click finish to complete the import.

 

 

3) Open the default package InputTest project src folder, double-click to open the file in InputTest.java IDE source code editing area.

(4) Right-click the file name InputTest.java open the shortcut menu, select Run as-> java application to run the program, run in conjunction with the results of the program, understand the code Scanner class object usage, master java console input method.

 

 

Experiment 6 Test file write program (10 minutes)

5 following the experimental procedure introduced WriteReadFileTest.java example, run the program and understand the program code, project folder observed myfile.txt file contents, the file input and output control operation.

 

 

2) myfile.txt follows

Experiment 7 (5 minutes)

5 following the experimental procedure introduced Chapter 33-3--3-4 sample program, the use of two master program loop control structure

Examples 3-3

 

Examples 3-4

 

Experiment 8 (5 minutes)

: 5 following the experimental procedure are introduced, Chapter 33-5 example program, lottery probability calculation algorithm appreciated

 

 The program used to calculate the equation n * (n-1) * (n-2) * ... * (n-k + 1) / (1 * 2 * 3 ... * k).

4. Experimental Summary: (10 minutes)

  The main contents of this week is to compare similarities and differences between the C language and Java language, but also the foundation of our learning Java content, because there is no science to understand when learning C language, so when feeling a little difficult to learn Java,

But by the video courseware and learning platform Mooc teacher, understanding the content of this section, there are many examples in textbooks, through case analysis and comparison of each section to learn about the different variables for each

Use, especially when running different results in the application of two different experimental loop in seven, so I know the importance of rigorous language program.

  During the experiment, getting to know and be familiar with some of the basic methods of the String class and StringBulider class. Through this study, I found understanding identifiers in Java is very important, in addition, I know more grammar, although still only basis, but I will continue to work hard to learn, after learning constantly improve their programming Level.

Guess you like

Origin www.cnblogs.com/2360689227t/p/11494496.html