Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: importing class files :S

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default importing class files :S

    Greetings to all who read this, i am completely new to java and have a problem with importing my own class file.

    My main page is this:

     
    import ConCLOCK;
     
    public class Time
    {
    	public static void main(String[] args)
    	{
    		ConCLOCK Clock1 = new ConCLOCK (0,15,2); 
    		Clock1.ConMINUTES();
    		Clock1.ConHOURS();
    		Clock1.ConTOTAL();
     
     
    	}
    }

    the imported file is this :

     
    public class ConCLOCK
    {
    	private long seconds;
    	private long minutes;
    	private long hours;
    	private long totalSEC;
     
     
     
    	public ConCLOCK ( long secs, long mins, long hrs)
    	{
    		seconds = secs;
    		minutes = mins;
    		hours = hrs;
    	}
     
    //converts minutes into seconds	
    	public  long ConMINUTES ()
    	{
    		if (minutes > 0) 
    		{
    			minutes = (minutes * 60);
    		}
    		return minutes;
    	}
     
    //converts hours into minutes then seconds	
    	public long ConHOURS ()
    	{
    		if (hours > 0 )
    		{
    			hours = (hours * 60) * 60;
    		}
    		return hours;
    	}
     
    	public void ConTOTAL () 
    	{
    		totalSEC = (seconds + minutes + hours);
    		System.out.println ( "Total time conversion to seconds is : " + totalSEC );
    	}
    }

    I am compiling from cmd prompt and not from eclipse or anything like that. I have two compiling errors that say that I need to add a "." and a ";" at the word ConCLOCK of line one right after import. My ultimate goal is to package the two class files. I am completely stumped and have no experience. Any help would rock my world. thx.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: importing class files :S

    If the two classes are in the same directory, they are in the same package (see Creating and Using Packages). You only need to import if they are in different packages. If they are in the same directory, Compile ConCLOCK first, then compile your other class. If they are in different folders, you need to define a package structure and import the correct package files appropriately.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: importing class files :S

    The import statement does not "import" other files into your code. It is way to tell the compiler where to look for classes that are used in your program. It is an extension of the classpath.

  4. #4
    Junior Member
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: importing class files :S

    that works, thanks to the both of you ... learning everyday and im stoked you both clarified those things up for me.

Similar Threads

  1. Importing excel data
    By supriya ramjee in forum File I/O & Other I/O Streams
    Replies: 11
    Last Post: October 20th, 2012, 09:39 AM
  2. Methods in java class files are not recognized.
    By Girish in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 18th, 2010, 05:44 AM
  3. Replies: 0
    Last Post: April 11th, 2010, 08:56 AM
  4. Need help compiling java class files
    By peahead in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 11th, 2010, 09:04 AM
  5. importing packages..
    By chronoz13 in forum Java IDEs
    Replies: 4
    Last Post: November 23rd, 2009, 05:49 PM