Basic concepts of Java programs

Source: Internet
Author: User
Tags integer numbers

Hello, everyone, here to explain the basic concept of Java program application.

The following are some of the following:

I. Definition of identifiers

II. Division of data types

III. Application of Operators

Iv. application of branching structure, cyclic structure and cyclic control grammar

The application of defining structure and method overloading

The following will begin to explain the five aspects of understanding

  First, the application of identifiers

Java notes : There are three comments in total, namely://single-line comment/**/Multiline comment/****...../document comment

In Java programming, the most critical application is the application of annotations, in the actual development cooperation, for each programmer to write the module, need a little comment to be able to use. Another point in the application process of delivery to the customer, the note on the document is more critical, in favor of the customer in the actual work of operation and maintenance work, improve the reading performance of the program.

  identifiers and keywords. where the identifier is: there are letters, numbers, underscores _, $ composition, which cannot start with a number, not a keyword in Java (some languages also become reserved words);

Here are a few more things to look out for:

1, in the actual process of writing, try not to use the numbers.

2, the name as far as possible, do not use the more simple naming, such as: A, B and so on.

3, the Java program strictly distinguish the case.

4, for "$" is a special significance, do not use

Key words are:

Abstract \ Assert \boolean\ break \ byte \ case \ catch \ char \ class \ continue \ const \ default \ Do \ Double \ else \ extends \ enum \ final \ finally \ float \ for

Goto \ If \ implements \ import \ instanceof \ int \ interface \ long \ native \ new \ package \ Private \ protected \ public \ return \ short \ static \ Synchronized

Super \ STRICTFP \ This \ throw \ transient \ try \ Void \ volatile \ While

The above is the most basic Java program keywords, in the subsequent learning process, slowly, will be exposed to a variety of different usages.

 II. Classification of data types

Different data types can hold different data content. is the actual development process, we need to according to different data length and type of different storage options, to a certain extent, to help program operation and memory occupancy rate is low.

The following are the most basic data types:

Short \ int \ long \ byte \ char \ float \ double \ Boolean

These are the most basic types that need to remember the length of each type and the relative corresponding application scenario. I will use the following application to do the most basic introduction

  1. Integral type

byte short int long

The above four types are represented as integers. The following is the basic int Application Type

public class int{

public static void Main (string[] args) {

Setting content for a variable uses the following format: Data type variable name = constant;

int num = 10;

int result = num * 2;

System.out.println ("");

}

}

In another case, a long data type needs to be converted to a short data type, where the pattern used is forced type conversion.

public class qiangzhizhuanghuan{

public static void Main (string[] args) {

Long num = 1000;

int x = (int) num;

SYSTEM.OUT.PRINTLN (x);

}

}

A forced type conversion avoids a certain amount of data overflow problems. However, although the program supports coercion of type conversions, the problem of whether the data will overflow is still to be considered when casting a large range of data types to a small range of data types.

  The contents of a variable can be modified, and the contents of the constant are not modifiable.

Explanation: The difference between the two is that the content of the constant is fixed, and the contents of the variable can be changed. A variable is a declarative way to keep each memory block in memory for use by the program. Objects that can be declared have integer, character, float, or other data types that are used as variables for saving.

  2. Floating point number

Floating-point numbers are decimals, where the default is a double-type data. (Double is the most widely held data type)

Because the double type is used by default, a double type is required for a strongly typed conversion when using the float type. There are two ways of using the letter "F" or "F" and declaring it with float before the variable or constant.

  3, Character type

Byte, char type, and so on.

The most critical of the character type is the number of characters in the Chinese type.

  4. Boolean type

As a logical type, which is reserved for two types of true, false type.

  5. String type

String as a string: A collection of multiple characters, a string that requires the use of double quotation marks "" to declare its contents.

  

  Third, operator

  

  

Iv. Circulation and judgment

Sequential structure: The program is executed on the next line, followed by the execution of the next statement, until the end of the program.

Select a structure: depending on whether the condition is set up or not, decide which statements to execute

Branching structure: branch structure in order to increase the logical structure of the selection.

If, If....else, if....else if ... else this 3 structure is complete.

Loop structure

While loop

It is divided into two while and do....while applications.

For loop

Maximum benefit is the number of clear loops

Loop control

Two types of control data are applied, including: Continue and break two application data.

v. Methods

Encapsulation can execute a piece of code, not only can be repeated calls, more convenient to implement code maintenance.

Overloading of methods: means that the method name is the same, the type or number of arguments is different, the call will be followed by the type of arguments passed and the number of different method body execution.

The following is an example of an application for method overloading:

Public class Testdemo {

Public Static void Main (String args[]) {

Method overloads call different method bodies depending on the type or number of arguments passed in after the statement is executed

System. out. println ("Two integer parameters:" + Add(10, 20));

System. out. println ("Three integer parameters:" + Add(10, 20, 30));

System. out. println ("Two floating-point parameters:" + Add(10.2, 20.3));

}

/**

* Implement an addition calculation operation for two integer numbers

* @param x operation number One

* @param y operation Digit Two

* @return The addition calculation results of two integer data

*/

Public Static int Add (int x, int y) {//Add () method is overloaded three times altogether

return x + y;

}

/**

* Implementation of an addition calculation operation for three integer numbers

* @param x operation number One

* @param y operation Digit Two

* @param z operation number Three

* @return The addition calculation results of three integer data

*/

Public Static int Add (int x, int y, int z) {//is not the same as the number of arguments to the previous add () method

return x + y + z;

}

/**

* Implement an addition calculation operation for two decimals

* @param x operation number One

* @param y operation Digit Two

* @return Two decimal numbers for addition calculation results

*/

Public Static double Add (double x, double y) {//is not the same as the parameter type of the previous add () method

return x + y;

}

}

Basic concepts of Java programs

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.