Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I have a general question about databases and Java. I'm doing something that now looks like I could do better with a database. I know of things like JDBC that provide some abstraction to a database, and I generally know of persistence frameworks that add a layer on top of that for things like retrieving information for beans. I am wondering if those frameworks would interfere with what I'm try to do, or if it's worth looking into them.

I'm iterating through daily stock data from files right now, with each symbol in a file. Every line has the symbol, date, closing price, opening price, high, low, and volume. So it's pretty much just big tables. I'd want to be able to look up spans of data for each symbol as a basic thing, but then also be able to query based on extra numeric data I'm going to provide. I suck at SQL (since I never use it after taking the tutorials) but it seems like these are pretty basic queries. So would a persistence framework on top of that be more of a burden?

Adbot
ADBOT LOVES YOU

Fly
Nov 3, 2002

moral compass

Rocko Bonaparte posted:

That's too bad. For this case it isn't a huge issue, but if I'm crunching a bunch of stuff, then I could see it being hellish trying to cram it into a single, atomic statement.
You should be able to make some private static methods to generate any of the data that you really need. The chained constructor call must be the first thing there because there is no valid instance state to reference, and the code might try to reference instance state if any instance methods or properties were accessible before the invocation of the other constructor.

In other words, it is easy to express what you really want, so it's not really a problem.

Fly
Nov 3, 2002

moral compass

Rocko Bonaparte posted:

I have a general question about databases and Java. I'm doing something that now looks like I could do better with a database. I know of things like JDBC that provide some abstraction to a database, and I generally know of persistence frameworks that add a layer on top of that for things like retrieving information for beans. I am wondering if those frameworks would interfere with what I'm try to do, or if it's worth looking into them.

I'm iterating through daily stock data from files right now, with each symbol in a file. Every line has the symbol, date, closing price, opening price, high, low, and volume. So it's pretty much just big tables. I'd want to be able to look up spans of data for each symbol as a basic thing, but then also be able to query based on extra numeric data I'm going to provide. I suck at SQL (since I never use it after taking the tutorials) but it seems like these are pretty basic queries. So would a persistence framework on top of that be more of a burden?
I know of no persistence framework that will make it [edit]easier to write the simple or complex queries you want. Things like JPA QL or Hibernate HQL may give you basically the equivalent of SQL, and maybe if you're inserting the data with a persistence framework (e.g., JPA or Hibernate), you could use their query language to get just the data you want rather than whole objects that you would then operate upon in the JVM.

Fly fucked around with this message at 19:39 on Dec 15, 2008

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Thanks Fly for both responses. I think I'll figure out how my queries might look in SQL and then start thinking about what that would mean in Java. I should have some minimal comfort editing a database before I start trying to work it with a framework.

When I saw hibernate in action, I saw it being used to tie objects (beans, I guess) to things in a database. It would take care of manipulating the database under the hood. Maybe that would work for me, but I'd need to shift to J2EE to start using bean components. And generally the nature of the work I'm doing, it would probably be easy enough to generate the queries by stating "give me all data for symbol XYZ from 2006/01/01 to 2007/01/01."

Fly
Nov 3, 2002

moral compass

Rocko Bonaparte posted:

Maybe that would work for me, but I'd need to shift to J2EE to start using bean components.
I would stay far away from J2EE. The JPA stuff in the EJB 3.0 specification is nice though. It's basically a simplified version of the Hibernate APIs. You do not need to use J2EE bean stuff (session beans, entity beans, hillo beans) for anything, ever.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Fly posted:

I would stay far away from J2EE. The JPA stuff in the EJB 3.0 specification is nice though. It's basically a simplified version of the Hibernate APIs. You do not need to use J2EE bean stuff (session beans, entity beans, hillo beans) for anything, ever.
Can one use Hibernate without a J2EE framework? I've only ever seen it used in J2EE.

Fly
Nov 3, 2002

moral compass

Rocko Bonaparte posted:

Can one use Hibernate without a J2EE framework? I've only ever seen it used in J2EE.
Yes, one can use Hibernate without any J2EE stuff. There's a simple API for managing sessions and transactions that allows you to load and save your objects. I do recommend using some kind of framework to manage the sessions rather than trying to manage them in your application logic.

I am more familiar with the JPA's terminology and API, so I cannot name the Hibernate APIs from memory.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Just quickly looking around, it seems like JDBC should work for the kind of data mining queries I'm doing. It would be hideous if I was doing session logic of some kind, but I'm not.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Fly posted:

You should be able to make some private static methods to generate any of the data that you really need. The chained constructor call must be the first thing there because there is no valid instance state to reference, and the code might try to reference instance state if any instance methods or properties were accessible before the invocation of the other constructor.

In other words, it is easy to express what you really want, so it's not really a problem.

This is usually true, but it breaks down when you want to simultaneously generate multiple values to pass to a different constructor. For that you'll have to either 1) build some sort of temporary tuple object (the construction of which probably won't be optimized out, if you're performance-obsessed) or 2) use a static builder method (which of course can't be used by subclass constructors). Java is unnecessarily restrictive here; the JVM itself is more permissive but still does not allow loops before delegate constructor calls.

Fly
Nov 3, 2002

moral compass

rjmccall posted:

This is usually true, but it breaks down when you want to simultaneously generate multiple values to pass to a different constructor. For that you'll have to either 1) build some sort of temporary tuple object (the construction of which probably won't be optimized out, if you're performance-obsessed) or 2) use a static builder method (which of course can't be used by subclass constructors). Java is unnecessarily restrictive here; the JVM itself is more permissive but still does not allow loops before delegate constructor calls.
The tuple object pattern is what I would typically use as a solution. It is an annoyance more than an problem.

maskenfreiheit
Dec 30, 2004
...

maskenfreiheit fucked around with this message at 03:55 on Sep 29, 2010

chocojosh
Jun 9, 2007

D00D.

GregNorc posted:

This is probably as basic as it gets, but I can't figure out this error.

The code I made compiles fine, but when I try to run it, I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError (filename)/class

I figured maybe it just didn't have the right permissions, so I did a chmod 755 on it. No luck. Thought maybe I had to specify the directory, so I tried ./(filename)

Still no luck.

Any ideas what I'm missing?

How are you trying to run it. I get the impression you're using the command line with javac/java?

Save the code below as file HelloWorld.java

code:

class HelloWorld {
        public static void main(String args[]) {
                System.out.println("Hello World");
        }
}


First compile it using the java compiler. Command: javac HelloWorld.java

Now run it using the java launcher, command: java HelloWorld

Note that it's java HelloWorld, NOT java HelloWorld.class

maskenfreiheit
Dec 30, 2004
...

maskenfreiheit fucked around with this message at 03:55 on Sep 29, 2010

Rekkit
Nov 5, 2006

This is a question in my homework and I don't know what's going on.
True or False, the argument to the method named "substring" is the actual substring that is being searched for.

This is another question, which I answered II and III are true. Can someone confirm or deny and explain?
Which of the following three Java features accurately determine if two String objects are identitical?

I. == operator
II. equals method
III. compareTo method

hexadecimal
Nov 23, 2008

by Fragmaster

Sour Fish posted:

This is a question in my homework and I don't know what's going on.

True or False, the argument to the method named "substring" is the actual substring that is being searched for.

False. Usually substring takes starting index and length. It is usually a member method of a String class and returns part of that string. Otherwise it would just take some string as argument and start and length integers, and return part of that string.

I think this is what you are talking about : http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html#substring(int)

For your second question its both II and III. equals returns true or false, but compareTo is more powerful. It returns 0 if they are equal, -1 if one string is lexicographically before the other, and 1 otherwise.

You should probably get into the habit of using official Javadocs pages that I already linked to. They usually answer such questions right away.

hexadecimal fucked around with this message at 22:25 on Dec 16, 2008

Rekkit
Nov 5, 2006

hexadecimal posted:



Thank you. Could you explain in a little more detail what the first question is asking me? I honestly do not understand the question or the answer.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Lets look at the Java API for the String class.

code:
public String substring(int beginIndex, int endIndex)
          Returns a new string that is a substring of this string.
It has a member method called substring that receives two integers, the beginning offset and the end offset. The question is asking you if the substring method receives the string that will be searched, so it is false.

In order to call this method you have to have an existing String object like so:
code:
String s = "Check this out.";
String sub = s.substring(0,5);
And sub would have the value of "Check"



If the statement in the question were true then in the API there would be a static method in the String class that received a String like so:
code:
public static String substring(String original, int beginIndex, int endIndex)
          Returns a new string that is a substring of original string.
Here is how this hypothetical method would be used:
code:
String sub = String.substring("Check this out",0,5);

Janitor Prime fucked around with this message at 23:19 on Dec 16, 2008

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!
^^ I thought that what the question was referring to was something more like this:

public boolean substring(String sub) - Determines whether the given substring can be found in this string.
Or perhaps:
public int substring(String sub) - returns the starting index where the substring can be found in this string, or else -1;

Thus, this would return true or 8, depending on which function existed:
code:
"Check this out.".substring("is");
However, it definitely does not work that way.

Bastard
Jul 13, 2001

We are each responsible for our own destiny.
Has anybody taken a look yet at JavaFX? Any opinions so far?

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
Is there a way to convert the RGB value of a BufferedImage pixel into hex? Alternatively, can the value of a pixel be gotten and set using hex?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Ensign Expendable posted:

Is there a way to convert the RGB value of a BufferedImage pixel into hex? Alternatively, can the value of a pixel be gotten and set using hex?

There are methods getRGB and setRGB to access individual pixels using the standard ARGB color space. There are, however, exactly zero methods to access the value of a pixel in "hex", because that is meaningless.

lamentable dustman
Apr 13, 2007

🏆🏆🏆

RGB is already hex. FF = 255 F0 = 240

If it is really important extend the class or something and make a function to take a string or hex number, parse to separate the color pairs, make them ints, and pass to the real setColor (or whatever it is).

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
Oh, ok. I just wanted to know if there was an easier way of doing it that dvinnen said.

Mill Town
Apr 17, 2006

Ensign Expendable posted:

Oh, ok. I just wanted to know if there was an easier way of doing it that dvinnen said.

It's fairly straightforward.

BufferedImage im = whatever;

String hexString = Integer.toHexString( im.getRGB(x, y) ).toUpper();

maskenfreiheit
Dec 30, 2004
...

maskenfreiheit fucked around with this message at 03:55 on Sep 29, 2010

sonic bed head
Dec 18, 2003

this is naturual, baby!

GregNorc posted:


code:
                if (x > 2); 

What's that semicolon doing there?

maskenfreiheit
Dec 30, 2004
Edit: Double Post

maskenfreiheit fucked around with this message at 21:31 on Mar 13, 2017

Lurchington
Jan 2, 2003

Forums Dragoon
Don't know if it's kosher here, but I've been involved in a work project using Scala

And coming from a C/C++ and Python background, I'm liking it alright.


Was just wondering if anyone's writing with scala, and if so, what IDEs and environments are you developing with. We're a very Emacs shop, but I guess I'm more used to a "traditional" IDE.

zootm
Aug 8, 2006

We used to be better friends.

Lurchington posted:

Was just wondering if anyone's writing with scala, and if so, what IDEs and environments are you developing with. We're a very Emacs shop, but I guess I'm more used to a "traditional" IDE.
I use Scala a lot at home (I really like the language), but a lot of the IDE stuff can be a little immature. The recommended route is to go for the official Eclipse plugin you can get off the website if you want the best features and integration, but I personally like (and use) the Netbeans plugin, mostly since I quite like Netbeans. It can be a little buggy, however.

lamentable dustman
Apr 13, 2007

🏆🏆🏆

So I've been working on this applet/servlet combo for a while now. The applet communicates with a servlet that collects data and sends it back to the applet via HttpsURLConnection. I'm using an unsigned cert for now as everything is on my dev machine.

Everything was running good till I updated the Java version today and the applet started throwing "java.security.AccessControlException: access denied (java.net.SocketPermission localhost:8443 connect,resolve)

So far I've tried editing my java.policies file, disabling my firewall (though everything is local). I don't think it has to do with my cert as I can reach https://localhost:8443/, everything is encrypted. Also, when I first started using SSL with the applet I was getting different, more descriptive errors till I fixed it.


The code where it gets thrown is basically this:

code:
URL url = new URL("https://localhost:8443/WARFile/servletName");

HttpsURLConnection = (HttpsURLConnection) url.openConnection();
   conn.setDoOutput(true);
   conn.setDoInput(true);

OutputStream out = conn.getOutputStream();

ObjectOutputStream oos = new ObjectOutputStream(out);
The error gets thrown where 'out' is declared

edit: does the applet have to be signed or something? I'm not modifying anytihng on the client's system but I am connecting to something out of it's domain I guess. Like I said, it worked fine with 1.5 so I guess security is tighter in 1.6

lamentable dustman fucked around with this message at 23:03 on Dec 29, 2008

firetech
Oct 26, 2005

Bastard posted:

Has anybody taken a look yet at JavaFX? Any opinions so far?
I like how Johnathan Schwartz tries to butter it up by saying that other competitive technology companies are trying to conquer the internet with their "hostile browsers" while he obviously is seeking the same domination himself by 'liberating' content owners into his own Java world.

Still, I wont be surprised if there is a FlickrFX or FacebookFX prototype a few years down the line.

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug

dvinnen posted:

So I've been working on this applet/servlet combo for a while now. The applet communicates with a servlet that collects data and sends it back to the applet via HttpsURLConnection. I'm using an unsigned cert for now as everything is on my dev machine.

Everything was running good till I updated the Java version today and the applet started throwing "java.security.AccessControlException: access denied (java.net.SocketPermission localhost:8443 connect,resolve)

So far I've tried editing my java.policies file, disabling my firewall (though everything is local). I don't think it has to do with my cert as I can reach https://localhost:8443/, everything is encrypted. Also, when I first started using SSL with the applet I was getting different, more descriptive errors till I fixed it.


The code where it gets thrown is basically this:

code:
URL url = new URL("https://localhost:8443/WARFile/servletName");

HttpsURLConnection = (HttpsURLConnection) url.openConnection();
   conn.setDoOutput(true);
   conn.setDoInput(true);

OutputStream out = conn.getOutputStream();

ObjectOutputStream oos = new ObjectOutputStream(out);
The error gets thrown where 'out' is declared

edit: does the applet have to be signed or something? I'm not modifying anytihng on the client's system but I am connecting to something out of it's domain I guess. Like I said, it worked fine with 1.5 so I guess security is tighter in 1.6

You're missing a variable name. Shouldn't it be
code:
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
   conn.setDoOutput(true);
   conn.setDoInput(true);

lamentable dustman
Apr 13, 2007

🏆🏆🏆

Ensign Expendable posted:

You're missing a variable name. Shouldn't it be
code:
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
   conn.setDoOutput(true);
   conn.setDoInput(true);

whoops, it is there in the real code. The code is on a secure system that can't reach the internet so I couldn't c/p it.

Eclipse would of caught that pretty fast anyways.

lamentable dustman
Apr 13, 2007

🏆🏆🏆

I figured it out, it was an issue with java versions. I've been using the Eclipse plugin 'Web Tools Platform' which had a section called 'facets' that needed the compiler level changed in. I was getting an error from it apparently but didn't notice, it looked like it was compiling anyways.

mister_gosh
May 24, 2002

I need to work in java fulltime so I won't forget some of these basics. I appreciate any feedback you may have.

I'm trying to run a class, which is not UI based at all. If a certain situation occurs, however, I want to serve a popup from a different class. I'm not quite grasping why it won't work.

code:
if(!message.equalsIgnoreCase("success")) {
            
   ProblemUI pui = new ProblemUI();
   pui.serveMessage(title, message);
         
} else { 
   // do something
}
code:
public class ProblemUI extends javax.swing.JFrame {
    
    public ProblemUI() {
        initComponents();
    }
    
    public void serveMessage(String title, String msg) {
        
        jLabel1.setText(title);     
        jLabel2.setText(msg);
                
    }

    private void initComponents() { 
        // Netbeans generated code...
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ProblemUI().setVisible(true); // want this to be 
                                                  // false but not sure
                                                  // how to set it to 
                                                  // true in serveMessage
            }
        });
    }

}

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
The outside code is creating a new instance of ProblemUI, but that instance is never made visible. Meanwhile, you have a main method in ProblemUI which creates an instance and makes it visible, but that method presumably never gets called. Where are you getting confused?

Fehler
Dec 14, 2004

.
Does anybody know where I could find sample code for comparing two WAV audio streams in Java? I need a function that returns some kind of "score" telling me how well the two streams match. From what I found on Google it looks like I need to do a Fourier Transformation, but I'm not really sure how to implement that and how to use it.

Fly
Nov 3, 2002

moral compass

Fehler posted:

Does anybody know where I could find sample code for comparing two WAV audio streams in Java? I need a function that returns some kind of "score" telling me how well the two streams match. From what I found on Google it looks like I need to do a Fourier Transformation, but I'm not really sure how to implement that and how to use it.
I would start reading about Fourier transforms. They convert a time-domain signal, such as a PCM (pulse-code-modulation) signal, into the frequency domain. You may also want to look at transforms like the Modified Discrete Cosine Transform (MDCT) which do about the same thing, but may be more useful as you may find more examples of other transforms used by, say MP3 or OGG Vorbis codecs.

Once you transform the WAV, you can compare the frequencies present over time, probably vaguely similarly to the way you would compare strings in a string search algorithm that allowed for some inexactness.

There's an iPhone and Android app that does this and tells you what song you are sampling with the phone's microphone.

firetech
Oct 26, 2005

mister_gosh posted:

I need to work in java fulltime so I won't forget some of these basics. I appreciate any feedback you may have.

I'm trying to run a class, which is not UI based at all. If a certain situation occurs, however, I want to serve a popup from a different class. I'm not quite grasping why it won't work.

In addition to what rjmccall said, you have to declare all of your UI elements at the level of the class to access them from other methods. I don't use NetBeans (plus you cut up your code), but it looks like all of the UI components (i.e. jLabel1 and jLabel2) are being declared at the level of the initComponents() method. Google 'variable scope' if you need more information.

Also, you might just want to bag all of that code and replace it with this method:
code:
public static void serveMessage(String title, String message) {
	javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(title), message);
}



QUESTION:
I'm using Gregory Guerin's AuthKit to 'authenticate' (a.k.a. run with elevated privileges) my new java application in Mac OS X. I cannot figure out how to authenticate the currently running app though. All I can do is launch another jar file with elevated privs. Is there a way to privilege the currently running java app?

firetech fucked around with this message at 08:09 on Dec 31, 2008

Adbot
ADBOT LOVES YOU

Fly
Nov 3, 2002

moral compass

firetech posted:

QUESTION:
I'm using Gregory Guerin's AuthKit to 'authenticate' (a.k.a. run with elevated privileges) my new java application in Mac OS X. I cannot figure out how to authenticate the currently running app though. All I can do is launch another jar file with elevated privs. Is there a way to privilege the currently running java app?
Are you asking how to make your application run with elevated privileges when your application starts, or are you wanting to change the privileges of an already-running application? The former is accomplished by signing your code, etc.. The former is not really possible unless you had started your code with an AccessControlContext that has some special ProtectionDomain to which you retain a reference and you alter at runtime.

edit: Probably nevermind what I wrote. Authkit seems to have little to do with Java security but instead with Mac OS X security, i.e., running with root privileges.

Fly fucked around with this message at 05:16 on Jan 1, 2009

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply