I cannot figure out how to use general packages in intellij

Answered

I am trying to utilize the import java.util*; packages in IntelliJ but the programs are not recognizing them (because I am obviously doing something wrong). So, for example, say I want to use import java.util.Date; and then proceed to write code that displays the number of milliseconds since 2:00 a.m. Whenever I write in the import java.util.Date;  and then write the code after it, it doesn't compile and I receive an error message. I know I am doing something wrong. Therefore, how do I call on the import java.util packages inside the editor so that I can call on its many classes and methods?

0
2 comments

Hi. Providing a screenshot of the error you are getting, and some code examples would be very helpful. Also check that your JDK is set properly: https://www.jetbrains.com/help/idea/sdk.html

0
Avatar
Permanently deleted user

 

import java.util.Date;

class DateDemo {
public static void main(String args[]) {
Date date = new Date();

System.out.println (date);

long msec = date.getTime();
System.out.println("Milliseconds since Jan. 1, 1970 GMT = " + msec);
}


}

that was my initial code. However, I kept getting an error message because at first it was not importing the java.util.Date package and it was just starting to run at main() and an error was of course popping up. I think it was because in the Class section I had put public class DateDemo instead of just class. Now it ran fine. Why would it be such an error to put public class DateDemo { ?

Hey thanks for the answer/reply as well. I really do appreciate it. I am struggling a little with coding but IntelliJ is helping.


0

Please sign in to leave a comment.