identifier expected Error in java Compilation
well in class level you can only define attributes of that class, cant do any processing which you are doing in classA and classB. Processing can only be done in method.
Just add main method make objects there
public class Hello
{
// value / method
public static String staticValue;
public String nonStaticValue;
public void main(String[] args){
Hello hello = new Hello();
Hello.staticValue = "abc";
hello.nonStaticValue = "xyz";
Hello hello2 = new Hello(); // here staticValue = "abc"
Hello.staticValue; // will have value of "abc"
hello2.nonStaticValue; // will have value of null
}
}
Main method is entry point of any program in java. Dont worry if you are confused where this main method is called.
identifier expected compilation error in Java[3]
You need to wrap your code in a method. You can't have normal statements directly inside a class.
A good method for you to wrap this in is in a main
method:
import java.io.*;
class attendance_and_student_management {
public static void main(String[] args) {
BufferedReader bw = new BufferedReader(new InputStreamReader(System.in));
File f5 = new File("e.txt");
f5.createNewFile();
File f4 = new File("d.txt");
f4.createNewFile();
File f3 = new File("c.txt");
f3.createNewFile();
File f2 = new File("b.txt");
f2.createNewFile();
File f1 = new File("a.txt");
f1.createNewFile();
}
}
By putting it in a main
method, you can directly invoke this class from the command line with java -cp <classpath> attendance_and_student_management
.
Note that by Java naming conventions, class names should use CamelCase and start with a capital. So the proper name for your class per these conventions is AttendanceAndStudentManagement
.
New maven project fails to compile: App.java:[1,8] identifier expected
Package names must be valid Java identifiers. That means that your package name is invalid for 2 reasons.
There are hyphens, which are not allowed in an identifier. The parser in the compiler thinks that the identifier is the portion of your package name before the first hyphen, which is public
. That is a keyword and not allowed as an identifier.
Try a different package name such as public_recommendation_service
or pubrecservice
.
Compiler error: identifier expected. How do I resolve this?
Indent the code. There main problem is here:
public static void main(String[] args) {
double monthRain = 0;
//more code...
while (years < 1) {
System.out.print("Invalid. Enter 1 or greater: ");
input anotheryears = keyboard.nextInt();
}
} //<--- here
//you're closing the main method
//and then you have more code outside of it
final int NUM_MONTHS = 12; // Months per year
System.out.println("Enter the rainfall, in inches, for each month."); //here
for (int y = 1; y <= years; y++); //here
//rest of code
Apart of this, remove the semicolons after for
statements:
for (int y = 1; y <= years; y++); //<-- remove this
It should be like this:
for (int y = 1; y <= years; y++) {
//rest of code...
}
Related Topics
Jackson Overcoming Underscores in Favor of Camel-Case
Pass a Local File in to Url in Java
What Java 8 Stream.Collect Equivalents Are Available in the Standard Kotlin Library
How to Clear or Empty a Stringbuilder
Difference Between "On-Heap" and "Off-Heap"
"File Not Found" When Running New Libgdx Project
Why We Shouldn't Make a Spring MVC Controller @Transactional
Best Option for Session Management in Java
Collections.Emptylist() VS. New Instance
Java Desktop Application: Swt VS. Swing
Rollback Transaction After @Test
What Does the Colon (:) Operator Do
How to Add Shapes on Javafx Linechart
Loading a Text File into a Textarea
Is It Safe to Get Values from a Java.Util.Hashmap from Multiple Threads (No Modification)
Moving Items Around in an Arraylist
Performance Difference Between a Wild Card Import and the Required Class Import