• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compiler Error

 
Ranch Hand
Posts: 163
1
jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


D:\surya>javac Test21.java
Test21.java:6: 'class' or 'interface' expected
package test2;
^
1 error

Why i am getting this error ? I am not understanding this.

Thanks & Regards
Kori Swapna Latha

[Edit - fixed code tags and formatting - MB]
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Swapna,

you have a scope/compile problem, x is not accessible for Test21.

public class Test1
{
public static int x=42;
}

better:
public class Test1
{
protected static int x=42;
}

fixes it.

public = everyone can access it.
protected = only class hierarchy can access it. reduce visibilty as much as possible.

I'm not sure if that fixes your actual compile problem. Give it a try.. you should get eclipse, much easier to learn java.

cheers
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swapna latha wrote:Test21.java:6: 'class' or 'interface' expected
package test2;
^
1 error

Why i am getting this error ? I am not understanding this.


You can only have one package declaration in a .java file, because a class can only belong to one package; and it must be the first statement other than comments.

Also: you can only have one public class in a source file; and it must have the same name as the file without the '.java'.

Winston
 
Korhan Rankin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Swapna latha wrote:Test21.java:6: 'class' or 'interface' expected
package test2;
^
1 error

Why i am getting this error ? I am not understanding this.


You can only have one package declaration in a .java file, because a class can only belong to one package; and it must be the first statement other than comments.

Also: you can only have one public class in a source file; and it must have the same name as the file without the '.java'.

Winston



I acutally didn't thought that the mentioned code is in one file.. if so Winston is right of course.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Korhan Rankin wrote:you should get eclipse, much easier to learn java.


I disagree. Much better that Swapna make these mistakes now, and learn to use Java properly from the command line. The time for an IDE is when you start building projects for real, not while you're learning.

Winston
 
Korhan Rankin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Korhan Rankin wrote:you should get eclipse, much easier to learn java.


I disagree. Much better that Swapna make these mistakes now, and learn to use Java properly from the command line. The time for an IDE is when you start building projects for real, not while you're learning.

Winston



I agree with your point, learning Java properly is better with starting from command line.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic