Results 1 to 4 of 4
  1. #1
    andrew.goss is offline Member
    Join Date
    Mar 2014
    Posts
    2
    Rep Power
    0

    Default import java.util.* not recognized

    I am currently using notepad to create a Java program and using the command box to compile it and execute it and it has been working fine. I have the JDK version 7 so java.lang works which I know does not need to be imported. The Calendar method which should be recognized is not.

    Here is the program. Cut this program and compile it in the command box. It will not recognize the Calendar method.

    import java.util.*;

    class Practice4_2
    {
    public static void main (String args[])
    {
    Calendar cal = Calender.getInstance();
    Date.now = new Date();
    cal.setTime(now);
    int dayofweek = cal.get(Calender.DAY_OF_WEEK);
    if (dayofweek == Calender.SUNDAY)
    System.out.println("Eat at Joes's");
    if (dayofweek == Calender.MONDAY)
    System.out.println("Eat at Tom's");
    if (dayofweek == Calender.TUESDAY)
    System.out.println("Eat at Kevin's");
    if (dayofweek == Calender.WEDNESDAY)
    System.out.println("Eat at Rich's");
    if (dayofweek == Calender.THURSDAY)
    System.out.println("Eat at Rose's");
    if (dayofweek == Calender.FRIDAY)
    System.out.println("Eat at Ken's");
    if (dayofweek == Calender.SATURDAY)
    System.out.println("Eat at Melissa's");
    }
    }


    Here is my path if needed:

    C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%System Root%\System32\Wbem;%SYSTEMROOT%\System32\WindowsP owerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Java\jdk1.7.0_51\bin;
    Attached Thumbnails Attached Thumbnails import java.util.* not recognized-java-util-question.jpg  

  2. #2
    typedef is offline Member
    Join Date
    Feb 2014
    Posts
    52
    Rep Power
    0

    Default Re: import java.util.* not recognized

    Quote Originally Posted by andrew.goss View Post
    I am currently using notepad to create a Java program and using the command box to compile it and execute it and it has been working fine. I have the JDK version 7 so java.lang works which I know does not need to be imported. The Calendar method which should be recognized is not.

    Here is the program. Cut this program and compile it in the command box. It will not recognize the Calendar method.

    import java.util.*;

    class Practice4_2
    {
    public static void main (String args[])
    {
    Calendar cal = Calender.getInstance();
    Date.now = new Date();
    cal.setTime(now);
    int dayofweek = cal.get(Calender.DAY_OF_WEEK);
    if (dayofweek == Calender.SUNDAY)
    System.out.println("Eat at Joes's");
    if (dayofweek == Calender.MONDAY)
    System.out.println("Eat at Tom's");
    if (dayofweek == Calender.TUESDAY)
    System.out.println("Eat at Kevin's");
    if (dayofweek == Calender.WEDNESDAY)
    System.out.println("Eat at Rich's");
    if (dayofweek == Calender.THURSDAY)
    System.out.println("Eat at Rose's");
    if (dayofweek == Calender.FRIDAY)
    System.out.println("Eat at Ken's");
    if (dayofweek == Calender.SATURDAY)
    System.out.println("Eat at Melissa's");
    }
    }


    Here is my path if needed:

    C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%System Root%\System32\Wbem;%SYSTEMROOT%\System32\WindowsP owerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Java\jdk1.7.0_51\bin;
    Thoroughly enjoyed this post as this is a classic example of the type of stuff I did when I first started learning programming.

    Ok, onto the problem. Your first problem is you spelled Calendar as Calender throughout your whole program. Another problem is the second line in main reads Date.now when you mean to read Date now. Third problem that's not so severe - you have a logically problem. When you cycle throughout your if statements you should stop checking once you've found a day of the week. In order to do this you must make all your if statements after the first else if's.

    Also as a (very important) side note. Post your code in tags. In order to do this select your code in advanced view and click the # button on the second line for editing your document. I almost didn't give your post a chance because I saw the code badly formatted (fortunately for you I was interested in your command prompt problem). This is why its important you make sure your code is in [CODE] tags otherwise people on coding forums will just pass your post up as someone to lazy to do the minimal.

    Try this and give me a shout if it works on your side:
    Java Code:
    import java.util.Calendar;
    import java.util.Date;
    
    public class Practice4_2
    {
    	public static void main(String args[])
    	{	
    		Calendar cal = Calendar.getInstance();
    		Date now = new Date();
    		cal.setTime(now);
    		int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
    		if (dayofweek == Calendar.SUNDAY)
    			System.out.println("Eat at Joes's");
    		else if (dayofweek == Calendar.MONDAY)
    			System.out.println("Eat at Tom's");
    		else if (dayofweek == Calendar.TUESDAY)
    			System.out.println("Eat at Kevin's");
    		else if (dayofweek == Calendar.WEDNESDAY)
    			System.out.println("Eat at Rich's");
    		else if (dayofweek == Calendar.THURSDAY)
    			System.out.println("Eat at Rose's");
    		else if (dayofweek == Calendar.FRIDAY)
    			System.out.println("Eat at Ken's");
    		else if (dayofweek == Calendar.SATURDAY)
    			System.out.println("Eat at Melissa's");
    	}
    }

  3. #3
    andrew.goss is offline Member
    Join Date
    Mar 2014
    Posts
    2
    Rep Power
    0

    Default Re: import java.util.* not recognized

    Glad you enjoyed my mess-ups.

    It was my first post and took me a half hour just to find how to start a thread, but everything you said was very helpful. Next time I will follow your advice. Thanks very much.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: import java.util.* not recognized

    Be sure to make good use of the API documentation, that should prevent troubles with spelling mistakes and such:

    Java Platform SE 7

    If you think a class or method should exist but you get errors anyway (or you want to browse to see what methods exist in a class), look it up here. Eventually you will start to use an IDE which will provide you with auto-completion, but its a good choice to work with the command prompt only during your learning period so you have to use more resources to solve problems.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Import java,util.Scanner error
    By rockets97 in forum New To Java
    Replies: 7
    Last Post: 02-20-2014, 08:34 PM
  2. Using import java.util.Scanner
    By The Taco in forum New To Java
    Replies: 2
    Last Post: 08-10-2013, 09:26 PM
  3. import java.util.* doesn't works
    By Martino Milani in forum New To Java
    Replies: 6
    Last Post: 01-24-2012, 02:05 AM
  4. import java.util ????
    By kris09 in forum New To Java
    Replies: 3
    Last Post: 08-11-2008, 12:39 AM
  5. java.util.DateFormat not found in import
    By christina in forum New To Java
    Replies: 2
    Last Post: 08-05-2007, 10:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •