Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By allaudin

Thread: Running Java from Command Line

  1. #1
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Running Java from Command Line

    Java Code:
    package demo;
    import primeNumbers.Prime;
    class DemoClass{
    
    public static void main(String[] args){
    
    Prime prime = new Prime();
    System.out.println(prime.isPrime(66));
    
    }
    
    }
    **********************************
    Java Code:
    package primeNumbers;
    
    public class Prime{
    
    
    public boolean isPrime(int number){
    boolean ok = false;
    if( number == 0 || number == 1 || number == 2)
    return true;
    for(int i=2; i <= Math.sqrt(number); i++)
    	if(number%i == 0)
    	ok = true;
    	if(ok)
    	return false;
    	else 
    	return true;
    
    }
    }
    not imorting primeNumbers when I run it from cmd .. theri root directory is mathematics .. ...showing error (package primeNumbers doesnot exist)
    package hierarchy is :

    mathematics -- ( demo , primeNumbers)
    any help ? thanks in advance

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,935
    Rep Power
    4

    Default Re: Running Java from Command Line

    When I ran them manually I put them each in
    mathematics\demo\DemoClass.java
    mathematics\primeNumbers\Prime.java

    Then I just compiled them from mathematics like this:
    javac demo\DemoClass.java
    javac primeNumbers\Prime.java

    Then I ran the DemoClass by doing:
    java demo.DemoClass
    From the mathematics directory

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Running Java from Command Line

    what i was doing .. i was compiling it being within the demo directory ...
    Villa likes this.

  4. #4
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Running Java from Command Line

    thanks jim

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,004
    Blog Entries
    7
    Rep Power
    20

    Default Re: Running Java from Command Line

    0 and 1 aren't prime numbers by definition.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 06-13-2013, 12:44 AM
  2. Linux running/compiling from Command Line?
    By arcelivez in forum New To Java
    Replies: 4
    Last Post: 01-27-2012, 11:10 PM
  3. Running Main from Command Line
    By sriram56 in forum New To Java
    Replies: 2
    Last Post: 11-26-2011, 09:27 AM
  4. Error While Running Windows Command Line Instruction
    By divs1210 in forum AWT / Swing
    Replies: 5
    Last Post: 04-13-2011, 04:09 PM
  5. Running Jar file using command line through Java Codes
    By NaturalE in forum Advanced Java
    Replies: 2
    Last Post: 02-24-2011, 04:07 AM

Posting Permissions

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