Dara Grass 201771010105 "Object-oriented Programming (Java)" Second week study summary

Source: Internet
Author: User
Tags float double

Dara Grass 201771010105"Object-oriented programming (java)" The second week of learning summary

Part one of theoretical knowledge learning

This week we are studying the third chapter of Java's basic program design structure, in this chapter we mainly learn about Java basic knowledge, data types, variables, operators, type conversions, strings, input and output, control flow, large values, and arrays.

1. Basic knowledge includes identifiers, keywords, and annotations.

Identifiers: Identifiers consist of letters, underscores, dollar signs, and numbers, and the first symbol cannot be a number. Identifiers can be used as class names, variable names, array names, file names, and so on.

Keywords: keywords are some words in the Java language that have been given a specific meaning, the keyword does not do variable names.

Note: Java is made up of three types of annotations: (1)//The comment 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 documents.

2. The data type has integer type, floating-point type, character type, and Boolean type of four.

(1) The data type of integer variable is divided into four kinds: int short long byte

For the int variant, the memory is allocated 4 bytes, which is 32 bits, and the value range is -231~231-1.

For short variables, memory is allocated 2 bytes, which accounts for 16 bits, and the range of values is -215~215-1.

For long variables, memory is allocated 8 bytes, which accounts for 64 bits, and the range of values is -263~263-1.

For byte variables, memory is allocated 1 bytes, 8 bits, and the range of values is -27~27-1.

(2) There are two kinds of floating-point types in Java: float double

For float type variable memory allocation 4 bytes, accounting for 32 bits.

For a double variable memory allocation of 8 bytes, accounting for 64 bits.

(3) Character type: the definition is assignable at the same time, Java uses the Unicode character encoding set, the encoding set 16 bits.

(4) Boolean type: The definition can be assigned at the same time, in Java, Boolean values and integers cannot be converted to each other.

3. Variables: Each variable in Java belongs to a type. When declaring a variable, the type that the variable belongs to is in front of the variable name. In Java, a row of variables can declare multiple variables. Once a variable is declared, it must be explicitly initialized with an assignment statement.

4. Operator: Includes arithmetic operator, increment operator and decrement operator, relational operator, logical operator, bitwise operator.

5. Type conversions: Implicit type conversions and forced type conversions.

6. String: Use "" to define the string. Java automatically generates a string class of objects for the strings constants, so you can initialize the string object directly.

To create an object of string and initialize it, you need to call the constructor of the class string, mainly with the following creative methods: ①string (): Create an empty string ②string (string value) ③string (char value[]) ④string (Char[],intstartindex,intnumchars) ⑤string (byte[],byte hibyte) ⑥string (Byte[],byte hibyte,intstartidnex,int NumChars).
The basic operation of the String class: (1) The substring of the string (2) string connection (+) (3) to get the length of the strings (4) to detect whether the string is correct ⑤ string to retrieve the ⑥ string and the conversion of the value (7) Gets the string representation of the object.

7. Input and output: Read input (when the console is input, a scanner object needs to be constructed and associated with the "standard input stream" system.in.) The formatted output uses System.out.print (x) to output the value x to the console, which prints out x the maximum number of non-0 digits allowed by the data type that corresponds to X. File input and output, in order to read the file, it is necessary to construct a scanner object with the Files object.

second, the experimental part

Experiment Two Java Basic Program Design ( 1 )

Experimental Time 2018-9-6

1 , experimental purposes and requirements

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

2 , experimental content and procedures

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)

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 the string class object and the StringBuilder class object.

Experiment 4: command-line mode down test run the following program 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 ("!");

}

}

Lab 5: In the Eclipse Environment, import the 3rd chapter of the sample program Inputtest,java steps:

(1) New Java project such as:

(2) Select File->import->file ystem->next, open the File import window such as, click on the above browse select Import source program and select, click on the below browse to select 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 Iputtest Project Src folder, and double-click Inputtest.java to open the file in the IDE's source program editing area.

(4) Right-click on 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, master the Java console input method.

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

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;

Test Retirement.java                                                                                                    Test Retirement2.java Test Lotteryodds.java

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

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

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

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

3. Experiment Summary:

This time we are doing the Java Basic Program design experiment, first through the teacher's explanation and our study, we basically mastered the Java language constructs the basic program data type, the variable, the operator, each kind of expression, the input output and the control flow basic syntax, Further familiarity with the basic steps of Java program development in two ways, command line and IDE. And through this experiment, we mastered the process of importing Java source programs into the Eclipse integrated development environment. But for the use of large array classes, multidimensional array classes, and so on, I do not quite understand, but I will be in my spare time to read as much as possible to learn. I think that we can pass the experiment to the teacher in the lecture of the content, understand more thoroughly, we master the knowledge of the textbook has a great help.

Dara Grass 201771010105 "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.