tags:

views:

217

answers:

3

First, the code in question:

package net.foo.server;

import at;
import ay;
import bi;
import bj;
import bl;
import ck;
import cw;
import da;
import dp;
import ds;
import dt;
import dw;
import ep;
import fa;
import fd;
import fi;
import fl;
import ge;
import ho;
import ht;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

Next, the errors:

net\foo\server\fooServer.java:8: '.' expected
import at;
         ^
net\foo\server\fooServer.java:8: ';' expected
import at;
          ^
net\foo\server\fooServer.java:9: class, interface, or enum expected
import ay;
       ^
net\foo\server\fooServer.java:10: '.' expected
import bi;
         ^
net\foo\server\fooServer.java:10: ';' expected
import bi;
          ^
net\foo\server\fooServer.java:11: class, interface, or enum expected

import bj;
       ^
net\foo\server\fooServer.java:12: '.' expected
import bl;
         ^
net\foo\server\fooServer.java:12: ';' expected
import bl;
          ^
net\foo\server\fooServer.java:13: class, interface, or enum expected

import ck;
       ^
net\foo\server\fooServer.java:14: '.' expected
import cw;
         ^
net\foo\server\fooServer.java:14: ';' expected
import cw;
          ^
net\foo\server\fooServer.java:15: class, interface, or enum expected

import da;
       ^
net\foo\server\fooServer.java:16: '.' expected
import dp;
         ^
net\foo\server\fooServer.java:16: ';' expected
import dp;
          ^
net\foo\server\fooServer.java:17: class, interface, or enum expected

import ds;
       ^
net\foo\server\fooServer.java:18: '.' expected
import dt;
         ^
net\foo\server\fooServer.java:18: ';' expected
import dt;
          ^
net\foo\server\fooServer.java:19: class, interface, or enum expected

import dw;
       ^
net\foo\server\fooServer.java:20: '.' expected
import ep;
         ^
net\foo\server\fooServer.java:20: ';' expected
import ep;
          ^
net\foo\server\fooServer.java:21: class, interface, or enum expected

import fa;
       ^
net\foo\server\fooServer.java:22: '.' expected
import fd;
         ^
net\foo\server\fooServer.java:22: ';' expected
import fd;
          ^
net\foo\server\fooServer.java:23: class, interface, or enum expected

import fi;
       ^
net\foo\server\fooServer.java:24: '.' expected
import fl;
         ^
net\foo\server\fooServer.java:24: ';' expected
import fl;
          ^
net\foo\server\fooServer.java:25: class, interface, or enum expected

import ge;
       ^
net\foo\server\fooServer.java:26: '.' expected
import ho;
         ^
net\foo\server\fooServer.java:26: ';' expected
import ho;
          ^
net\foo\server\fooServer.java:27: class, interface, or enum expected

import ht;
       ^
30 errors

I have already made sure the the CLASSPATH variable includes the directory. Anybody have any clue? (Note: the compiler is only having trouble with my classes

A: 

For starters, you are importing a whole bunch of classes into a .java file that doesn't declare anything. That's what the class, interface, or enum expected message is about.

After all those imports, you would declare a class (or interface, or enum) like this:

package net.foo.server;

/*
 * import statements 
*/

public class MyClass {
    // fields, methods, etc. here
}

What are the randomly-named 2-letter packages you're importing?

Matt Ball
I assumed they were classes in an unnamed package rather than packages (which would be import at.*). I think there is some restriction against importing stuff from an an unnamed packaged. You can create a .java file which does not declare anything. (I always create a package-info.java - for javadoc - which does not declare anything.)
emory
Emory is correct, these are classes outside a sub-package, directly in the CLASSPATH. And I do declare a class after the imports, I just didn't feel it was necessary to include it here.
Nathan Gibson
A: 

You can't import classes like that unless they are part of a package outside the package this class is in. If these classes are outside, you are going to have to explicitly import them or use the * wildcard to import them all at the same time.

Roi
A: 

Import statements are used to import types. There's no concept of importing a package the way you've written your code.

You can import every type in a package using star-notation, e.g.,

import at.*;

But you cannot just import the package "at." This is the source of all the compiler issues you're seeing.

I'd further point out that completely undescriptive two-letter package names without any hierarchy whatsoever goes very much against well-established naming and organization conventions in Java. I refer you to a Wikipedia link on naming conventions found by simply Googling for "Java package names."

I recommend you become more familiar with the language conventions. These conventions are used because they make things a lot easier on you as well as anybody else who wants to read your code.

RonU
These are not packages. They are classes that are not in a sub-package, directly in the CLASSPATH.
Nathan Gibson
Okay, well aside from the violation of Java naming principles, wherein types are camel-cased, you cannot import a type from the default package (the default package has no name), which is what you're describing.So again, you're left with the restriction that import statements must start with a package and eventually refer to types, either explicitly or by star-notation.
RonU
Obviously, my code was obfuscated since it's a personal project that I'm working on. My question had nothing to do with naming principles, which I know plenty about. simply seeing the word foo and random letters would have clued me in on the obfuscation. As far as the hierarchy, let me clarify how my package is set up.CLASSPATH=.;C:\footest\.;The classes that this code is importing are in C:\footest\.This file is in C:\footest\net\foo\server\.I received a nearly identical class from a colleague of mine, which used the exact same package structure and was compiled successfully.
Nathan Gibson