201871010135 Zhang Yujing "object-oriented programming (java)" the second week of learning summary

      201871010135 Zhang Yujing "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

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

        2. grasp the Java Application Program Structure;

        3. Master and variable data types Java language;

        4. learn to use various types of expressions configured Java operator;

        The master Java Application input-output technology;

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

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

 

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

    A basic knowledge

    1. The identifier of letters, underline, dollar sign and numbers, and the symbol is not the first digital

The following are legal identifiers: Hello, $ 1234, the program name, www_123

Identifier may be used: class name, object name, variable name, a method name, array name, file name, etc.

   No dollar signs in the C language, while in JAVA.

  2. The keyword is a keyword in the Java language some words have 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 comments

There are three Java annotations ways:

     1) by the contents // // comment this line has been completed.

     2) / * and * / define a comment block.

    3) / ** start, end with * / comment this method can be used to automatically generate documentation.
 II. Data Types

    Java is a strongly typed language. This means that each variable must declare one for the type.

    There are eight basic types of Java

     Integer type (int, Short, Long, byte )

     floating-point type (float, double)

     character type (char) boolean (boolean)

    


    1. Integer constants, said:

        Decimal: 123, 6000

        octal: 077, 065

        Hex: 0x234, 0Xab12

         binary: 0b1001,0B0111

    data type integer variables divided into four categories:

         int byte Long Short 


     Machine-independent Java integers in the range and run Java code.   Java is no unsigned types.


    For int variables, memory allocation, 4-byte, 32-bit representing the range - (2 ^ 31) - (2 ^ 31) -1.

    For short variables, memory allocation, 2 bytes, 16-bit representing the range - (2 ^ 15) to (2 ^ 15) -1.

    For long variables, memory allocation, 8 bytes, 64-bit representing the range - (2 ^ 63) - (2 ^ 63) -1.

    For byte variables, memory allocation 1-byte, 8 bits, the range - (2 ^ 7) to (2 ^ 7) -1.

 2 floating point type

There are two Java floating-point types: float double

floating-point constants, said: decimal 430.2
                                 scientific notation 4.302E2

indicate overflow and three special floating-point constants errors:

 --Double.POSITIVE_INFINITY positive infinity
 negative infinity --Double.NEGATIVE_INFINITY
 NaN (not a number) - Double.NaN

For a float 4 bytes variable memory allocation, representing 32-bit
memory allocation for variable double type 8 bytes occupy 64 bits.

3. Character

char c='a';

4 Boolean

Constants true, false

While assignment is defined
   boolean x = true, y = false ;

In Java, integer and Boolean values ​​can not be converted to each other.

5. Variables

In Java, every variable belonging to one type. When you declare a variable, the variable type belongs to precede the variable name. In Java, you can not declare a variable within the same scope of two of the same name.

 Variable initialization: After a variable declaration, it must be explicitly initialized by assignment - Never use an uninitialized variable value.

 6. Constant

 Defining constants: In Java, use the keyword final to indicate constants. Traditionally constant names are capitalized. Keyword final representation can only assign a value to a variable, its value once set, it can not be changed.
          final double CM_PER_INCH = 2.54;
 in Java, is often desirable in a constant using a plurality of methods in a class, generally referred to as class constants these constants. You can use the keyword static final constants declare a class (class constants).
        public static final double CM_PER_INCH = 2.54;           

7. Operators   

  1.    new new This is an operator for creating an object.

         Instanceof returns a Boolean value that indicates whether an object is an instance of a particular class or its subclasses.           
 2. Priority

 

 8. mathematical functions and constants

Mathematical functions included in the Math class. Power function, trigonometric, exponential function and its inverse function such as

Java also provides two constants. Math.PI, Math.E

if we are not in front of a mathematical method name and constant name prefix "Math.", Can add the following code to the top of the source file.
import static java.lang.Math *.;

III. Type Conversion

1. implicit type conversion is to follow most of the numeric conversion priority relationship automatically.

 2. cast

four. String

1) Java string is a sequence of Unicode characters, which is the basic character of the data structure of the organization, similar to the use of an array of characters.
2) built-in string type, it provides a Java String class predefined in a standard Java class library. In Java, strings are treated as objects to deal with.
3) the need to use the string program can be divided into two categories:
do not do modifications and changes after 4) create an immutable string String class ;
after 5) allows to do to create change and build a string of changes StringBuilder class.

 1 System.String categories: (1) obtaining substrings (2) connected to a string (3) obtaining a length of string class String length () returns the length of a string. Whether the string (4) is equal to the detection string (5) retrieval string (6) into a digital numerical value string (7) to obtain the object representation   

 2.String class and API documentation
   String Class 50 includes a plurality of string processing method of various types;

    Use JDK API documentation can be found online all the standard class and its methods.

V. O

 1. Input input through the console, a Scanner need to construct the object, and associated with the "standard input stream" System.in. Scanner in = new Scanner (System.in);

 2. Use of System.out.print output (x) outputs the value of x to the console.

 3. file input and output
   in order to file for reading, you need to construct a Scanner objects with a File object. For example: Scanner in = new new Scanner (new new File ( "myfile.txt"));
   To write to a file, you need to construct a PrintWriter object in the constructor, simply provide the file name: PrintWriter out = new PrintWriter ( " myfile.txt ");
   the PrintWriter the PrintWriter new new OUT = (" myfile.txt ");

VI. Process Control

Java There are five statements:

1) method call statement    System.out.println ( "the Hello!");    2) expression statement 3) compound statement 4) control statement 5) packege import statements statements and

 

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.

2. Experimental content with the steps:

Experiment 1 peer review procedure

Through this peer assessment, I would have been very familiar with the multiplication table of the code, and also mastered. In the peer review process, the students from the mistakes I have made in more attention to these details, then I will be a lot of attention.

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

  

 

 1) Experimental code is as follows:

 

 

 

 

2) The results are as follows:

 

实验3: 更改实验2中s1s2s3为StringBuilder类对象,观察程序运行结果并与实验2结果进行对比,理解String类对象与StringBuilder类对象的区别。

1)程序代码如下:

 

 2)程序运行结果如下

 

 实验4:在命令行方式下调试运行下列程序,理解java应用程序命令行参数的用法。

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(“!”);

  }

}

 运行结果如下:

 

 

实验5:Eclipse环境下导入第3章示例程序InputTest.java步骤:

(1) 新建java project如下图

 

                            

 

 

 

(2) 选择File->import->File ystem->Next,打开文件导入窗口如下图,点击上方Browse选择导入源程序并选中,点击下方Browse选择源程序导入位置为新项目InputTest/src位置后,点击finish完成导入。

                                      

 

(3) 打开InputTest项目src文件夹的缺省包,双击InputTest.javaIDE源程序编辑区打开文件。

(4) 右键单击InputTest.java文件名打开快捷菜单,选择Run as->java application运行此程序,结合程序运行结果,理解代码中Scanner类对象用法,掌握java控制台输入方法。

                

 

 

实验6:按照实验5操作步骤,导入WriteReadFileTest.java示例程序,运行程序并理解程序代码,观察项目文件夹下文件myfile.txt的内容,掌握文件的输入输出操作。

1)运行结果如下:

                    

 

  

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

1)程序3-3 运行结果

                 

 

 2)程序3-4  运行结果

             

 

 

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

  1)程序3-5运行结果

               

 

 实验总结:

  1)通过本次实验,我进一步熟悉了命令行和IDE两种方式下JAVA程序开发的基本步骤,知道了字符串类的部分用法,理解了String和StringBuilder的区别与联系,知道了如何检测字符串是否相等,字符串的连接,构建字符串,也明白了如何更好的利用使用String,以及如何导入程序。学习了JAVA语言构造基本程序的数据类型,变量,运算符,各类表达式,输入输出,以及流程控制的基本语法。

  2)通过老师和助教的帮助,我解决了很多问题。在接下来的学习过程中我会认真的看待问题,不懂就问,继续努力。

Guess you like

Origin www.cnblogs.com/zyja/p/11487247.html