Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 4, 2012, 11:50 PM   #1
kulimer
Banned
 
Join Date: Aug 2011
Import packages to Java

Hi all,
I have trouble importing any .jar packages, like this one
http://www.icsa.inf.ed.ac.uk/researc...distributions/

I've tried putting it under src and reference library, with command

import eduni.*;
or
import java.eduni.*;

What is going on? Has anyone imported successfully? How did you do it? thanks!
kulimer is offline   0 Reply With Quote
Old Mar 5, 2012, 06:58 AM   #2
wrldwzrd89
macrumors G4
 
wrldwzrd89's Avatar
 
Join Date: Jun 2003
Location: Solon, OH
Quote:
Originally Posted by kulimer View Post
Hi all,
I have trouble importing any .jar packages, like this one
http://www.icsa.inf.ed.ac.uk/researc...distributions/

I've tried putting it under src and reference library, with command

import eduni.*;
or
import java.eduni.*;

What is going on? Has anyone imported successfully? How did you do it? thanks!
Remember, a star import does NOT also import subpackages of the package you're importing. It merely imports all classes in that package. Since the eduni package doesn't have any classes in it, this will fail.
__________________
iMac Intel (Rev H, 27"), 1TB HDD, 16GB RAM, 10.8.4
wrldwzrd89 is offline   0 Reply With Quote
Old Mar 5, 2012, 11:35 AM   #3
kulimer
Thread Starter
Banned
 
Join Date: Aug 2011
Quote:
Originally Posted by wrldwzrd89 View Post
Remember, a star import does NOT also import subpackages of the package you're importing. It merely imports all classes in that package. Since the eduni package doesn't have any classes in it, this will fail.
I could be doing something wrong there, but I've also tried, which also didn't work:
1. SSJ from University of Montreal
http://www.iro.umontreal.ca/~simardr/ssj/indexe.html

2. The JSC library
http://www.jsc.nildram.co.uk/downloads/download.html

On another onte, I was told by someone else "JRE requirements are different for [different] packages".

while someone else said, "It ought to work on any version newer than Java5", which I think the Lion has?

Last edited by kulimer; Mar 5, 2012 at 11:45 AM.
kulimer is offline   0 Reply With Quote
Old Mar 5, 2012, 11:56 AM   #4
wrldwzrd89
macrumors G4
 
wrldwzrd89's Avatar
 
Join Date: Jun 2003
Location: Solon, OH
Quote:
Originally Posted by kulimer View Post
I could be doing something wrong there, but I've also tried, which also didn't work:
1. SSJ from University of Montreal
http://www.iro.umontreal.ca/~simardr/ssj/indexe.html

2. The JSC library
http://www.jsc.nildram.co.uk/downloads/download.html

On another onte, I was told by someone else "JRE requirements are different for [different] packages".

while someone else said, "It ought to work on any version newer than Java5", which I think the Lion has?
Nope. Lion has Java 6...
__________________
iMac Intel (Rev H, 27"), 1TB HDD, 16GB RAM, 10.8.4
wrldwzrd89 is offline   0 Reply With Quote
Old Mar 5, 2012, 12:31 PM   #5
naples98
macrumors member
 
Join Date: Sep 2008
Location: Houston
1. Can you post some code to show how you are using the import statements and describe what errors you are getting?

2. What IDE are you using? Have you added the jars to your classpath?
naples98 is offline   0 Reply With Quote
Old Mar 5, 2012, 01:35 PM   #6
kulimer
Thread Starter
Banned
 
Join Date: Aug 2011
Quote:
Originally Posted by naples98 View Post
1. Can you post some code to show how you are using the import statements and describe what errors you are getting?

2. What IDE are you using? Have you added the jars to your classpath?
Would the screenshot below help?

I am using Eclipse (Ver. Helios Service Release 2)

I right clicked GibbsSampling > Java Build Path > Add External JARs, does that sound like the normal procedure?

I've also tried, import eduni.*;
which the screenshot doesn't show.
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2012-03-05 at 12.23.19 AM.png
Views:	21
Size:	173.7 KB
ID:	327705  
kulimer is offline   0 Reply With Quote
Old Mar 5, 2012, 01:55 PM   #7
kulimer
Thread Starter
Banned
 
Join Date: Aug 2011
I think I figured it out, the files should be located under "/SRC" NOT under "/Referenced Libraries".

And then, add External Jars. Won't work if it's "/Referenced Libraries".
kulimer is offline   0 Reply With Quote
Old Mar 5, 2012, 02:08 PM   #8
naples98
macrumors member
 
Join Date: Sep 2008
Location: Houston
Quote:
Originally Posted by kulimer View Post
I think I figured it out, the files should be located under "/SRC" NOT under "/Referenced Libraries".

And then, add External Jars. Won't work if it's "/Referenced Libraries".
I usually put external jars in a "lib" folder and then add them to the build path. The "/Referenced Libraries" you refer to is not the location of the jars but just that your project is using them.
naples98 is offline   0 Reply With Quote
Old Mar 5, 2012, 02:25 PM   #9
kulimer
Thread Starter
Banned
 
Join Date: Aug 2011
Quote:
Originally Posted by naples98 View Post
I usually put external jars in a "lib" folder and then add them to the build path. The "/Referenced Libraries" you refer to is not the location of the jars but just that your project is using them.
Now I have them all in, still having some trouble using it.
API for the JSC package:
http://www.jsc.nildram.co.uk/api/jsc...ons/Gamma.html

I want to generate numbers from gamma(shape=2.5, scale=0.5).
I have this:

double theta;
theta = rand.Gamma(2.5, 3);

I get "rand cannot be resolved", how should I use it? Unlike R, there are no reproducible examples.

Screenshot has the codes.
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2012-03-05 at 3.24.48 PM.png
Views:	8
Size:	51.4 KB
ID:	327721  
kulimer is offline   0 Reply With Quote
Old Mar 5, 2012, 02:29 PM   #10
naples98
macrumors member
 
Join Date: Sep 2008
Location: Houston
"rand" is a variable name that you have never declared. You need to declare it, just like "theta" before you can call methods on it.

Edit: I don't think you want to use "rand" rather "g" on line 15.

Edit #2: I keep looking at this and thinking about ways to explain it without just giving you the answer but...

"g" is of type Gamma and the class Gamma has methods. I don't know what methods Gamma has but you are probably looking for something like

Code:
theta = g.calculateTheta(2.5, 2);
which means you are calling the calculateTheta method on the instance of Gamma called "g".

Last edited by naples98; Mar 5, 2012 at 02:44 PM.
naples98 is offline   0 Reply With Quote
Old Mar 5, 2012, 02:52 PM   #11
kulimer
Thread Starter
Banned
 
Join Date: Aug 2011
Quote:
Originally Posted by naples98 View Post
"rand" is a variable name that you have never declared. You need to declare it, just like "theta" before you can call methods on it.

Edit: I don't think you want to use "rand" rather "g" on line 15.
I don't know how to use Rand along with gamma, any clues? (API link in the last post)

So, I wrote:
Gamma g = new Gamma();
Random r = new Random();
theta = r.g(2.5, 3);

error: in the last line, under g
"The method g(double, int) is undefined for the type Random"
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2012-03-05 at 3.47.11 PM.png
Views:	6
Size:	50.7 KB
ID:	327727  

Last edited by kulimer; Mar 5, 2012 at 03:29 PM.
kulimer is offline   0 Reply With Quote
Old Mar 5, 2012, 03:32 PM   #12
naples98
macrumors member
 
Join Date: Sep 2008
Location: Houston
When you have an instance of a class stored in a variable, in this case "g", and you want to use methods for that class, you use "g.methodName()" where methodName is the method you want to use.

In the case of the Gamma class, it has 1 method called "sample" which returns a random number so you would call "g.sample()" to use that method.

I don't know why you think you have to use the Random class.
naples98 is offline   0 Reply With Quote
Old Mar 5, 2012, 03:37 PM   #13
kulimer
Thread Starter
Banned
 
Join Date: Aug 2011
Quote:
Originally Posted by naples98 View Post
Code:
theta = g.calculateTheta(2.5, 2);
which means you are calling the calculateTheta method on the instance of Gamma called "g".
yeah, what you are saying makes sense. But something is not right.

First, call Gamma, so, I have g. Followed by, dot r, where r means random. I have,
Code:
theta = g.r(2.5, 3.0);
Also, should I declare
Code:
Rand r = new Rand(); 
//or 
Random r = new Random();
I'm going with the first one, it's the jsc method, but I get red underline under Rand.
kulimer is offline   0 Reply With Quote
Old Mar 5, 2012, 03:51 PM   #14
naples98
macrumors member
 
Join Date: Sep 2008
Location: Houston
Quote:
Originally Posted by kulimer View Post
First, call Gamma, so, I have g. Followed by, dot r, where r means random. I have,
Code:
theta = g.r(2.5, 3.0);
The class Gamma does NOT have a method called "r" so
Code:
theta = g.r(2.5, 3.0);
is not going to work. Also, you don't "call Gamma", you call a "method from the class Gamma".

Quote:
Also, should I declare
Code:
Rand r = new Rand(); 
//or 
Random r = new Random();
I'm going with the first one, it's the jsc method, but I get red underline under Rand.
The first one may give you an instance of Rand if it has a no-arg constructor but I don't know what the class Rand is or where you are getting it from. The second will correctly give you an instance of Random although I don't see anywhere in your code that requires it. Exactly what are you looking at that makes you think you need to use Random (or Rand).
naples98 is offline   0 Reply With Quote
Old Mar 5, 2012, 05:03 PM   #15
kulimer
Thread Starter
Banned
 
Join Date: Aug 2011
Quote:
Originally Posted by naples98 View Post
The class Gamma does NOT have a method called "r" so
Code:
theta = g.r(2.5, 3.0);
is not going to work. Also, you don't "call Gamma", you call a "method from the class Gamma".

The first one may give you an instance of Rand if it has a no-arg constructor but I don't know what the class Rand is or where you are getting it from. The second will correctly give you an instance of Random although I don't see anywhere in your code that requires it. Exactly what are you looking at that makes you think you need to use Random (or Rand).

exactly, like you said! To generate random I should use
Code:
g.random()
And I don't need to declare random like how I do in import java.util.Random;

So, it should be
Code:
double alpha=2.5;
	    double beta=r.nextInt(10)*1.0; 
	    Gamma g = new Gamma(alpha,beta);
	    System.out.println("Random value is "+g.random());
Also, you have to type
import jsc.distributions.Gamma;
import jsc.*; won't call Gamma out.

I don't know why, but I worked my way through. A screenshot for anyone else ever Googles here. This should help you!
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2012-03-05 at 5.57.21 PM.png
Views:	7
Size:	68.2 KB
ID:	327740  
kulimer is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Some apps prompt to install Java 6 even when Java 7 is installed MacMan988 OS X Mavericks (10.9) 1 Apr 18, 2014 07:56 AM
Java 6 or Java 7 for OSX Mavericks for your Macbook Pro? Starfyre MacBook Pro 3 Dec 22, 2013 03:49 PM
Java 6.x security risk (?) vs Java 7.x and broken apps w/ v7.x installs? mgiamo Mac Basics and Help 1 Dec 15, 2013 03:48 PM
Chrome on OS X -- Java plugin / Java 7 vs Java 6 Issue booyahbooyah Mac Applications and Mac App Store 4 May 31, 2013 09:13 AM
Installed Java 7.07 but doesn't show up in Java preferences? -mattias- OS X 10.8 Mountain Lion 21 Aug 31, 2012 04:49 PM

Forum Jump

All times are GMT -5. The time now is 03:43 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC