i am new to java i hava saw error that illegal start of error in this program

public class double
{
public static void main(String[] args )
{
double d=1232.44;
System.out.println("the double value is :"+d);
}}

please help me

Dani AI

Generated

: the replies from , and are on the right track — the compiler hit a token it could not accept where an identifier or declaration was expected. The fix is to use a valid top-level class name and follow Java file/name rules, then recompile. Also include the full javac error next time (as asked) — the line number in the message points to the exact place the parser gave up.

A minimal, working example (different from the one posted) you can save and try:

public class DoubleDemo {
    public static void main(String[] args) {
        double value = 1232.44;
        System.out.println("the double value is :" + value);
    }
}

Save as DoubleDemo.java, compile with javac DoubleDemo.java and run with java DoubleDemo. The filename must match the public class name (case sensitive), and identifiers must not be Java reserved words.

If you still see "illegal start of expression", check these common causes:

  • Look at the line number javac prints and the few lines before it — a missing ; or unmatched { earlier often causes the parser to fail later.
  • Methods declared inside other methods, or stray tokens outside any class, will trigger the same message.
  • Invisible characters (UTF-8 BOM) or wrong file encoding can confuse the compiler; re-save as plain UTF-8 without BOM or compile with javac -encoding UTF-8.
  • Copy/paste errors: stray angle brackets, XML, or editor auto-inserted text.

Use a simple IDE (Eclipse/IntelliJ/NetBeans) or javac output to find the exact offending line. For the authoritative list of reserved words, see the Java keywords documentation: Java keywords.

Recommended Answers

All 3 Replies

What was the full text of the error message?

You should not use ANY of Java's keywords or class names for the names of your classes or variables.

yep ... double is a reserved keyword. that 'll propably be your fault.
just rename your file (and class) to something more suitable (and allowed) like DoubleApp

public class double
{
public static void main(String[] args )
{
double d=1232.44;
System.out.println("the double value is :"+d);
}}

you cannot use keywords lik NormR1 says

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.