(5) Java Fundamentals-Methods, keywords, naming conventions, annotations

Source: Internet
Author: User

First, the method

Method is equivalent to the implementation of a function.

Public  int           max    (int NUM1 , int num2 \ n". "

modifier      return type    Method name   method (parameter can have N) method body

  Modifier: The modifier is optional and tells the compiler how to call the method. This defines the type of access for the method.

Static: Class method, which can be called directly from the class name

  Return type: The method can return a value. The value of Returnvaluetype is the data type returned by the method. Some methods do not return a value to perform the desired action. In this case, returnvaluetype is the keyword void.

  Method Name: This is the actual name of the method. The method name and the parameter list together form the method signature.

  Parameter: The parameter is like a placeholder. When calling a method, pass a value to the parameter. This value is called the actual parameter or parameter. A parameter list refers to the number of parameters of a type, order, and method. Parameters are optional, that is, a method can contain any parameters.

  Method Body: The method Body contains a collection of which method statements are defined.

Second, the key word

Keywords: words that have special meanings in Java.

Constants and variables cannot have the same name as a keyword when they are named . Each keyword has its own special use

Key words Meaning
Abstract Indicates that the class or Member method has an abstract property
Assert Used for program debugging
Boolean One of the basic data types, Boolean type
Break Jump out of a block early
Byte One of the basic data types, byte type
Case Used in a switch statement to represent one of the branches
Catch Used in exception handling to catch exceptions
Char One of the basic data types, character types
Class Class
Const Reserved keywords, no specific meaning
Continue Back to the beginning of a block
Default Default, for example, in a switch statement, indicating that a default branch
Do Used in the DO-WHILE loop structure
Double One of the basic data types, double-precision floating-point number types
Else Used in a conditional statement to indicate a branch when the condition is not true
Enum Enumeration
Extends Indicates that one type is a subtype of another type, where the common types have classes and interfaces
Final Used to describe the final attribute, indicating that a class cannot derive a subclass, or that a member method cannot be overridden, or that the value of a member field cannot be changed
Finally Used to handle exception cases, to declare a block of statements that are essentially bound to be executed
Float One of the basic data types, single-precision floating-point number types
For A guide word for a cyclic structure
Goto Reserved keywords, no specific meaning
If Guide Words for conditional statements
Implements Indicates that a class implements the given interface
Import Indicates that you want to access the specified class or package
instanceof Used to test whether an object is an instance object of a specified type
Int One of the basic data types, integer type
Interface Interface
Long One of the basic data types, long integer type
Native Used to declare a method that is implemented by a computer-related language (such as the C/c++/fortran language)
New Used to create a new instance object
Package Package
Private An access control method: Private mode
Protected An access control method: Protection mode
Public An access control method: Common mode
Return Returning data from member methods
Short One of the basic data types, the short integer type
Static Indicates a static property
Strictfp Used to declare fp_strict (single-precision or double-precision floating-point number) expressions that follow the IEEE 754 arithmetic specification
Super Indicates a reference to the parent type of the current object or a constructor for the parent type
Switch Guide words for Branching statement structures
Synchronized Indicates that a piece of code needs to be executed synchronously
This Reference to the current instance object
Throw Throws an exception
Throws Declares all exceptions that need to be thrown in the currently defined member method
Transient Declaring a member domain without serialization
Try Try a block that might throw an exception
void Declares that the current member method does not return a value
Volatile Indicates that two or more variables must be changed in a synchronized manner
While

Used in the loop structure

Third, naming rules

1. Class and interface name. The first letter of each word is capitalized and is case-sensitive.

For example, Myclass,helloworld,time and so on.

2. Method name. The first character is lowercase, the remainder is capitalized, and is case-sensitive. Use as little underline as possible.

For example, Myname,settime and so on. This naming method is called Camel-named.

3. Constant name. The constant name of the base data type uses all uppercase letters, and the words are separated by underscores. Object constants can be mixed in size. for example, Size_name. 4. Variable name. Can be mixed in uppercase and lowercase, the first character is lower case, and the word delimiter is capitalized with the first letter of the word. Don't underline, use the dollar sign less. The name of the variable is to do as far as possible to see the meaning.   Iv. NotesThere are three main ways to annotate Java1//Comment line2/* ... * * Comment several lines3/**......*/Documentation Comments

(5) Java Fundamentals-Methods, keywords, naming conventions, annotations

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.