201871010117- Shi Yan Yu "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. To learn and master the Java Application Program Structure;
  2. Learn and master data types and variables Java language;
  3. Learn to use Java operator construction of various types of expression;
  4. Java Application control input and output technology;
  5. Master the Java process control technology (branch, loop);
  6. Math master class, String class usage

Part I: similarities and differences between Java and C combined with relatively basic grammar, summarizes this week theoretical knowledge (fonts are marked in red and different Java language section c, but also pay special attention to the red word part)

1. Basics

1.1 Identifier

(A) identified by a letter, underscore, dollar sign configuration and numbers, and the first symbol is not a number.

  (B) identifier may be used:

Class name, object name, variable names, method names, data name, file name, etc.

1.2 Keyword

(A) are some of the key words in the Java language has been given a specific meaning.

(B) common in Java keywords are: class , public , the try , the catch , IF, float, Import , void and so on.

Note: The keyword is not a variable name

1.3 Notes

   a) // // footnotes have been made to this end of the line.

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

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

2 Data Type

   a) Java before use of each variable must declare the variable type

   b) the type of data that is divided into four types: integer type (int, Short, Long, byte ) floating-point type (float, double) character type (char) boolean ( boolean )

 

   c) It is worth mentioning that, Java is not the type of coding language used in ANSI C code, but Unicode code . Unicode (Unicode, Unicode) is a coding standard that meet the cross-language, cross-platform text conversion processing requirements.

Note: in Java does not have unsigned types ;

 

    e) Boolean type

Constants true, false;

Integer and Boolean values ​​can not be converted to each other in Java.

3.1 Variable

   a) In Java, each of the variables belonging to one type. When you declare a variable, the variable type belongs to precede the variable name.

   b) his party can declare multiple variables, but not recommended. Individually declare each variable can improve the readability of the program.

Note: After a variable declaration must be explicitly initialized by assignment of its ----- Never use an uninitialized variable values;

       Declare variables as close as possible to use local variables for the first time, which is a good programming style.

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

3.2 Constant

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

   b) Keyword final means that only the variable assigned a value, its value once set, it can not be changed. 

   c) In Java, 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).

4. Operators

   a) Java, the various operators are related to the object-oriented

   b) Java provides two special operators

      -  new new This is an operator used to create objects. 

      -  instanceof returns a Boolean value that indicates whether an object is an instance of a particular class or its subclasses.

   c) operator precedence and associativity

 

 

 

 d) a mathematical function contained in the Math class. Power function; trigonometric functions; exponential function and its inverse function, etc., Java also provides two constants: Math.PI Math.E

 5. Type Conversion

(A) conversion of syntax type mandatory:

       (Target type) variable name

 

   Two operands (b) there is a double type, the other will be converted into double type;

     has 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 to type int.

6. string

    a) In Java, the string is treated as an object. 

    b) the need to use a program strings can be divided into two categories:

        After you create will not do modifications and variations of immutable string class String

        After allowed to do to create change and build a string StringBuilder class changes

    c) using the "" is defined string

    d) Java will automatically generate a constant string of the object class String , String object can be initialized directly.

 

7. O

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

    b) Use of System.out.print (x) outputs the value of x to the console, the command data corresponding to the type of x will be the maximum allowable non-zero digits x printout.

8. The control flow

Control statements (the program control flow is determined by these control statements)

a)if、switch、for、while、do-while

b) Package Penalty for statement and import statements

9. large numerical

    a) If the basic integer and floating point data type can not achieve the required accuracy, may be used java.math package two classes, a BigInteger and BigDecimal.

    b) these two classes can be operated for any length of digital

       BigInteger class implements arbitrary-precision integer arithmetic

       BigDecimal realized the arbitrary-precision floating-point operations

10. Array

(1) An array is a data structure that is an ordered set of data,

      The data type of each element in the array are the same.

Statement (2) of the array

a) one-dimensional array format:

Array element type array name [];

Array element type [] array name; // recommended

 

b) two-dimensional array format:

Array array element type name [] [];

Array element type [] [] array name; // recommended

d) wherein the data type can be any type java, including basic and complex types.

e) can also be used to declare an array of defined classes;

Point[] line;

f) java in the array declaration does not allocate memory for the array, in java, arrays are separate classes, have their own way.

Creating (3) of the array

After the array is declared, the new operator to use its allocated memory space, the length of the array must be specified when allocating memory.

Format is as follows:

Array = new array element type name [number]

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 and step

Experiment 1 peer review procedure

        Found a lot of our own problems in the peer review program, where the biggest problem is that we do not understand the basic framework java program, we should pay more attention to grasp the basic knowledge.

Experiment 2 : The following code fragment comprising write java application, the output string class object value of s3.

String s1=“Hello!”;

String s2=“World”;

String s3=s1+s2;

The results are shown running

 

 

Experiment 3: Experiment 2 Change S1 , S2 , S3 as StringBuilder class object is observed with the experimental result of the program and comparing the results 2, understood String class object distinction StringBuilder class object.

 

 

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

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

  }

}

Results are as follows in FIG.

 

 

 

Experiment . 5: the Eclipse introduction of ambient Chapter 3 InputTest.java sample program steps:

(1)  New java project below:

 

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

 

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

(4)  Right-click InputTest.java the file name to open the context 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.

Results are as follows in FIG.

 

 

 

Experiment 6 : following the experimental 5 steps, introducing WriteReadFileTest.java example, run the program and understand the program code , Observation myfile.txt file folder contents of the master file input and output operations.

Results are as follows in FIG.

 

 

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

The first procedure was as follows

 

 The second program was as follows

 

 

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

Results are as follows

 

 Application of the for-loop of the formula n * (n-1) * (n-2) * ... * (n-k + 1) / (1 * 2 * 3 * ... * k).

4. Experimental summary

  The third chapter we mainly learn the basics of Java syntax, most of which c and similar language, so it reduces our learning curve. In this chapter of the study, I learned all kinds of expressions using the Java operator constructed, learned to import Java files, learned to string class, by explanation and online learning resources of the classroom teacher, I can learn more Know how.

       By this week's study, I better understand the importance of the experiment, and the teacher gave us a lot of examples, let us better understand the program, understand the basic procedure should be how to write, but also deepened the impression by their own hands, such a learning mode I feel very good, as well as seniors as a teaching assistant, which greatly helped us to learn.

 

Guess you like

Origin www.cnblogs.com/sxy19991214/p/11493378.html