201771010135 Yang Yongqing "Object-oriented Programming (Java)" Second week study summary

Source: Internet
Author: User

Part I: Theoretical Knowledge learning Section

3.1 identifiers: Consists of letters, underscores, dollar signs, and numbers, and the first symbol cannot be a number and can be used as: class name, variable name, method name, array name, file name, and so on. There are hello,$1234, program name,www_123 and so on.

(2) Keyword: A specific word that has been given a particular meaning in the Java language.

3.2 Note: There are three ways to annotate Java:

(1) // note content is from // until the end of this line.

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

(3) /** Start,* / End This annotation method can be used to automatically generate the document.

3.3 Data type:

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

there are 8 Basic types of Java: integer type (int, short,Long ,byte

floating-point types (Foat, double)

Character Type (char)

Boolean type (Boolean )

data types are divided into four kinds : int short Long byte

The range of integers in Java is independent of the machine running Java code;

there is no unsigned type in Java.

3.4 Variables:

in the in Java , each variable belongs to a type. When declaring a variable , the type to which the variable belongs is before the variable name .

Double salary;

int vacation days;

Long Earth Population;

Boolean done;

in the in Java , a row can declare multiple variables. Declaring each variable individually can improve the readability of the program.

int i,j://both is integers

Initialization of variables:

(1) Once a variable is declared , it must be explicitly initialized with an assignment statement -Never use the value of an uninitialized variable.

(2) in Java , variable declarations can be made anywhere in the code. The declaration of a variable is as close as possible to the place where the variable was first used , which is a good program writing style

(3) in Java , You cannot declare two variables of the same name within the same scope.

Constants: In Java , use the keyword final to indicate constants. The customary constant names are capitalized.

Final double cm_per_inch=2.54;

* Keyword final indicates that a value can only be assigned once, and its value cannot be changed once it is set .

3.5 Operators :

A special operator provided by Java: New, which is an operator used to create an object.

Java Another special operator: instanceof- Returns a Boolean value that indicates whether an object is a specific class or an instance of its subclass.

3.6 String: String: Immutable string

A Java string is a sequence of Unicode characters that is the descriptors of this data structure and is used similar to a character array.

There is a built-in string type, but a Java predefined class stringis provided in the standard Java Class library . In Java , strings are treated as objects .

The strings that need to be used in a program can be divided into two main categories:
– a string class of immutable strings that cannot be modified or changed after creation ;
– Build String StringBuilder class that allows to make changes and changes after creation .

3.7 Input and output:

1. Read input:

when you enter through the console , you need to construct one . The Scanner object , and a is associated with the standard input stream system.in . Scanner in New Scanner (System. in).

The Scanner class is defined in the java.uti package , so it is necessary to load the corresponding package in.

because The Scanner class input is visible , so it does not apply to reading passwords from the console. Java SE6.0 specifically introduces the Console class for this purpose.

2. Format-type output:

Use System.out. Print (x) outputs the value x to the console , This command will be x - The maximum number of non-0 digit digits allowed by the corresponding data type is printed out x.

Java se5.0 Inherits the printf method in the C library function , System.out. printf. .

the formatted output of the date and time in the printf method.

3. File input and output:

to read a file , you need to construct a Scanner object with the files object . For example , Scanner in New Scanner ("MyFile. TXT ")); to write to a file , you need to construct a PrintWriter Object , in the constructor , just provide the file name PrintWriter out new PrintWriter ("MyFile. TXT ");

3.8 Control flow (see experimental process)

3.9 Big Data

Java can be used if basic integer and floating-point data do not meet the required precision . the two classes in the math package , Biginteger and Bigdecimal. These two classes can manipulate arbitrary long numbers.

The Biginteger class realizes the integer operation of arbitrary precision , and Bigdecima realizes the floating-point operation with arbitrary precision.

Part II: Objectives and requirements of the experiment

(1) Further familiar with the basic steps of Java Program Development in command line and IDE two ways ;

(2) Mastering the process of importing Java source program under Eclipse integrated development environment ;

(3) Mastering the basic Grammar of the basic program of Java language construction, such as data type, variables, operators, various expressions, input and output, and process control;

(4) mastering The use of the string class, the StringBuilder class, and the array class

Part III: experimental content and procedures

Lab 1: write a Java application that outputs the values of the following 4 expressions

The results are as follows:

Experiment 2: Write a Java application that contains the following code fragment , outputting the value of the string class object S3.

String s1= "hello!";

String s2= "World";

String s3=s1+s2;

Experiment 3: Change Experiment 2 s1,S2,S3 as StringBuilder class object, observe the program running results and compare with experiment 2 results, Understand the difference between a string class object and a StringBuilder class object.

Experiment 4: Run the following program in command-line mode to understand the use of Java Application command-line parameters.

Lab 5:Import Chapter 3 sample program Inputtest.java steps in Eclipse environment :

(1) new Java project such as:

(2) Select File->import->file ystem->next, open the File Import window like, click on the above browse Select Import source program and select, click Browse below After selecting the source program import location for the new project inputtest/src location, click Finish to complete the import.

(3) open the default package of the Inputtest Project Src folder, and double-click Inputtest.java to open the file in the IDE's source program editing area.

(4) right-click the Inputtest.java file name to open the shortcut menu, choose Run As->java application running the program, in conjunction with the program run results, understand the code Scanner Class object usage, mastering the Java Console input method.

The results are as follows:

Experiment 6 : follow The steps in Experiment 5, import the Writereadfiletest.java sample program, combine the program

The running results understand the program code , observe the contents of the file MyFile.txt under the project folder, and master the input and output operation of the file. The results are as follows:

Experiment 7: Follow the procedure of experiment 5, import the 3rd Chapter sample program, each sample program summarizes the learning content from the syntax and algorithm two angles.

(1) test Retirement.java,retirement2.java,lotteryodds.java to master the cyclic control structure;

(2) test Bigintegertest.java, master the use of large numerical classes;

(3) test Lotterydrawing.java, master the use of arrays;

(4) test Compoundinterest.java, master the use of multidimensional arrays;

(5) test Lotteryarray.java, master the use of irregular arrays.

Part IV: Experimental summary

This experiment is a validation experiment, in the further familiar with the Eclipse function, skilled in the need to import the file software, debugging all the volume, the successful operation of the program to obtain the answer, that is, the Eclipse integrated development Environment Import Java source program process, Further familiar with the command line and the IDE Two ways Java program Development Basic steps, step by step to run the program, until successful, probably mastered the Java language constructs the basic program of data types, variables, operators, all kinds of expressions, input and output, flow control basic grammar, feeling full of harvest, Hope that in the future can be faster and better to fix all Java programs.

201771010135 Yang Yongqing "Object-oriented Programming (Java)" Second week study summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.