import java.util.*;
package everything_is_an_object;


class MyClass {
	int i;
	char c;
}

public class Main {
	public static void main(String[] args)
	{
		MyClass x = new MyClass();
		System.out.println(x.i);
		System.out.println(x.c);
	}
}

My error is on the second line,that was generated by my IDE,with the package. What si the problem ?

Recommended Answers

All 7 Replies

You didn't mention what the error was.

Syntax error on token "package", import expected

Swap your package and import declarations. The package must be the first line in the file.

Doing that it always give me a warning: The import java.util is never used. How can I get rid of that warning ?

Remove it. If it's not used then you don't need to import it.

One more question i have,for every program i need a package ? i am making exercises from a book,i want to organize them by chapters*folders) but when i create a package in my folder,it creates it always in SRC folder.

If you designate a package, the file must appear in a directory of the same name. You are not required to use packages, but it does keep things more organized.

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.