Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error on token "package", import expected (Java)

Tags:

java

I am trying trying to import java.lang.Math in Java on Eclipse and am getting the error in the title. Here is the beginning of my code:

import java.lang.Math;

package test1;

This error is popping up under "package test1;"

like image 811
user2800912 Avatar asked Sep 20 '13 22:09

user2800912


1 Answers

The package statement must be first in the file, before anything, even imports:

package hw1;

import java.lang.Math;

Plus, you don't need to import java.lang.Math, or anything in java.lang for that matter.

The JLS, Chapter 7 says:

A compilation unit automatically has access to all types declared in its package and also automatically imports all of the public types declared in the predefined package java.lang.

like image 129
rgettman Avatar answered Oct 18 '22 04:10

rgettman