201871010128- Yang Lixia "object-oriented programming (java)" the second week of learning summary

201871010128- Yang Lixia "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. 1. adapt the teacher teaching, learning can be completed this week, according to independent study theoretical knowledge requirements;
  2. 2. Master Java Application Program Structure;
  3. 3. Master Java data types and variables of the language;
  4. 4 Learn to use Java operator construction of various types of expression;
  5. The master Java Application input-output technology;
  6. 6. grasp the Java process control technology (branch, loop); (Key)
  7. 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 this week

The basic program structure design of Java Chapter III

3.1 Basics

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

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

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

(2 ) the keyword is Java language in some of the words have been given a specific meaning.

Common have: class, public, the try, the catch, IF, float, Import, void and so on.

Keyword is not a variable name. 

(3) Java annotations in three ways:

 //    comments by the contents // this line has been completed.

/ * And * /    define a comment block.

 / * Start * / end comment this method can be used to automatically generate documentation.

3.2 Data Types

There are eight basic types of Java  

- integer type (int, short, long, byte)

- floating-point type (float, double)

- character type (char)

- boolean (boolean)

Integer constants said: Decimal: 123, octal 6000: 077, 065

Hex: 0x234, 0Xab12 binary: 0b1001,0B0111

Data type integer variables into four: int byte Long Short

Machine-independent Java integers in the range and run Java code. Java is not the type unsigned

For int variables, memory allocation, 4-byte, 32-bit representing the range -231 ~ 231-1.

For short variables, memory allocation, 2 bytes, 16-bit representing the range -215 ~ 215-1.

For long variables, memory allocation, 8 bytes, 64-bit representing the range -263 ~ 263-1.

For byte variables, memory allocation 1-byte, 8 bits, in the range -27 ~ 27-1

3.3 variables

in Java, each belonging to one type variable. When you declare a variable, the variable type belongs to precede variables. 

salary Double; 

int vacationDays; 

Long earthPopulation; 

boolean DONE; 

in Java, and his party can declare multiple variables. Individually declare each variable can improve the readability of the program. 

Variable initialization

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

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

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

Defining constants

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

final double CM_PER_INCH=2.54;

(2 ) Keyword final indicates only assign a value to a variable, its value is set once, the subsequent code can not be modified.

(3 ) In Java, it 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

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

(1) implicit type conversions
most numeric conversion relationship is to follow the priority automatically.  
Transformation of the following:  
If the two operands is a double type, the other will be converted into double. 
Otherwise, if either operand is a float type, the other will be converted into float type. 
Otherwise, if either operand is a long type, will be converted into another type long. 
Otherwise, both operands are converted into int type
( 2) cast
mandatory type conversion syntax:  
(target type) variable name  
should be forced upon the type of conversion, beware of losing data.  

Example . 1: Double X = 9.987; 

int NX = (int) X; // converted nx = 9 

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. There are 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.

Programs need to use the string can be divided into two categories:

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

Create a permit to do the modifications and variations of the building after a string StringBuilder class.

3.7 Input Output

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

    ( 2 ) Use of System.out.print (x) the value of x is output to the console, the command will be x corresponding to the type of data allowed maximum non- 0 digits printout x .

3.8 Control Process

Control statements

ifswitchforwhiledo-while

Package statement and import statements

3.9 Large value

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

 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

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

( 2 statement) Array

One-dimensional array format:

Array element type    array name [];

Array element type []  array name;  

 Two-dimensional array format:

Array element type    array name [] [];

Array element type [] []   array name; 

Wherein the data type can be a java any type, including basic and complex types.

Class may also be defined to declare an array;

Point[] line;

f) java in the array declaration does not allocate memory for the array in java , the array is a separate class, with its own approach.

( 3 create) an array

After the array is declared, use the new operator assigned memory space, the length of the array must be specified when allocating memory. After the array of numbers created, all array elements automatically initialized to 0; boolean create an array after the array elements are initialized to false;. Array of objects is initialized to null after array creation can not change the size.

( Operation 4) of the array

Copies the array
array sort

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)

Peer assessment program this session by marking of student programs, to identify problems, and reflect the same problems if they exist, know the meaning of each line of code represents, pay attention to the program's error-prone points, so our overall framework and content of the program have a deeper understanding.

Experiment 2 the preparation contains the following code fragment java application, the output string class object value of s3. (5 points)

String s1=“Hello!”;

String s2=“World”;

String s3=s1+s2;

 operation result

 

 

Experiment 3 Change Experiment 2 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 (5 minutes)

 

 

Experiment 4 commissioning program in the following command line, understanding java application usage command-line arguments. (5 points)

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

  }

}

 operation result

 

 

 

Experiment 5 to import Java (5 minutes)

(1) New java project below:

 

 

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

 

 

myfile.txt reads as follows:

 

 

 

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

3-3 run results

 

 

3-4 run results

 

 

Experiment 8 5 following the experimental procedure of introducing the sample program Chapter 33-5, understood lottery probability calculation algorithm. (5 points)
Example 3-5

 

 

4. Experimental Summary: (10 minutes)
 This week study, the contacting step to the java command line and IDE two ways java program development, introducing the java source Eclispe integrated development environment, the basic data types java program language constructs, variables, operators, various types of expression, input and output, String class, use the StringBuilder class, in the course of the experiment will not read a lot of programs, some steps up there are still many difficulties, but is a gradual and learning process, to continue in ignorance to know, continue to accumulate experience, and gradually improve. It should also be more to their own learning and thinking, learn to find information related to the video is a good example mooc learning resources should be fully utilized. 

Guess you like

Origin www.cnblogs.com/ylxzjh/p/11489261.html