"53" keywords in Java (with 2 reserved words)

Source: Internet
Author: User
Tags error handling finally block modifier throw exception java keywords

How many 1.java keywords (keyword) are there?

51+2 a reserved word = 53 Keywords (java keywords are lowercase!!) )

What is the reserved word for 2.java (reserve word)? Question: What are the differences?

2 reserved words

Reserved words in the Java language refer to reserved keywords

1). Const Youdao Interpretation: N. Constants, constants

The declaration used to modify a field or local variable. It specifies that the value of a field or local variable is constant and cannot be modified

2). Goto Youdao Interpretation: VI. Go to

Specifies to jump to the label, and when the label is found, the program processes the command starting from the next line.

What are the 3.java keywords, and what are the functions?

1). Access modifier Keywords (3 total)

Key words

Mean

Notes, Common

Public

Public-owned

Available across packages (default selection)

Protected

The protected

Available in the current package

Private

Privately owned

Current class available

2). Define classes, interfaces, abstract classes and implement interfaces, inherit class keywords, instantiate objects (total 6)

Key words

Mean

Notes, Common

Class

Class

public Class A () {} curly braces have the implemented method body, the class name needs to be the same as the file name

Interface

Interface

public interface B () {} curly braces have the method body, but no implementation, the method body sentence is followed by the English semicolon ":" End

Abstract

Declaring abstractions

Public abstract class C () {} is between the class and the interface, either with or without an implemented method body

Implements

Realize

For class or interface implementation interface public class A interface B () {}

Extends

Inherited

Used for class-inheriting classes public class A extends D () {}

New

Create a new object

A a=new a (); A denotes a class

3). Package keywords (total 2)

Key words

Mean

Notes, Common

Import

Introduction of the Package keyword

When using some classes of a package, you can automatically insert the package containing the class name by pressing CTRL + click with Ctrl+shift+o or the selected class name (class or property or method). such as: JFrame shortcut key after automatically join

Import Javax.swing.JFrame;

Package

Define the keywords for the package

Put all the related classes in a package class to find modifications and so on. such as: Package javake.flycat.draw002;

4). Data type of keywords (12 total)

Key words

Mean

Notes, Common

Byte

BYTE type

8bit

Char

Character type

16bit

Boolean

Boolean type

--

Short

Short-integer

16bit

Int

Integral type

32bit

Float

Floating point Type

32bit

Long

Long integer type

64bit

Double

Double precision

64bit

void

No return

public void A () {} Other required returns are often used with return

Null

Null value

True

Really

False

False

5). Condition cycle (flow control) (Total 12)

Key words

Mean

Notes, Common

If

If

if () {} What about curly braces in parentheses?

Else

Otherwise, or

Often used with if, same usage

While

When what is the time

While what do you do what while () {}

For

When three conditions are met

for (;;) {}

Switch

Switch

switch (expression)
{
case constant Expression 1: statement 1;
....
Case constant Expression 2: statement 2;
Default: statement;
}
Default is to execute a case without a match, and default is not required.
The statement after the case can be used without curly braces.
The decision condition of the switch statement can accept Int,byte,char,short and cannot accept other types.

Case

Returns the result in the switch

Default

Default

Do

Run

Long And while

Break

Jump out of the loop

Continue

Go on

Interrupt this cycle and start the next time

Return

Return

Return a value type

instanceof

Instance

A two-dollar operator, and ==,>,< is the same class. Tests whether the object on its left is an instance of the class to the right of it, and returns a Boolean type of data

6). Modifying methods, classes, properties, and variables (9 total)

Key words

Mean

Notes, Common

Static

of static

Both properties and methods can be decorated with static, using the class name directly. Property and method name.   Only inner classes can use the static keyword decoration, which calls directly using the class name. The inner class name is called. Static can exist independently. Static block

Final

The final non-change

Both methods and classes can be decorated with final

Final-Modified classes cannot be inherited

The final modification method is not overridden by a quilt class.

Definitions of constants:

The final decorated property is a constant.

Super

Calling a method of the parent class

Common public void Paint (Graphics g) {

Super.paint (g); · }

This

The object of the parent class of the current class

Invokes a method in the current class (representing the object that called the method)

This.addactionlistener (AL): Wait a minute.

Native

Local

Strictfp

Rigorous, precise

Synchronized

threads, synchronizing

Transient

Short

Volatile

Easy to lose

static Example:

public class test{

Class a{}//Inner class

ActionListener al=new ActionListener (...) {}//anonymous inner class

}

Static blocks take precedence over the execution of other methods/classes

7). Error handling (total of 5)

Key words

Mean

Notes, Common

Catch

Handling Exceptions

1.try+catch
The procedure is run into a try block, and if an exception is thrown, go to the catch block to process it. Then execute the statement after the catch block

2.try+catch+finally
The procedure is run into a try block, if an exception is thrown, go to the catch block, after the catch block executes, execute the code of the finally block, and then execute the code after the finally block.
If no exception is thrown, execute the try block and execute the code of the finally block. Then execute the statement after the finally block

3.try+finally
The procedure is run into the try block, and if an exception is thrown, the program turns to the code that executes the finally block. Will the code behind the finally block be executed? No! Because you did not handle the exception, after you have encountered an exception, the method exits with the exception that was thrown after the finally execution.
It is important to note that because you do not catch an exception, you declare the throw exception after the method

(Information from the Internet)

Try

Catching exceptions

Finally

There are no exceptions to be executed

Throw

Throws an Exception object

Some of the factors that can cause problems with the program, such as writing errors, logic errors, or API application errors, and so on. In order to prevent the program from crashing, it is necessary to detect these factors beforehand, so Java uses the mechanism of exception.

Exceptions in Java are used by "throw", or "throw" in English, which means "throw" the error message if something is found to be abnormal.

Throws

Declares that an exception may be thrown

Give the exception to his superiors and manage it without exception handling.

Throw is the action you perform. For example, if you think there may be an abnormality, then take it out like this:

String A; if (a = = null),

Throw new Exception ("A is null");

So throw is a throw-away action

Throws is used only at the end of a method, which means that if there is an exception inside the method body, this throws it to its caller. such as: public void Add (int a, int b) throws Exception (); This method indicates that, when executing this method, an exception may be generated, and if an exception is generated, then whoever calls this method will throw it to the person. (from Baidu)

8). I don't know what it is (Total 2)

Key words

Mean

Notes, Common

Enum

enumeration, enumerating types

Assert

Assertion

Enum: Represents a set of common constants that can be used to represent a class of constant values of the same type, such as:

Gender:

public enum Sexenum {

male, female;

}

Color:

public enum Color {

RED, Blue,green,black;

}

The values inside the enumeration object must be unique.

Attachment: The difference between throw and throws

Difference One:

Throw is a statement that throws an exception; throws is a method that throws an exception;

Throw syntax: Throw < exception object >

In a method declaration, adding a throws clause indicates that the method throws an exception.

Throws syntax:[< modifier >]< return value type >< method name > ([< parameter list;]) [throws< exception class;]

Where: The exception class can declare multiple, separated by commas.

Difference Two:

Throws can be used alone, but throw cannot;

Difference Three:

The throw is either used with the try-catch-finally statement or used with the throws. However, throws can be used alone and then caught by the method that handles the exception.

Throws E1,e2,e3 just tells the program that this method might throw these exceptions, and the caller of the method might want to handle the exceptions. And these abnormal e1,e2,e3 may be produced by the function body.

And the throw is clear where this exception is to be thrown.

void DoA () throws Exception1, Exception3 {

try {

......

} catch (Exception1 e) {

Throw e;

} catch (Exception2 e) {

SYSTEM.OUT.PRINTLN ("error");

}

if (A! = b)

throw new Exception3 ("Custom Exception");

}

Code block ... may produce abnormal Exception1, Exception2, and Exception3.

If a Exception1 exception is generated, it is captured and then thrown by the caller of the method to do the processing;

If the Exception2 exception is generated, the method does its own processing (printing out the wrong name), so the method does not throw out the Exception2 exception, void DoA () throws Exception1, Excpetion3 inside of the Exception2 also do not have to write;

The Exception3 exception is an error in the logic of the method, the programmer has to handle the logic error in the case of throwing an exception Exception3, the caller also needs to handle.

The throw statement is used in the body of the method to indicate that an exception is thrown and handled by the statement in the method body

The throws statement is used after the method declaration to indicate that the exception is thrown, and is handled by the statement in the previous-level method that called the method

Throws primarily declares that this method throws this type of exception so that other places call it when it knows to catch the exception.

Throw is a specific action that throws an exception, so it is throwing an exception instance.

throws indicate which of you might be inclined to

Throw it, that's where you turn that tendency into reality.

While

1) The throws appears in the method function head, and the throw appears in the function body;

2) throws represents the possibility of an exception, which does not necessarily occur; throw throws an exception, and execution throws must throw some exception;

3) Both are negative ways of handling exceptions (the negativity here is not to say that this is not a good idea), just throw or possibly throw an exception, but not by the function to handle the exception, and the real handling exception is handled by the upper call of the function.

52756452

"53" keywords in Java (with 2 reserved words)

Related Article

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.