201871010114- Li Yansong "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/11435127.html

Job learning objectives

  1. Teachers adapt teaching methods, to complete the study this week, according to independent study theoretical knowledge requirements;
  2. Master the Java Application Program Structure;
  3. Master and variable data types Java language;
  4. Learn to use Java operator construction of various types of expression;
  5. Java Application control input and output technology;
  6. Master the Java process control technology (branch, loop); (Key)
  7. Math master class, String class usage. (difficulty)

Part I: similarities and differences between Java and C combined with relatively basic grammar, summarizes theoretical knowledge 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 enum extern float for goto

                            if   int    long    register   return  short   signed    sizeof    static   struct  switch   typedef    union    unsigned   void volatile   while

There are Java keywords: abstract boolean break byte case catch char class continue default do double else extends false 

                                final   finally    float    for   if  implements    import   instanceof    int    interface  long   native    new    null   package private  

                              protected    public    return   short   this   throw    throws    transient   true try   static    super    switch   synchronized  void   volatile    while

3. basic types:

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

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, the 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];

7. Calculate byte length

Calculating a C language array directly through the sizeof byte length, if it is the length of the array, the type needs to be divided by a byte length of the byte length of the array
java just inside a property b.length it.
SizeB the sizeof = int (B);
the printf ( "Array B byte length =% d \ n", sizeb );

printf("size of int =%ld\n",sizeof(int));

printf ( "length of the array b D% \ n-", SizeB / the sizeof (int));
8. The string

String, java is affirmed can not be modified, if you want to modify is the StringBuffer
c language, which is operated by the method of string.h

9. 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]

 

{

 

// class body

 

}

 

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])

 

{

 

// method body

 

}

 

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.

 

The definition of a C function as follows:

 

[Storage Class] [data type] function name ([parameter listed])

 

{

 

// function body

 

}

 

Optional storage class:

extern: external function.

 

static: static function.

Part II: Experimental part

Experiment name: Experiment two basic Java programming

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 

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

String s1=“Hello!”;

String s2=“World”;

String s3=s1+s2;

Code:

public class testtt {

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

 

 The results shown in FIG Run:

 

 

Experiment 3: 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:

package hello;

public class test3{

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

operation result:

 

  

Experiment 4: commissioning program in the following command line, understanding the use of java application command line arguments.

{  
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(“!”);
  }
}
命令行运行结果:

 

Experiment 5:

Chapter 3 introduced sample program steps Eclipse environment InputTest.java

(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 position, click finish to finish the import.

 

 

 

(3) to 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.

operation result:

 

 

Experiment 6 file reading and writing program testing

) Introduction WriteReadFileTest.java examples:

 2) derived myfile.txt

 

 实验7 照实验5的操作步骤,导入第3章3-3——3-4示例程序,掌握两个程序循环控制结构的用途

3-3

 

 

 

3-4

 

 

实验8 

按照实验5的操作步骤,导入第3章3-5示例程序,理解抽奖概率计算算法。

 

 

 

4. 实验总结:通过本周的学习,我掌握了以下java程序设计的基本知识,

(1)学习了数据类型,变量,运算符,类型转换,字符类型,输入输出,Math类,string类,了解了Java的最基本的的语法知识

(2)强化了自己使用集成开发平台(eclipse)来编写,导入以及运行程序的能力,结合c语言的语法与java语法的区别有了对于Java语言更深的理解。

(3)在实验中,我掌握了更多的语法,逐渐看懂了一些程序的含义因此,在mooc学习中了解了Java的基础知识,需要大量的编程练习才能熟悉的掌握这门语言

(4)在本周随堂考试中发现自身的循环结构以及java中类的概念理解还是不够熟悉,以后需要加深这些方面的学习,及时补上,理解到自学在这门课程的重要性

Guess you like

Origin www.cnblogs.com/liyansong0198/p/11483634.html