201871010111- Liu Jiahua "object-oriented programming (java)" the second week of learning summary

201871010111- Liu Jiahua "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://edu.cnblogs.com/campus/xbsf/2018CST1/homework/4519>

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

3.1 Basics

Identifier:

A, identified by letters, underline, dollar signs and numbers, and the first symbol is not a number.

B, these are all valid identifiers:

Hello, $ 1234, the program name, www_123

C, an identifier may be used: a class name, variable name, a method name, array name, file name, etc.

Key words:

A, is the java language specific word has been given a specific meaning

B, common are: class, public, try, catch, if, float, import, void and so on.

C, variable names do keyword

Comment:

Java annotations in three ways:

1. //
Notes // contents have been made to this end of the line.
2. / * and * /
define a comment block.
3. / ** start, * / end
this annotation method can be used to automatically generate documentation.

3.2 Data Types

There are eight basic types of Java
- integer types (int, short, long, byte ) - floating-point type (float, double)

- character type (char) - boolean (boolean)

3.3 Variable

* In Java, every variable belonging to one type. When you declare a variable, the variable type belongs to precede the variable name.

– double salary;           – int vacationDays;

– long earthPopulation;  – boolean done;

* In Java, a line can declare multiple variables. Individually declare each variable can improve the readability of the program.

– int i,j;//both are integers

Variable initialization

* After a variable declaration must be explicitly initialized by assignment to it - Never use an uninitialized variable's value.

* In Java, you can declare a variable anywhere in the code. Declare variables should be as close as possible to the local variable is first used, easy to read and use.

* In Java, you can not declare a variable within the same scope of two of the same name.

Defining constants

* In Java, use the keyword final to indicate constants. Traditionally constant names are capitalized.

final double CM_PER_INCH=2.54;

* Keyword final representation can only assign a value to a variable, its value once set, can not follow the code and then modify it.

* In Java, often want a constant can be used in multiple methods in a class, these constants are usually called class constants. You can use the keyword static final declare a class constants (class constants).

public static final double CM_PER_INCH

3.4 Operators

* Various operators: and related object-oriented computing

  • new - it is used to create an object operator.
  • Instanceof - returns a Boolean value that indicates whether an object is an instance of a particular class or its subclasses. 

* Operator precedence and associativity 

* Mathematical functions and constants

  • Mathematical functions included in the Math class.

- power function, trigonometric, exponential, and other inverse function and so on.

  • 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", you can add the following code at the top of the source file: -impot static java.lang.Math *;.

3.5 Type Conversion

3.6 String

* 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.

* A built-in string type, but provides a Java String predefined classes in the standard Java class library. In Java, strings are treated as objects to deal with.

* Strings need to use the program can be divided into two categories:

  •  After you create will not do modifications and variations of immutable string String class;
  •  It does allow modifications and variations to build a string StringBuilder class after creation.

3.7 Input Output

* Read input 

* Formatted output 

* File Input and Output

3.8 Control Process

3.9 Large value

* If the basic integer and floating point data type can not achieve the required accuracy, then the package may be used java.math two classes, a BigInteger and BigDecimal. These two classes may operate any longer intended number.

* BigInteger class implements arbitrary-precision integer arithmetic, B igDecimal 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.

* Identify the elements is achieved by the array name and an index to it, and

As a [0] a first element of the array represents, a [. 1] array representing
the second element a, and so on.

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)掌握Eclipse集成开发环境下导入Java源程序的过程;

(3)掌握Java语言构造基本程序的数据类型、变量、运算符、各类表达式、输入输出、流程控制的基本语法;

(4)掌握Math类、String类、StringBuilder类的用法。

2. 实验步骤与内容:

实验1 程序互评

  评分要求:结合评分程序的运行情况,给出评分程序成绩,满分5分,每个错误扣1分,扣至0分为止;

评分者每发现一个正确的错误,本人实验1得分加1分,最高加5分。

实验2:编写包含以下代码片段的java应用程序,输出字符串类对象s3的值。

String s1=“Hello!”;

String s2=“World”;

String s3=s1+s2;

 

 

 

代码如下:

package MyProject;

public class Week2SX2 {

    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); } }

 

 运行结果如下:

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

 代码如下:

package MyProject;

public class Week2SX3 {
    public static void main(String[] args) 
{ StringBuilder s1
=new StringBuilder("Hello!"); StringBuilder s2=new StringBuilder("world"); StringBuilder s3=new StringBuilder(); s3.append(s1); //append 字符拼接 s3.append(s2); System.out.println(s3); } }

 

 运行结果如下:

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

 

package MyProject;

        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("!");
          }
        
    }

 

 运行截图如下:

实验5Eclipse环境下导入第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的内容,掌握文件的输入输出操作。

 

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

3-3示例程序运行结果:

3-4示例程序运行结果:

 

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

第三部分:实验总结

  通过上周对基础理论的学习以及对eclipse运用的初步掌握,在此次实验过程中,在程序的书写和格式上出错率比上次明显少了很多。此次实验

进一步熟悉命令行和IDE两种方式下java程序开发的基本步骤,学习了如何向eclipse导入其他文件夹中的程序,掌握Java语言构造基本程序的数据类型、变量、

运算符、各类表达式、输入输出、流程控制的基本语法。

       在实验过程中,逐渐了解并熟悉了String类和StringBulider类的一些基本方法。通过本次学习,我发现了在Java中认识标识符很重要,另外,我掌握了更多的语法,虽然都还只是基础,但我会继续努力学习,在以后的学习中不断提高自己的编程水平。

 

Guess you like

Origin www.cnblogs.com/JerryLau-213/p/11479736.html