Java Common Keywords

Source: Internet
Author: User
Tags error handling finally block volatile

There are currently 53 keywords in Java: a reserved word of 51+2 = 53 keywords

1. Reserved keywords for Java (2)

Const-Constant, constant: a declaration used to modify a field or local variable.

Goto-Go to: Specify to jump to the label, after the label is found, the program will process the command starting from the next line

2. Access modifier keywords (3)

public: Available Across packages

protected (Protected): Available in the current package

Private (private): The current class is available

3. Defining classes, interfaces, abstract classes and implementing interfaces, inheriting class keywords, instantiating objects (6)

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

Interface (interface): public interface B () {} There is a method body in curly braces, but there is no implementation, the method body sentence is followed by an English semicolon; end

Abstract (Declaration abstraction): Public abstract class C () {} is between the class and the interface, either, or it may not have an implemented method body

Implemenst (Implementation): For a class or interface, implement interface public class A interface B () {}

extends (inheritance): for class-Inheriting classes public class A extends D () {}

New (Create new Object): A a=new A (); A denotes a class

4, the package of keywords (2)

Import (Introduction of the Package keyword): When using some classes of a package, only the class name is required, and then use Ctrl+shift+o or the selected class name (class or property or method) Ctrl + Click to automatically insert the package containing the class

Package (Define the package's keywords): Put all related classes in a package class to find modifications, etc.

5, Data type of keywords (12)

byte (byte type): 8bit

Char (byte type): 16bit

Boolean (Boolean type):--

Short (Short integer type): 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 () {} others that need to be reversed are often used with return

NULL (null value)

true Really

false False

6. Condition cycle (flow control) (12)

if (IF): if (conditional statement {Execute code} if the conditional statement is true, start executing {} contents

Else (otherwise, or): Often used with if, the same usage: if (...) {...} Else{...}

while (when): while (conditional statement) {Execute code}

for (when three conditions are met): for (initialize loop variable; judging condition; loop variable Value {}

Switch (Selection structure): switch (expression) {case constant expression 1: statement 1;...case constant expression 2; statement 2;default: statement;}default is the default is not required if there is no match to execute it. The statement after the case can be used without curly braces.

Case (results in the expression matching switch): Ibid.

default (default): Default is to execute it without a matching case, default is not required

Do (running): Long and while

Break (Jump out of the loop): Directly out of the loop, executing the code after the loop body

Continue (continue): Interrupts the cycle and starts the next cycle

return (return): Return a return value type

instanceof (example): A two-dollar operator, and = =, >, < are 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

7. Modifying methods, classes, attributes, and variables (9)

Static (Static): properties and methods can be modified with static, using the class name, property, and method name directly. Only internal classes can use the static keyword adornment, which is called directly using the class name and the inner class name. Static can exist independently

Final (Final Immutable): Methods and classes can be modified by final, final decorated classes cannot be inherited, and final adornments cannot be overridden by subclasses. Definition of constants: Final decorated properties are constants

Super (Method of calling parent Class): Common public void Paint (Graphics g) {super.paint (g); ...}

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

native Local

STRICTFP (Strict, precise)

synchronized (Thread, Sync): Only one thread can be executed in a single time. Another thread must wait for the current thread to execute this block of code before executing the code block

transient Short

volatile (volatile)

8. Error handling (5)

Catch (Handling Exception): (1) The Try+catch program flow is: Run into the try block, if there is an exception thrown, go to the catch block to handle. Then execute the statement after the catch block

(2) The Try+catch+finally program flow is: Run into the try block, if an exception is thrown, then go to catch collapse, 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 program flow is: Run into the try block, if there is an exception thrown, then go to the code of the finally block.

Try (Catch Exception)

finally(no exceptions are performed)

Throw (Throws an Exception object): Some can cause program problems, such as writing errors, logic errors or API application errors, and so on. Weili prevents the program from crashing by detecting these factors in advance, so Java uses the exception mechanism

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 an exception that may be thrown): Give the exception to his superiors and manage it without exception handling.

9. Others (2)

enum (Enumerate, enumerate, type)

assert Assertion

Java Common Keywords

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.