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
zootm
Aug 8, 2006

We used to be better friends.
I didn't see one of these in the generic thread, so I guess it's just a matter of time.

Here's a thread for small questions relating to everyone's favourite programming language, Java. Chuck your questions up here.

:siren: Attention! Java is not JavaScript :siren:
Despite their similar names the languages are hugely different; questions relating to JavaScript should be directed to the Web Development Megathread

I'm going to follow this with a post on IDEs/tools/etc. Anyone who wants stuff added to that post or contact me or whatever.

zootm fucked around with this message at 18:57 on May 21, 2008

Adbot
ADBOT LOVES YOU

zootm
Aug 8, 2006

We used to be better friends.
Hefty information post
Here's the promised post on tools.

IDEs
A quick note on IDEs: Java is very verbose, so autocompletion is handy when working on it for any period of time. Luckily Java has some really great IDEs handy:

NetBeans IDE - Open source, developed primarily by Sun. Gets a lot of features based around whatever Sun is currently pushing, uses Ant as its package format (meaning it's easy to run your build remotely) and has a really nice GUI editor, along with excellent support for Ruby on Rails should you decide to run, screaming, from Java at some point. Also comes with a fairly good profiler which I would recommend more highly if it hadn't crashed and burned when I was trying to profile something over a transatlantic link the other day.

Eclipse - Another open source IDE, a little bit more flexible than NetBeans, but does more stuff for you. This was clearly better than NetBeans for a long time so this is what most teams use these days. Has a huge wealth of plugins (of variable quality) for the various frameworks available for Java. Also Bubblegum Wishes recommends this series of videos teaching Java from the ground up using Eclipse.

IntelliJ IDEA - Costs money, but pretty much nobody who tries it ever goes back. I've not used it, but I don't think I've ever heard a negative review.

Another note, though - it might be worth learning Java without these tools. They do a lot for you, and you will miss out on a lot of the subtleties of how Java works.

Finding problems
Debuggers and profilers (all of the tools above have at least the former), as with most languages, can be invaluable in finding Java problems. It's always worth knowing how your dependencies work, too, since it's the cause of a lot of misconceptions.

Preventing problems
Another tip is to use FindBugs to find common errors in your code. It may give you a lot of "false" positives, but if you keep your code clean you get a much nicer protection against the dumb mistakes that we all make sometimes than you get from "it compiles". I've run this ever since spending 2 hours with a workmate trying to find the cause of weird behaviour which turned out to be caused by someone doing == comparison on a boxed integer value (:eng101: this doesn't do what it looks like it does).

For those of you who like to be doubly paranoid, PMD does this sort of job too. PMD works on source code (rather than compiled bytecode) though, which makes it a whole bunch easier to, among other things, add your own rules. This gives you the freedom to add a check on something you know you do a lot, which is handy. It's probably for more-advanced or -paranoid users to run both, though, and FindBugs will likely be easier and more productive if you only want to use one. :)

Also, run your compiler with the "-Xlint" flag. This turns on all the warnings. This is a good thing. If you look at your code and see a warning that you decide is unwarranted (sadly there are some things that just don't work well with generics without warnings), you can add the @SuppressWarnings( "warningType" ) annotation to the method in questions, but do not do this until you are confident you understand the reason for the warning.

Your code should be clean of warnings from both the compiler and FindBugs, unless you have a drat good reason to the contrary. :argh:

zootm fucked around with this message at 13:26 on Jul 15, 2009

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
I'd like to post that everyone who uses Java to make money should know how both .equals() and .hashCode() work. You can find numerous guides online, plus Joshua Bloch's Effective Java goes into great detail about these methods. I won't get into it here to avoid a huge poo poo post, but here are some links:

http://www.geocities.com/technofundo/tech/java/equalhash.html
http://www.ibm.com/developerworks/java/library/j-jtp05273.html

a good reason why you should know your poo poo:
http://www.hibernate.org/109.html

Also, understand the ramifications of having immutable Strings. A lot of people I've worked with don't understand the concept of immutable Strings and don't know a reason for using StringBuilder other than "you just do." What the gently caress. Also available in numerous online resources or by reading Effective Java.

IntelliJ is really nice. Eclipse is ok if you are willing to put up with its poo poo. Someone likened it to Mac vs PC. If you want something that just works, use IntelliJ, if you like to tinker, go with Eclipse. I haven't used NetBeans enough to say if it's good or bad, all I'm sure of is that Sun is really pushing JRuby so their ruby support is very good.

Leehro
Feb 20, 2003

"It's a gaming ship."
Glad to see this thread here. It looked like java was dead based on the activity in this forum. I didn't start writing java until about a year ago, and started using an IDE just a few months ago. I started with Eclipse because I read about its tomcat plugin. It absolutely blew my mind that I could run a webapp in tomcat, play around on my browser, and be debugging it in eclipse.

When I had to write a GUI application, I switched to NetBeans 6.0, which I absolutely love. It seems cleaner and simpler than Eclipse, and the GUI designer is terrific. I'm also very pleased with the subversion integration (showing changes) and the build configurations and how it creates a "dist" directory complete with a README and all of your JARs in a lib folder.

So no questions now, but I'm sure I'll have one soon.

csammis
Aug 26, 2003

Mental Institution
Can one use IntelliJ or Netbeans if they're developing Java RCP applications that target the Eclipse framework itself, or does that lock one into having to use Eclipse? I'm doing this at work, but I can't friggin' stand Eclipse. It's slower than an rear end in a hat.

Mista _T
Nov 11, 2000

Mix it with Curly and Larry and Moe, WOOP-WOOP WOOP-WOOP WOOP hey, YO!

csammis posted:

Can one use IntelliJ or Netbeans if they're developing Java RCP applications that target the Eclipse framework itself, or does that lock one into having to use Eclipse? I'm doing this at work, but I can't friggin' stand Eclipse. It's slower than an rear end in a hat.

I'd assume if it were making calls into the framework library, then you are pretty much stuck with Eclipse. If it were making calls into a library that acts as an intermediary framework between the plugin and the IDE, then it could be ported, but I have no idea if such a platform exists.

zootm
Aug 8, 2006

We used to be better friends.

csammis posted:

Can one use IntelliJ or Netbeans if they're developing Java RCP applications that target the Eclipse framework itself, or does that lock one into having to use Eclipse? I'm doing this at work, but I can't friggin' stand Eclipse. It's slower than an rear end in a hat.
Running Java 6 makes a big difference to performance, other than that I've not had a huge problem with Eclipse. I imagine you'll be missing a lot of tools if you try to do this sort of project outside of Eclipse but it's unlikely it's genuinely impossible.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

csammis posted:

Can one use IntelliJ or Netbeans if they're developing Java RCP applications that target the Eclipse framework itself, or does that lock one into having to use Eclipse? I'm doing this at work, but I can't friggin' stand Eclipse. It's slower than an rear end in a hat.
Apparantly you can: http://www.jetbrains.com/idea/documentation/usingIDEAforEclipse.html

I don't know how well it'll work, though. It'd be wise to not wipe Eclipse before you try it out for a week or so, despite how tempting it is.

Spartan22x
Dec 22, 2006

by Fragmaster
I'm having problems getting the visual editor working in eclipse on OS X. Has anyone in here gotten it to work or do you have any tips to try to get it working? I tried installing it through Help->Software Updates->Find and install, using the Graphical Editing Framework server option thing. It didn't work, as I can't see any graphical editing tools anywhere in eclipse. This same method, however, DID work for the Ruby tools and the C/C++ tools. So, does anyone know how I can fix this? I may need it for some programming projects for class later on this semester, and I'd like to have it working by then.

Belgarath
Feb 21, 2003
Not strictly a Java question, but, does anyone know if Eclipse has anything similar to visual studio's #region ?

zootm
Aug 8, 2006

We used to be better friends.

Belgarath posted:

Not strictly a Java question, but, does anyone know if Eclipse has anything similar to visual studio's #region ?
Yes, but you need a plugin. If you grab the "code folding" plugin from the update centre described on this page, you can do it by going to Preferences... Java/Editor/Folding, change to use the "Coffee-Bytes" folding implementation, enabling the "user-defined" folds, and then entering folds like this:
code:
// [start] Blah blah blah
private int thisIsJustCode;
// [end]
You might need to reload any open editors to see the change. You can customise the start and end text if you want, as well.

Incidentally this feature is available by default on Netbeans which uses an XML syntax like this:
code:
// <editor-fold desc="Blah blah blah">
private int thisIsJustCode;
// </editor-fold>
:)

FuzzyBuddha
Dec 7, 2003

Stupid IDE question....

I've been using JCreator LE, another free Java IDE, and, other than plain text editors, the only thing I've used for Java programming. I'm almost ashamed to admit that I haven't played around with any others. It's just been a "it's what I downloaded first, so that's what I use" kinda thing.

What benefits do the others have and how does JCreator rank among the others?

zootm
Aug 8, 2006

We used to be better friends.
I'm not sure about JCreator since I've never used it, and the other ones are basically like I noted in the second post of this thread; is there anything specific you'd like to know?

Sym
Feb 22, 2006
Where am I?

FuzzyBuddha posted:

Stupid IDE question....

....

What benefits do the others have and how does JCreator rank among the others?

Well first and foremost, JCreator is Windows only. All the others are cross compatible.

From a Windows user point of view JCreator is nice since its written in C++ and has a very fast clean interface. The debugger is also very well done, similar to the .NET debugger.

The downsides are fairly large, It doesn't do code completion unless you purchase the pro version, it only connects to a CVS repository (no SVN support), No drag/drop GUI creator, and it doesn't have the ability for plugins.

Not supporting plugins is what really hurts it. Simple things like debugging a JSP, or Servlet which is pretty straight forward in the other IDE's just isn't possible with JCreator.

As someone who has paid for the professional version of JCreator, I wish I had put the money into IntelliJ.

Leehro
Feb 20, 2003

"It's a gaming ship."

FuzzyBuddha posted:

Stupid IDE question....

I've been using JCreator LE, another free Java IDE, and, other than plain text editors, the only thing I've used for Java programming. I'm almost ashamed to admit that I haven't played around with any others. It's just been a "it's what I downloaded first, so that's what I use" kinda thing.

What benefits do the others have and how does JCreator rank among the others?

after a quick look at the features of JCreator Lite, I can point out a few things that NetBeans has that it doesn't:

Code Completion
Context-sensitive help
Debugger
bean methods wizard

There's a lot more. NetBeans seems more friendly whether you started your application there or you're working from existing sources. It creates ant build scripts for you. The refactoring is incredibly useful -- whether you want to rename a class/package or easily add get/set (bean) methods to something. The javadoc popups and code completion have really been useful. It just makes a lot more sense than any other IDE I've used.

Plus it's cross platform, free, and works with some other languages. There are a lot of plugins too, and I think it's less cluttered than Eclipse.

Try NetBeans for a day or even an hour. It's easy to get up and running.

icehewk
Jul 7, 2003

Congratulations on not getting fit in 2011!
edit: see next post

icehewk fucked around with this message at 05:59 on Feb 26, 2008

icehewk
Jul 7, 2003

Congratulations on not getting fit in 2011!
After six weeks of my first programming course, I know absolutely nothing. The instructor doesn't teach along with the book, nor does he teach much of the ideas behind the code. To borrow a lovely analogy, it's like he goes over what you can nail where without explaining where the spot to be nailed is located or why it's being nailed. As such, I've taken it upon myself through the resources provided here to learn Java outside of class and hope I can catch up before the next project is assigned. Unfortunately, my latest project is due Wednesday and I don't know where to begin. Can you guys help?

quote:

CS 172
Project 2 (due February 27/28)

Develop and test a RationalNumber class that allows exact fraction arithmetic (floating-point arithmetic is approximate). We will enhance this class in Project 3 so that, among other things, RationalNumber objects always store fractions reduced to lowest terms. RationalNumber’s should follow the same rules about writing and doing arithmetic with fractions that you learned about in fifth grade. Your RationalNumber class should behave as illustrated by the code in the following test driver and the output that is generated by running that driver. You should develop and test the class one feature at a time (use a short code-test-debug cycle so that you are never more than a few lines of code away from working Java code), using statements like those in the driver below, adding and testing features approximately in the order suggested by the driver:
code:
public class Project3Driver {
  
  public static void main(String[] args) {
    RationalNumber r1 = new RationalNumber(4, 6);
    System.out.println("r1 = " + r1); // equivalent to "r1 + " + r1.toString()
    RationalNumber r2 = new RationalNumber(-3, 1);
    System.out.println("r2 = " + r2); 
    RationalNumber r3 = new RationalNumber(0, 5);
    System.out.println("r3 = " + r3); 
    RationalNumber r4 = new RationalNumber(1, -3);
    System.out.println("r4 = " + r4); 
    RationalNumber r5 = new RationalNumber(-1, -3);
    System.out.println("r5 = " + r5);
    //RationalNumber r6 = new RationalNumber(-2, 0); // generates error
    						// message and exits the application
    RationalNumber r7 = new RationalNumber(-2, -3);
    
    RationalNumber threeFourths = new RationalNumber(3, 4);
    RationalNumber fiveSixths = new RationalNumber(5, 6);
    System.out.println("3/4 + 5/6 = " + threeFourths.plus(fiveSixths));
    System.out.println("3/4 - 5/6 = " + threeFourths.minus(fiveSixths));
    System.out.println("3/4 * 5/6 = " + threeFourths.times(fiveSixths));
    System.out.println("3/4 / 5/6 = " + threeFourths.dividedBy(fiveSixths));
    RationalNumber oneFourth = new RationalNumber(1, 4);
    System.out.println(Math.pow(16, -oneFourth.doubleApproximation()));
    
    System.exit(0);   // This is superfluous here but necessary if
                      // if the application uses swing components
  }

}
Output:

r1 = 4/6
r2 = -3
r3 = 0
r4 = 1/-3
r5 = -1/-3
3/4 + 5/6 = 38/24
3/4 - 5/6 = -2/24
3/4 * 5/6 = 15/24
3/4 / 5/6 = 18/20
0.5

The following gives a skeleton version of the RationalNumber class with some hints to help you supply the missing code.
code:
public class RationalNumber {

  // data

  private int numerator;
  private int denominator;
  

  // constructors

  public RationalNumber(){
    numerator = 0;
    denominator = 1;
  }
  
  public RationalNumber(int numeratorIn, int denominatorIn){
    if (denominatorIn == 0){
      System.out.println("Denominator can't be zero");
      System.exit(0);
    }
    numerator = numeratorIn;
    denominator = denominatorIn;
    //if (numerator != 0)   WE’LL ADD THIS IN PROJECT 3
    //  reduce();
  }
  

  // public methods
  
  public String toString(){
    // include code here that handles the cases where numerator = 0 or 
    // denominator = 1 
  }
  
  public RationalNumber plus(RationalNumber r){
    //  just think of the rules for adding fractions
  }
  
  public RationalNumber times(RationalNumber r){
    //  just think of the rules for multiplying fractions
  }
  
  public RationalNumber dividedBy(RationalNumber r){
    
    if (r.numerator == 0){
      throw new ArithmeticException();
    }
    else{
      // use the fact that division is multiplication by the inverse 
    }
  }
  
  public RationalNumber minus(RationalNumber r){
    // just think of the rules for subtracting fractions    
  }
  
  
  public double doubleApproximation(){
    // just divide numerator by denominator.  Make sure it’s floating-point
    // division.
  }
  
} // class RationalNumber

fret logic
Mar 8, 2005
roffle
Hmm I was thinking about that program in the shower from what you posted in the other thread, and it looks a bit different from what I thought it would be. When I was thinking of the addition, I was implementing reducing to the lowest terms. This looks like it just multiplies the denominators and leaves it like that.

Just curious though, would a feature to keep people from entering fractions that would become complex use the modulus operator?

1337JiveTurkey
Feb 17, 2005

icehewk posted:

After six weeks of my first programming course, I know absolutely nothing. The instructor doesn't teach along with the book, nor does he teach much of the ideas behind the code. To borrow a lovely analogy, it's like he goes over what you can nail where without explaining where the spot to be nailed is located or why it's being nailed. As such, I've taken it upon myself through the resources provided here to learn Java outside of class and hope I can catch up before the next project is assigned. Unfortunately, my latest project is due Wednesday and I don't know where to begin. Can you guys help?

OK. With objects, what you're doing is describing their behavior, so that if you've got r1 and you add it to r2, you explain how the sum is found with plus(). I'll show you how to make an invert() function, something which isn't part of your assignment but is useful for a RationalNumber class. In order to invert a number, we make its numerator equal to the denominator and the denominator equal to the numerator.

code:
public class RationalNumber {
  // Other stuff is up here
  public void invert() {
    // If the reason for temp isn't clear, work out why by hand
    int temp = numerator;
    numerator = denominator;
    denominator = temp;
  }
}
This says whenever we have an object which is a RationalNumber, we can invert it by switching the numerator and denominator. In the case of an object r1, you'd do so by calling r1.invert(); In the assignment, the instructor wants you to do this for addition, subtraction, multiplication and division. However, since these have two numbers, you refer to the second number as r in the function, and its numerator and denominator are r.numerator and r.denominator respectively. Are there any specific problems you're having?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

fret logic posted:

When I was thinking of the addition, I was implementing reducing to the lowest terms. This looks like it just multiplies the denominators and leaves it like that.

It says in the instructions that in the next project they will reduce the fraction to it's lowest terms. For now it's enough that they just keep multiplying the denominator.

Incoherence
May 22, 2004

POYO AND TEAR

icehewk posted:

After six weeks of my first programming course, I know absolutely nothing. The instructor doesn't teach along with the book, nor does he teach much of the ideas behind the code. To borrow a lovely analogy, it's like he goes over what you can nail where without explaining where the spot to be nailed is located or why it's being nailed. As such, I've taken it upon myself through the resources provided here to learn Java outside of class and hope I can catch up before the next project is assigned. Unfortunately, my latest project is due Wednesday and I don't know where to begin. Can you guys help?
From the skeleton given, basically all you need is to implement plus(), minus(), times() and dividedBy(). That greatly simplifies your problem.

Let's walk through plus(): First, how do you add fractions? If you have two fractions a/b and c/d, what is their sum in terms of a, b, c, and d? Second, which field of which object corresponds to a, b, c, and d?

fret logic
Mar 8, 2005
roffle

MEAT TREAT posted:

It says in the instructions that in the next project they will reduce the fraction to it's lowest terms. For now it's enough that they just keep multiplying the denominator.

Yeah, I was jus' sayin.

icehewk
Jul 7, 2003

Congratulations on not getting fit in 2011!

Incoherence posted:

Let's walk through plus(): First, how do you add fractions? If you have two fractions a/b and c/d, what is their sum in terms of a, b, c, and d? Second, which field of which object corresponds to a, b, c, and d?

It would be a+c when b=d. How would you go about finding the LCD? Is the data field the part that corresponds to a, b, c and d?

1337JiveTurkey
Feb 17, 2005

icehewk posted:

It would be a+c when b=d. How would you go about finding the LCD? Is the data field the part that corresponds to a, b, c and d?

Don't worry about least for the moment, just common.

horse_ebookmarklet
Oct 6, 2003

can I play too?
Given the following conditions:
code:
		double anArray[] = {9.2, 9.3, 9.0, 9.9, 9.5, 9.5, 9.6, 9.8};
		double lowest = 10, highest = 0, sum = 0, fin;
		for(int i = 0; i < anArray.length; i++) {
			if(anArray[i] < lowest) { lowest = anArray[i]; }
			if(anArray[i] > highest) { highest = anArray[i]; }
			sum = sum + anArray[i];
		}
		fin = (sum - highest - lowest);
		System.out.println( fin );
fin is equal to 56.90, but the application prints 56.89999999999999; Is this due to a quirk in Java's System.out class? What should I do in a case such as this when I want to print a double?

Incoherence
May 22, 2004

POYO AND TEAR

icehewk posted:

It would be a+c when b=d. How would you go about finding the LCD? Is the data field the part that corresponds to a, b, c and d?
No, if b = d, then it'd be (a+c)/b. I'm being pedantic here for a reason: this isn't a Java problem, but an algorithmic problem, and if you can't specify how to add fractions algebraically how do you expect to tell the computer how to?

And, as previously mentioned, don't worry about the LCD. Look at the example output for a hint as to what denominator the result should have.

NotHet posted:

Given the following conditions:
code:
		double anArray[] = {9.2, 9.3, 9.0, 9.9, 9.5, 9.5, 9.6, 9.8};
		double lowest = 10, highest = 0, sum = 0, fin;
		for(int i = 0; i < anArray.length; i++) {
			if(anArray[i] < lowest) { lowest = anArray[i]; }
			if(anArray[i] > highest) { highest = anArray[i]; }
			sum = sum + anArray[i];
		}
		fin = (sum - highest - lowest);
		System.out.println( fin );
fin is equal to 56.90, but the application prints 56.89999999999999; Is this due to a quirk in Java's System.out class? What should I do in a case such as this when I want to print a double?
It's a floating point quirk. If you HAVE to have 56.9 for some reason, round it.

Incoherence fucked around with this message at 20:39 on Feb 26, 2008

horse_ebookmarklet
Oct 6, 2003

can I play too?

Incoherence posted:

It's a floating point quirk. If you HAVE to have 56.9 for some reason, round it.
Well then this becomes irritating on two levels. I guess I can sorta understand a floating point quirk in Java, but why the hell did Eclipse decide to be inconsistent and represent the value as 56.9 in it's debugger? Oh well. Thanks for the help!

Fly
Nov 3, 2002

moral compass

NotHet posted:

Well then this becomes irritating on two levels. I guess I can sorta understand a floating point quirk in Java, but why the hell did Eclipse decide to be inconsistent and represent the value as 56.9 in it's debugger? Oh well. Thanks for the help!
Most people must readjust their expectations when using fixed precision floating point numbers, such as the IEEE 754 implementation Java has. There are rounding issues because it is impossible to represent some decimal values exactly in such floating point representations.

http://www.ibm.com/developerworks/java/library/j-jtp0114/

icehewk
Jul 7, 2003

Congratulations on not getting fit in 2011!

Incoherence posted:

No, if b = d, then it'd be (a+c)/b. I'm being pedantic here for a reason: this isn't a Java problem, but an algorithmic problem, and if you can't specify how to add fractions algebraically how do you expect to tell the computer how to?

So what would I write to find the common denominator? I really don't understand much of the actual language beyond syntax and reference.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Fly posted:

Most people must readjust their expectations when using fixed precision floating point numbers, such as the IEEE 754 implementation Java has. There are rounding issues because it is impossible to represent some decimal values exactly in such floating point representations.

http://www.ibm.com/developerworks/java/library/j-jtp0114/

You can also try BigDecimal if you don't need balls to the wall arithmetic performance.

Incoherence
May 22, 2004

POYO AND TEAR

icehewk posted:

So what would I write to find the common denominator? I really don't understand much of the actual language beyond syntax and reference.
We're not even talking about the language here. How would you do it if you were just writing an algebraic formula?

icehewk
Jul 7, 2003

Congratulations on not getting fit in 2011!
Seems the uni knows how tough the class is so they provide a free tutor three times a week. Algebraically, a/b and c/d would require b*d and d*b along with a*d and c*b. That would be (a*d)+(c*b) over (b*d), right?

icehewk fucked around with this message at 00:15 on Feb 27, 2008

Incoherence
May 22, 2004

POYO AND TEAR

icehewk posted:

Seems the uni knows how tough the class is so they provide a free tutor three times a week. Algebraically, a/b and c/d would require b*d and d*b along with a*d and c*b. That would be (a*d)+(c*b) over (b*d), right?
Yeah, that. Check that against their example; you should get exactly the same thing they do.

Okay, now that's step 1. Step 2 is to figure out how to express each of a, b, c, and d in terms of the two objects.
code:
  public RationalNumber plus(RationalNumber r){
    //  just think of the rules for adding fractions
  }
Your choices are numerator, denominator, r.numerator, and r.denominator. Then just substitute those four names into the algebraic formula you already have, and test it.

icehewk
Jul 7, 2003

Congratulations on not getting fit in 2011!
Got it, thanks a ton. :)

csammis
Aug 26, 2003

Mental Institution
Java 1.5:

I'm trying to figure out how to load a text file contained inside my program's JAR (into a FileReader if that matters). java.util.ResourceBundle was the first place I looked, but it seems to want to split the file into key/value pairs and that's not what I'm going for.

The JAR layout:
code:
src
  main
   +java
   |  various
   |    folders
   |      seriously
   |        ridiculously
   |          deep
   |            OhHereItIs.java
   +resources
      myfile.txt
How can I address this file? I know next to nothing about Java IO :smith:

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome

csammis posted:

Java 1.5:

I'm trying to figure out how to load a text file contained inside my program's JAR (into a FileReader if that matters). java.util.ResourceBundle was the first place I looked, but it seems to want to split the file into key/value pairs and that's not what I'm going for.

The JAR layout:
code:
src
  main
   +java
   |  various
   |    folders
   |      seriously
   |        ridiculously
   |          deep
   |            OhHereItIs.java
   +resources
      myfile.txt
How can I address this file? I know next to nothing about Java IO :smith:

Class.getResource() and friends will get you a file if it's on your classpath. So, in your example:

code:
URL myErl = Class.getResource("myfile.txt");
should work ok. You won't be able to write to it, IIRC.

Leehro
Feb 20, 2003

"It's a gaming ship."
Does anyone have a quick tutorial or example for one of the EE persistence APIs? Everything I come across seems to be part of some framework.

zootm
Aug 8, 2006

We used to be better friends.

rotor posted:

You won't be able to write to it, IIRC.
Yeah, the classpath is essentially read-only (which I think makes a lot of sense, considering).

Leehro posted:

Does anyone have a quick tutorial or example for one of the EE persistence APIs? Everything I come across seems to be part of some framework.
You know, I don't think I've seen the javax.persistence stuff being used without Hibernate, but I'm aware it can be done. This tutorial seems pretty generic as regards the API, other than the fact that it's based on Glassfish for setting stuff up. They're using Toplink there which affects the configuration (as you'd expect it to), all the stuff mentioned works in Hibernate too, as far as I'm aware.

Other than that the Javadoc for the API is actually pretty good.

roadhead
Dec 25, 2001

I have a receipt printer, connected to a cash drawer that takes plain text input (with special control characters for drawer popping and paper cutting) outputting formatting receipts in my software.

The catch is I have to support a variety of printers with different control codes (easy), widths (harder) and demonic possessions (hardest).

So what I'm looking for is an easy way to use an existing layout language (LaTeX, HTML, etc.) to layout a document that eventually is put into a String on which getBytes() is called and 100% plain vanilla already formatted text with the right column alignment and justifications.

I'm leaning heavily towards either HTML or some horrible hack of ReportMill - but I'm open to ideas and conjecture, as I've got a little while to think about this.


I'll be storing the "templates" in the database and they're accessed from just a plain text field, since thats how they end up when sent to the printer :/

Adbot
ADBOT LOVES YOU

Scinon
Jul 23, 2006
Now with 2% more atoms!

roadhead posted:

I have a receipt printer...

Interestingly enough I have been messing around with a receipt printer that I got from a friend. It uses a serial connection with a cash drawer, but can use any old serial connection. I use rxtx for the serial communication by the way. ( http://users.frii.com/jarvi/rxtx/ )

The code was modified from examples from Sun and various other sources. It sends a string to the printer and then sends the print command (0x0D on my printer) to print the buffer.
http://snipplr.com/view/5264/comm-write/

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