My first Java project encountered: Type name is not valid. The type name ‘Hello World’ is not a valid identifier

tags: Java learning log  java  eclipse

When I first contacted Java, I created a project but found that the class name is an illegal identifier @Illegal identifier

Create the first Java project: Hellow World


It displays Type name is not valid. The type name ‘Hello World’ is not a valid identifier. After searching for the problem, I found that there is a space in the name of Hellow World.A legal identifier cannot be mixed with spacesof.


Later, a cross was found in the upper part of the code block, which read: "Must declare a named package because this compilation unit is associated to the named module ‘HelloWorld’"

I found a solution by searching the blogs of big guys:What to do if the package is not declared

For Java novices who use the latest version of eclipse, they may encounter a small problem:
“ Must declare a named package because this compilation unit is associated to the named module ‘MyProject02’ ”
The reason for this situation is that in the latest version of eclipse, you need to define a package while defining a class. This is different from the previous eclipse, and many java instructional videos still use the non-latest version of ecilpse , So we see in many teaching videos that the teacher can directly create a class. Here, let me say by the way how to define a package:
Select the File->New->Class command in the eclipse menu bar, in the import dialog box, search for Package, and then name it.
From the blogger-DSB kid

The first time I came into contact with java, there were always many problems. After typing the code, I found

The problem of The public type c must be defined in its own file occurs because the defined JAVA class is inconsistent with the file name;
Solution:JAVA error: The public type *** must be defined in its own file***
   1. Modify the file name to the same name as the public class;
  2, modify the class name to the same file name;
  3. When the subclass inherits the parent class, there is no need to use public modification
From the blogger-Data circle

Then I took a closer look at my class name and file name, and found that HelloWorld was entered as HellowWorld by me. I did not find the problem after reading it for a long time. It seems that the code is still not sensitive enough...

After running the program, you can output the page to get the content in the quotes of System.out.println
This is the first project I created: HelloWorld

Intelligent Recommendation

My first SpringBoot project-Hello World

The previous article briefly introducedHow to quickly create a Spring Boot project, We have a basic project structure: First, we analyze pom.xml From the content of dependencies, we can easily find th...

Appear "Not valid pin name for part type XX" wrong reasons and solutions when importing PADS OrCAD

Examples of errors: As a simple example to explain. The figure is a circuit diagram: Then fill in the appropriate component to each PCB footprint. Here, LED lamp selection of in-line package, can be f...

deno error trying to connect: dns error: The requested name is valid, but the requested type of data cannot be found

error: error sending request for url (https://raw.githubusercontent.com/pillarjs/path-to-regexp/v6.1.0/src/index.ts: error trying to connect: dns error: requested name is valid, but the requested type...

The first Java project: Hello World

If the SDK is popular, select the jdk installation directory Click onjdk installation and environment variable configurationRemember where you installed jdk Then click Next Then click Next Name the pr...

not a valid identifier

1, problem When you install TMUX, add the environment variable, add it. Then the overloaded environment source ~ / .bashrc Tips: not a valid identifier 2, solution Limited: Not a valid identifier. Bai...

More Recommendation

iOS encountered Unkown type name NSString Unkown type name CGFloat

Defined herein is a C data type. Directly into the #import <UIKit / UIKit.h> resolved in a file   I had the same issue on my project when I was trying to mix C code (.h and .c) with Objecti...

My first hello world program JAVA

Learning any language, the first program is hello world. Just beginning to learn java junior partner, I suggest writing code in Notepad so you can lay a better foundation for the next. First create a ...

Hello World! My first java program

IDEA installation JDK: Java Development Kit (Development Tool Pack) JRE: Java Runtime Envoironment (operating environment) JVM: Java Virtual Machine (virtual machine) Install Install JDK 1. Download j...

Exception javax.el.ELException: The identifier [float] is not a valid Java identifier

This error only occurs with Tomcat7.X.     Use todayStruts 2 Extreme Form Validation Framework:https://code.google.com/p/struts-plus/   Jsp code: Access jsp report exception javax.el.EL...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top