[Solved]: org.eclipse.e4.core.di.InjectionException: java.lang.NoClassDefFoundError: javax/annotation/PostConstruct

Problem:

!SESSION 2018-07-30 13:20:28.430 -----------------------------------------------eclipse.buildId=4.7.0-vfinal-2017-09-29T14:34:02Z-Typesafejava.version=9.0.4java.vendor=Oracle CorporationBootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_INFramework arguments: -keyring /Users/admin/.eclipse_keyringCommand-line arguments: -os macosx -ws cocoa -arch x86_64 -keyring /Users/admin/.eclipse_keyring!ENTRY org.eclipse.osgi 4 0 2018-07-30 13:20:41.005!MESSAGE Application error!STACK 1org.eclipse.e4.core.di.InjectionException: java.lang.NoClassDefFoundError: javax/annotation/PostConstructat org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:410)at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:318)at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createDefaultHeadlessContext(E4Application.java:491)at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createDefaultContext(E4Application.java:505)at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:204)at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:614)at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:151)at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.base/java.lang.reflect.Method.invoke(Method.java:564)at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)at org.eclipse.equinox.launcher.Main.run(Main.java:1499)Caused by: java.lang.NoClassDefFoundError: javax/annotation/PostConstructat org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:124)at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:399)... 22 moreCaused by: java.lang.ClassNotFoundException: javax.annotation.PostConstruct cannot be found by org.eclipse.e4.core.di_1.6.100.v20170421-1418at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:433)at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395)at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387)at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)... 24 more!ENTRY org.eclipse.e4.ui.workbench 4 0 2018-07-30 13:20:41.013!MESSAGE FrameworkEvent ERROR!STACK 0java.lang.NoClassDefFoundError: javax/annotation/PreDestroyat org.eclipse.e4.core.internal.di.InjectorImpl.disposed(InjectorImpl.java:450)at org.eclipse.e4.core.internal.di.Requestor.disposed(Requestor.java:156)at org.eclipse.e4.core.internal.contexts.ContextObjectSupplier$ContextInjectionListener.update(ContextObjectSupplier.java:78)at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:111)at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.handleInvalid(TrackableComputationExt.java:74)at org.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:178)at org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.dispose(EclipseContextOSGi.java:99)at org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.bundleChanged(EclipseContextOSGi.java:141)at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:908)at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:213)at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:120)at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:112)at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:168)at org.eclipse.osgi.container.Module.publishEvent(Module.java:476)at org.eclipse.osgi.container.Module.doStop(Module.java:634)at org.eclipse.osgi.container.Module.stop(Module.java:498)at org.eclipse.osgi.container.SystemModule.stop(SystemModule.java:202)at org.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle$EquinoxSystemModule$1.run(EquinoxBundle.java:165)at java.base/java.lang.Thread.run(Thread.java:844)Caused by: java.lang.ClassNotFoundException: javax.annotation.PreDestroy cannot be found by org.eclipse.e4.core.di_1.6.100.v20170421-1418at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:433)at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395)at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387)at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)... 21 more

 

Solution:

You’re using Java 9 so you have to add –add-modules=ALL-SYSTEM to the eclipse.ini as described in https://wiki.eclipse.org/Configure_Eclipse_for_Java_9#eclipse.ini_summary

or you can remove Java 9 and use Java 8. It works fine for me.

How to uninstall Java 9 on macOS Sierra

macOS high sierra removing Java 9:

1. delete the java folder you find in the dir shown to you after executing:

/usr/libexec/java_home -V

The output of the command will be like this

$ /usr/libexec/java_home -VMatching Java Virtual Machines (3):    9.0.4, x86_64: "Java SE 9.0.4" /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home    1.8.0_161, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home    1.8.0_144, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home

use “Go to” in finder and copy and paste the dir to get there:

2. After deleting Java folder output will be something like this:

$ /usr/libexec/java_home -VMatching Java Virtual Machines (2):    1.8.0_161, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home    1.8.0_144, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home

 

Which are the best hill stations near Bangalore?

Choose these mountain(Hill) stations near Bangalore for your next holiday and make sure you have an unforgettable trip. Whether it’s a weekend getaway or a quiet time away from the hustle and bustle of city life, these destinations will bring you plenty of fun and relaxation.

1. Coorg-India Scotland

About 247 km from Bangalore, Coog is one of the best mountain stations in Karnataka. Known as “Kashmir in the South” and “Scotland in India” due to its fascinating scenery and old-world charm, the mountain station has some interesting hiking trips such as Pushpagiri, Tadiandamol and Brahmagiri Peaks, which are very challenging. And has an outstanding natural beauty.

2. Ooty-Mountain Queens Station

About 270 km from Bangalore, Utti has been a popular summer resort since the colonial era. The capital of the Nilgiri district of Ooty attracts a large number of tourists every year because of its towering mountains, vast grasslands, great lakes, lush forests, miles of tea gardens and eucalyptus trees, and the arrival of tourists. At Ooty, some must-see attractions include the Government Rose Garden, Botanical Gardens, Lake Ooty, Stone House, St. Stephen’s Church and other attractions.

3. Nandi Mountain – a quiet resort

These majestic Nandi Hills share the border with Tamil Nadu and are just an hour’s drive from Bangalore. The Biligiriranga Swamy Temple Wildlife Sanctuary is located. Look at the jungle residents, such as shy screaming deer, chital and sambar and more than 254 species of birds, and you have no restraint when walking around in the forest. Relax in the jungle resort and enjoy the tranquillity of the surroundings. Prepare for a holiday you will never forget!

4. Coonoor – the magic of toy trains

Coonoor is known for its lush green Nilgiri hills, tea gardens and impressive views of the tranquil environment, which helps to grow particularly aromatic teas. Strolling through the tea plantations and visiting the plantations is one of the main attractions of the place, making travel to Coonoor an absolute pleasure. Explore the surrounding area of Coonoor on a toy train and enjoy the breathtaking views of the Nilgiri hills. Although it is about 290 km from Bangalore, you can book a toy train to explore the beautiful mountain station.

5. Wayanad – Land of rice fields

Wayanad allows you to enjoy a comfortable environment on a hot summer day, making it one of the most popular mountain stations near Bangalore. Located in Nilgiri Biosphere, about 290 km from IT City, Wayanad not only ensures a rich natural landscape, but also has an interesting history. Ways to visit in Wayanad include the Wayanad Wildlife Sanctuary, the Edakkal Cave, the Wayand Heritage Museum, Kuruva Island, Pazhassi Park and Pookote Lake and other places.

6. Yelagiri Hills – for adventure lovers

A place for adventure lovers to dream, Yelagiri calls for a fun break. If your eyes are always looking for unknown areas, Yelagiri Hills is your best choice. Without commercialization, this place is perfect for perfect postcards. One of the most popular mountain stations around Yelagiri in Bangalore, 160 km away, will provide a fun-filled break for you and your loved ones.

7. Yarkud – Budget holiday on the card

Can’t this holiday be squandered? From Bengaluru (about 215 km) to Yercaud, enjoy a convenient leisure break! With rugged mountains and a tranquil lake, Yercaud is a mountain station that will satisfy your eyes. This fascinating mountain station has endless orange and coffee plantations, as well as many parks, viewpoints, waterfalls and caves to offer you the thrill of exploration. Don’t forget to throw those walking shoes when packing Yercaud.

8. Cafes in Chikmagalur-Karnataka

The beautiful town of Chikmagalur is located at the foot of the Mullayanagiri Mountains, 203 km from Bangalore. This fascinating mountain station is not only the main trading and commercial centre of the state, but also the delight of hikers, explorers and nature lovers. Must-see attractions include the Kalathhigiri Falls, the Veerabhadra Temple and more. Traveling to Chikmagalur is definitely an unforgettable journey.

Now that you know the best mountain station near Bangalore, you will soon start planning your trip. Have a good trip!

 

Java Objects and Classes

Java is an object-oriented language. The following basic concepts are supported:

  • Polymorphism
  • inherit
  • Packaging
  • abstract
  • class
  • Objects
  • Examples
  • method
  • Heavy load

In this section we focus on the concepts of objects and classes.

  • Object : An object is an instance of a class (the object is not a girlfriend ) and has state and behavior. For example, a dog is an object, its state is: color, name, breed; behavior: waving tail, calling, eating and so on.
  • Class : A class is a template that describes the behavior and state of a class of objects.

The boys and girls in the figure below are classes, and each individual is the object of this class:


Objects in Java

Let us now understand in depth what is an object. If you look around at the real world around you, you will find lots of objects, cars, dogs, people and so on. All these objects have their own state and behavior.

Take a dog for example. Its status is: name, breed, color, behavior: calling, waving tail, and running.

Compared with real objects and software objects, they are very similar.

Software objects also have state and behavior. The state of the software object is an attribute, and the behavior is reflected by the method.

In software development, the internal state of the method operation object is changed, and the mutual calling of objects is also accomplished by methods.

Classes in Java

Classes can be seen as templates for creating Java objects.

Use the following simple class to understand the definition of a class in Java:

public class Dog { String breed ;int age ;String color ;void barking () {}void hungry () {}void sleeping () {} }

A class can contain the following types of variables:

  • Local variables : Variables defined in a method, constructor, or statement block are called local variables. Variables are declared and initialized in the method. After the method ends, the variable is automatically destroyed.
  • Member variables : Member variables are defined in the class, outside the body of the method. This variable is instantiated when the object is created. Member variables can be accessed by methods, constructors, and statement blocks of specific classes in the class.
  • Class variables : Class variables are also declared in the class, outside the body of the method, but must be declared as static.

A class can have multiple methods. In the above example: barking(), hungry(), and sleeping() are methods of the Dog class.


Construction method

Each class has a constructor. If you do not explicitly define a constructor for a class, the Java compiler will provide a default constructor for the class.

When creating an object, at least one constructor must be called. The name of the constructor must have the same name as the class. A class can have multiple constructors.

Here is an example of a constructor method:

public class Puppy {        public Puppy ( ) {   }        public Puppy ( String name ) {           // This constructor has only one argument: name   } }

Create an object

Objects are created from classes. In Java, use the keyword new to create a new object. Creating an object requires the following three steps:

  • Declaration : declare an object, including the object name and object type.
  • Instantiation : Use the keyword new to create an object.
  • Initialization : When you create an object with new, the constructor initializes the object.

Here is an example of creating an object:

public class Puppy {        public Puppy ( String name ) {               // This constructor has only one parameter: name               System.out.println ( "The puppy's name is: " + name ) ; }        public static void main ( String [ ] args ) {               // The following statement will create a Puppy object               Puppy myPuppy = new Puppy ( "tommy" ) ;  } }
Compiling and running the above program will print the following result:The puppy's name is: tommy : tommy

Access instance variables and methods

The member variables and member methods are accessed through the created object as follows:

/ * Examples of objects * /ObjectReference = new Constructor ( ) ; / * access class variables * /ObjectReference . VariableName ; / * Method access class * /ObjectReference . MethodName ( ) ;

Examples

The following example shows how to access an instance variable and call a member method:

public class Puppy {int puppyAge;public Puppy(String name) {System.out.println("The puppy's name is: " + name);}public void setAge(int age) {puppyAge = age;}public int getAge() {System.out.println("The puppy's age is : " + puppyAge);return puppyAge;}public static void main(String[] args) {Puppy myPuppy = new Puppy(" tommy ");myPuppy.setAge(2);System.out.println(" variable value: " + myPuppy.puppyAge);}}

Compile and run the above program with the following results:

The name of the puppy is: tommy : tommyThe puppy's age is: 2The puppy's age is : 2  Variable value: 2Variable value : 2  

Source file declaration rules

In the final part of this section, we will learn the rules of declaration of source files. When defining multiple classes in a source file, and also import statements and package statements, pay special attention to these rules.

  • There can be only one public class in a source file
  • A source file can have more than one non-public class
  • The name of the source file should be the same as the class name of the public class. For example: The class name of the public class in the source file is Employee, so the source file should be named Employee.java.
  • If a class is defined in a package, then the package statement should be in the first line of the source file.
  • If the source file contains an import statement, it should be placed between the package statement and the class definition. If there is no package statement, the import statement should be first in the source file.
  • The import statement and package statement are valid for all classes defined in the source file. In the same source file, you cannot declare different packages with different classes.

Classes have several levels of access, and classes are also divided into different types: abstract classes and final classes. These will be introduced in the Access Control section.

In addition to the types mentioned above, Java has some special classes, such as: inner classes, anonymous classes.


Java package

Packages are mainly used to classify classes and interfaces. When developing Java programs, hundreds or thousands of classes may be written, so it is necessary to classify classes and interfaces.

Import statement

In Java, if you give a full qualified name, including the package name, class name, then the Java compiler can easily locate the source code or class. The Import statement is used to provide a reasonable path so that the compiler can find a class.

For example, the following command line will command the compiler to load all classes in the java_installation/java/io path

import java.io.*;java.io.*;

A simple example

In this example, we create two classes: Employee and EmployeeTest .

First open the text editor and paste the following code into it. Note that the file is saved as Employee.java.

The Employee class has four member variables: name, age, designation, and salary. This class explicitly declares a constructor that has only one argument.

Employee.java file code:

import java . io .*; public class Employee {  String name ; int age ; String designation ; double salary ;  // Constructor for the Employee class  public Employee ( String name ) {  this . name = name ;  }   // Set the value of age  public void empAge ( int empAge ) {  age = empAge ; }   /* set the value of designation */  public void empDesignation ( String empDesig ) {  designation = empDesig ; }   /* set the value of salary */  public void empSalary ( double empSalary ) {  salary = empSalary ; }   / * print information * /  public void printEmployee ( ) {  System . out . println ( " Name: " + name ) ; System . out . println ( " Age: " + age ) ; System . out . println ( " Post: " + designation ) ; System . Out . println ( "Salary: " + salary ) ; }}
Programs are started from the main method. To be able to run this program, you must include the main method and create an instance object.

The EmployeeTest class is given below, which instantiates two instances of the Employee class and calls the method to set the value of the variable.

Save the following code in the EmployeeTest.java file.

EmployeeTest.java file code:

import java . io .*;public class EmployeeTest {public static void main ( String [ ] args ) {/* use the constructor to create two objects */Employee empOne = new Employee ( " Bubbule1 " ) ;Employee empTwo = new Employee ( " Bubbule2 " ) ;// Call member methods of these two objects empOne . empAge ( 26 ) ;empOne . empDesignation ( " advanced programmer " ) ;empOne . empSalary ( 1000 ) ;empOne . printEmployee ( ) ;empTwo . empAge ( 21 ) ;empTwo . empDesignation ( " rookie programmer " ) ;empTwo . empSalary ( 500) ;empTwo . printEmployee ( ) ;}}

Compile these two files and run EmployeeTest class, you can see the following results:

$ javac EmployeeTest.javaEmployeeTest . java$ java EmployeeTest EmployeeTest Name: Bubbule1 Name: Bubbule1Age: 26Age: 26Position: Senior programmerPosition: Senior programmerSalary: 1000.0Salary: 1000.0Name: Bubbule2 Name: Bubbule2Age: 21 Age: 21Position: rookie programmer Position: rookie programmerSalary:500.0Salary: 500.0

Java Basic Syntax

A Java program can be thought of as a collection of objects that work together by calling each other’s methods. The following is a brief introduction to the concepts of the following classes, objects, methods, and instance variables.

  • Object : An object is an instance of a class with state and behavior. For example, a dog is an object, its state is: color, name, breed; behavior: waving tail, calling, eating and so on.
  • Class : A class is a template that describes the behavior and state of a class of objects.
  • Methods : Methods are behaviors. A class can have many methods. Logical operations, data modifications, and all actions are done in the method.
  • Instance variables : Each object has a unique instance variable, the state of the object is determined by the value of these instance variables.

The First Java program

Let’s look at a simple Java program that will print the string Hello World

Examples

/* The first Java program * It will print the string Hello World */public class HelloWorld {       public static void main ( String [ ] args ) {              System.out.println ( " Hello World " ) ; // Print Hello World  }  }
The following will introduce how to save, compile and run this program step by step:
  • Open Notepad and add the code above.
  • Save the file name as: HelloWorld.java;
  • Open the cmd command window and enter the location of the target file, assuming C:\
  • Type javac HelloWorld.java in the command line window and press enter to compile the code. If there is no error in the code, the cmd command prompt will advance to the next line. (Assuming that the environment variables are set up).
  • Then type java HelloWorld Press Enter to run the program

You will see Hello World in the window

C : > javac HelloWorld.javaC : > java HelloWorld Hello World

Basic grammar

When writing Java programs, the following points should be noted:

  • Case sensitivity : Java is case-sensitive, which means that the identifiers Hello and hello are different.
  • Class Name : For all classes, the first letter of the class name should be capitalized. If the class name consists of several words, the first letter of each word should be capitalized, for example MyFirstJavaClass .
  • Method name : All method names should begin with a lowercase letter. If the method name contains several words, each subsequent word is capitalized.
  • Source file name : The source file name must be the same as the class name. When saving the file, you should use the class name as the file name (remember that Java is case-sensitive) and the file name has the suffix .java. (If the file name and class name are not the same, a compilation error will result.)
  • Main method entry : All Java programs are executed by the public static void main(String [] args) method.

Java identifier

All parts of Java need names. Class names, variable names, and method names are all referred to as identifiers.

About Java identifiers, the following points need attention:

  • All identifiers should start with the letters (AZ or az), dollar sign ($), or underscore (_)
  • The first character can be followed by any combination of letters (AZ or az), dollar sign ($), underscore (_), or digit
  • Keywords cannot be used as identifiers
  • Identifiers are case-sensitive
  • Examples of legal identifiers: age, $salary, _value, __1_value
  • Examples of illegal identifiers: 123abc, -salary

Java modifiers

Like other languages, Java can use modifiers to decorate methods and properties in a class. There are two main types of modifiers:

  • Access control modifiers: default, public, protected, private
  • Non-access control modifiers: final, abstract, strictfp

We will discuss the Java modifier in depth in later chapters.


Java variables

There are mainly the following types of variables in Java

  • Local variables
  • Class variables (static variables)
  • Member variables (non-static variables)

Java array

Arrays are objects stored on the heap and can hold multiple variables of the same type. In later chapters, we will learn how to declare, construct, and initialize an array.


Java enumeration

Java 5.0 introduced enumeration, enumeration limit variables can only be pre-defined values. Using enums can reduce bugs in the code.

For example, we design a program for a juice shop that will restrict juices to small cups, medium cups, and large cups. This means that it does not allow customers to order juices other than these three sizes.

Examples

class FreshJuice {        enum FreshJuiceSize {             SMALL , MEDIUM , LARGE       } FreshJuiceSize size ;     } public class FreshJuiceTest {        public static void main ( String [ ] args ) {               FreshJuice juice = new FreshJuice() ;              juice . size = FreshJuice . FreshJuiceSize . MEDIUM;  }}

Note: Enumerations can be declared individually or declared within a class. Methods, variables, constructors can also be defined in the enumeration.


Java keywords

The Java keywords are listed below. These reserved words cannot be used for the names of constants, variables, and any identifiers.

categoryKeywordsInstructions
Access controlPrivateprivate
Protectedbe protected
Publicpublic
Class, method, and variable modifiersAbstractDeclaration abstraction
Classclass
ExtendsExpanded, inherited
FinalFinal value, immutable
ImplementsImplementation (interface)
Interfaceinterface
NativeNative, native methods (non-Java implementations)
NewNew, create
StaticStatic
StrictfpStrict, precise
SynchronizedThread, synchronization
Transientshort
VolatileVolatile
Program control statementBreakJump out of the loop
CaseDefine a value for switch selection
Continuecarry on
Defaultdefault
Dorun
Elseotherwise
Forcycle
Ifin case
InstanceofExamples
Returnreturn
SwitchSelect execution based on value
Whilecycle
Error handlingAssertAssert whether the expression is true
CatchCatch an exception
FinallyAre there any exceptions to execute
ThrowThrows an exception object
ThrowsDeclaring an exception may be thrown
TryCatch an exception
Package relatedImportIntroduce
Packagepackage
basic typeBooleanBoolean
ByteByte type
CharCharacter type
DoubleDouble precision floating point
FloatSingle precision floating point
IntIntegral
LongLong integer
ShortShort type
Variable referenceSuperParent class, super class
ThisThis category
VoidNo return value
Reserved keywordsGotoIs a keyword but cannot be used
ConstIs a keyword but cannot be used
Nullair

Java annotations

Like C/C++, Java also supports single-line and multi-line comments. The characters in the comment will be ignored by the Java compiler.

/* This is the first Java program* It will print Hello World * This is an example of a multi-line comment */public class HelloWorld {             public static void main ( String [ ] args ) {                         // This is an example of a single-line comment                        /* This is an example of a single line comment */                       System.out.println( "Hello World" ) ;       } }

Java blank line

Blank lines, or commented lines, are ignored by the Java compiler.


inherit

In Java, a class can be derived from other classes. If you want to create a class and you already have a class that has the properties or methods you need, you can inherit the class from the newly created class.

With inherited methods, you can reuse methods and properties of existing classes without overwriting them. The inherited classes are called super classes, and the derived classes are called subclasses.


interface

In Java, an interface can be understood as a protocol in which objects communicate with each other. The interface plays an important role in inheritance.

The interface defines only the methods to be used for derivation, but the exact implementation of the method depends entirely on the derived class.