Object-oriented Programming (Java) The second week of learning summary

Source: Internet
Author: User
Tags mathematical functions

Object-oriented Programming (Java) The second week of learning summary

Wang Yingchi 201771010129

The first part: Purpose and requirements of the experiment

some purposes and requirements of ① theory

(1) 3.1 Basic knowledge (2) 3.2 data type (3) 3.3 variable (4) 3.4 operator (5) 3.5 type conversion

(6) 3.6 character type (7) 3.7 Input/output (8) 3.8 Control Flow (9) 3.9 Large value (10) 3.10 Array

② The purpose and requirements of the experimental part

(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) Master the Java Language constructs the basic program data type , the variable , the operator, each kind of expression, the input output, the flow control the basic grammar;

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

Part II: Theoretical knowledge, Experimental content and procedures

Theoretical knowledge:

3.1 Basic knowledge

identifiers :

A, identifiers consist of letters, underscores, dollar signs, and numbers, and the first symbol cannot be a number.

B, The following are legal identifiers:

Hello, $1234, program name, www_123

C, the identifier can be used as: class name, variable name, method name, array name, file name, and so on.

Keywords:

A is a specific word that has been given a specific meaning in the Java language

B, The common are : class,public,try,catch,if,float,import,void.

C, keyword does not do variable name

Comments:

Three ways to annotate Java:

1.//
The comment content is from //Until the end of this line.
2./* and */
Defines a comment block.
3./** Start, */End
This annotation method can be used to automatically generate documents.

3.2 Data types

There are 8 basic types of Java
– Integer type (int, short, Long, byte) – floating-point type (float, double)

– Character type (char) – Boolean type (Boolean)

3.3 Variable

* 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 vacationdays;

–long earthpopulation; –boolean done;

* 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

* after a variable declaration, it must be explicitly initialized with an assignment statement -Never use the value of an uninitialized variable.

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

* in Java, two variables of the same name cannot be declared within the same scope.

Definition of 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.

* in java, you often want a constant to be used in multiple methods within a class , often referred to as class constants. You can declare a class constant (class constants) with the keyword static final.

public static final double cm_per_INCH

3.4 operator

* Precedence and binding of various operator * operators * mathematical functions and constants

3.5 Type Conversions

3.6 String

The *java string is a sequence of Unicode characters that is the organization word descriptors This data structure and is used similar to a character array.

* There is a built-in string type, but a Java pre-defined class string is provided in the standard Java class library. In Java, strings are treated as objects .

* the strings that need to be used in the 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

* Read Input * formatted output * file input and output

3.8 Control Process

3.9 Large values

* if the basic integer and floating-point data do not meet the required precision, then you can use the two classes in the Java.math package, BigInteger and BigDecimal. These two classes can manipulate the number of long-term meanings.

The *biginteger class realizes the integer operation of arbitrary precision, and BIgdecimal realizes the floating-point operation with arbitrary precision.

3.10 Arrays

* An array is a data structure that is a collection of ordered data, The data type of each element in the array is the same.

* The determination of an element is implemented by the array name and its subscript,

such as A[0] represents the first element of array A, a[1] represents the array
The second element of a, and so on.

Experimental section:

Experiment 1: write the Java application and output the values of the following 4 expressions.

int i=1;

Double d=1.0;

(1) 45+45*50%i--

(2) 1.5*3+d++

(3) (true) && (3>4)

(4) (i>0) | | (i<0)

Results:

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;

Results:

Experiment 3: Change Experiment 2 s1,S2,S3 as StringBuilder class object, observe the program running result and experiment 2 results are compared to understand the difference between a string class object and a StringBuilder class object.

Results:

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

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:

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

(1) new Java project such as:

(1) select file->import->general->file system->next, open the File import window such as, click on the above Browse Select Import source program and select, Click Browse below to select the source program import location for the new project inputtest/src location, click Finish to complete the import.

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

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

Results:

Experiment 6 : follow The procedure of Experiment 5, Import Writereadfiletest.java sample program, understand program code with program running result , observe the contents of file MyFile.txt under project folder, Master the input and output operation of the file.

Results:

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 master the loop control structure;

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

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

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

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

Summarize:

through this week's study, I mastered the basics of Java programming , learning about data types, variables, operators, type conversions, character types, input and output, control processes, large values, and arrays. In the lab, I was able to use command line (Dos) more skillfullyto run the program, and enhanced my ability to use the integrated development Platform (Eclipse) to write, import and run programs.

In the specific experimental operation, I realized that the identifiers in the program are very important, if the input errors or in the wrong place, it is likely to cause the program to run an error. In addition, in the experiment, I mastered more grammar, gradually understand some of the meaning of the program, and realize that this is a link with the C language, and other language courses, the very need for self-study courses. Therefore, I will take more time to study the course under the class.

Object-oriented Programming (Java) The second week of learning 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.