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
Mill Town
Apr 17, 2006

dvinnen posted:

yea, i know that of course, but judging by the fact that the instructor wants him to implement the Comparable interface I think he is suppose to roll his own

Good question! JulianD, can you post the whole assignment, please, so we know how in-depth the problem really is?

Adbot
ADBOT LOVES YOU

JulianD
Dec 4, 2005

dvinnen posted:

As for how to implement the function, nobody is going to do your homework but here is a hint. What primitive type makes up a String object? And what other kind of primitive type can it be represented as?

I know no one is going to do my homework for me, and I wasn't asking anyone to; I was only expressing confusion at the vagueness of Mill Town's hint. Anyway, I think I've figured it out now:

code:
public int compareTo(Object pass)
{
  Passenger pass2 = (Passenger) pass;
  if(last_name.compareTo(pass2.last_name)==0)
  {
    if(first_name.compareTo(pass2.first_name)==0)
    {
      return 0;
    }
    else
    {
      if(first_name.compareTo(pass2.first_name)>=1)
      {
        return 1;
      }
    }
  }
  else
  {
    if(last_name.compareTo(pass2.last_name)>=1)
    {
      return 1;
    }
    
    return -1;
  }
}
The if body of the outermost if...else statement determines whether the two last names are the same; if they are, it goes to the inner if...else statement, which compares the first names to see if they're the same. If the first names are the same, then my compareTo method returns 0 and breaks out of the method. Otherwise, the two first names are not the same and it checks to see if my passenger's first name would come after the after the one I'm comparing to; if it does, I return 1 and break out of the method.

Then I move into the body of the outer if...else statement, so that the last names aren't the same now. If my passenger's last name comes after the one I'm comparing to, I return 1 and break. Since I'm out of the body of the loop otherwise, I return -1 and break.

It looks like I won't take care of the case where the last names are the same but my passenger's first name comes before the one I'm comparing to, but I think that this actually will because the only time it would return -1 is if my passenger's last name comes before the one I'm comparing to or if I go through all those other cases and don't return anything else, so I still return a -1.

Mill Town, I'd rather not post the whole project because I've occasionally seen the tendency people have to go too far in explaining something, and I don't want that to happen with a part of the project I haven't gotten to just yet. If you guys could take a look at my approach there and see if it makes sense to you, too, that'd be great before I start trying to build this into my other classes. Thanks agian for the help!

hlfrk414
Dec 31, 2008
Since you did try to solve it yourself, I'll give you some sudo-code that may help you simplify what you are trying to do:


code:
public int compareTo(Object pass)
{
    //compare last names and save result
    //if result is non-zero, then Passengers are different and the comparison
    //can be used as the return value
    
    //if the result is zero, we'll only need to look at first names, so return
    //the result of comparing them. Simple.
}

Patashu
Jan 7, 2009
I've never delt with compiling or exporting java code outside of an IDE like Netbeans, help me out here?

I'm trying to submit some java code to a 'codegolf' site, where you have to write the smallest amount of code to satisfy a task. This means it has to compile it and run it server-side. The site in question: http://golf.shinh.org/p.rb?hexagon+2nd+fixed

This is the start of my code:
code:
import java.io.*;public class h{static int i,j,z,l;public static void main(String[] args)throws IOException{
Now, I seem to have a catch-22 in that if I name the class anything except tmp it throws a compile error:

code:
Compile failure

tmp.java:1: class h is public, should be declared in a file named h.java
import java.io.*;public class h{code...
                        ^
1 error

:

(eval):165:in `handle_'
(eval):163:in `chdir'
(eval):163:in `handle_'
./handler.rb:69:in `handle'
/data/xen/golf/index.fcgi:37
/data/xen/golf/index.fcgi:21:in `each'
/data/xen/golf/index.fcgi:21
If I name it tmp, it throws up when it tries to run it instead:
code:
Exception in thread "main" java.lang.NoClassDefFoundError: loaded class test was in fact named tmp
   at java.lang.VMClassLoader.defineClass(libgcj.so.81)
   at java.lang.ClassLoader.defineClass(libgcj.so.81)
   at java.security.SecureClassLoader.defineClass(libgcj.so.81)
   at java.net.URLClassLoader.findClass(libgcj.so.81)
   at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.81)
   at java.lang.ClassLoader.loadClass(libgcj.so.81)
   at java.lang.ClassLoader.loadClass(libgcj.so.81)
   at gnu.java.lang.MainThread.run(libgcj.so.81)
Given that it ignores the name of the file as well as glosses over the name of the class when submitting, how do I resolve this problem, or is this site unable to accept java code? It's not the tersest thing in the world but I'm proud of the 2 hours I spent on it. :colbert:

EDIT: Also, it doesn't seem to have java.util...in the absense of a scanner, is the best way to get an integer of input really to wrap System.in in an InputStreamReader in a BufferedInputStream?

Patashu fucked around with this message at 06:24 on Apr 21, 2009

Shavnir
Apr 5, 2005

A MAN'S DREAM CAN NEVER DIE
The reason its freaking out if your class is named h is because in Java your class's name has to match the filename it is in. Rename the file to h.java and that should clear up the first problem. As for the second, I don't know that's kinda weird.

Patashu
Jan 7, 2009
I -can't- rename it h.java, whatever I send it renames it to tmp.java then executes it as test.java or something like that. I don't even know.

zootm
Aug 8, 2006

We used to be better friends.
I can't remember if you can invoke non-public classes, but try removing 'public' from before 'class' and calling the class test. If it works you'll save 7 characters on your golf thing too.

Mill Town
Apr 17, 2006

JulianD posted:

I know no one is going to do my homework for me, and I wasn't asking anyone to; I was only expressing confusion at the vagueness of Mill Town's hint. Anyway, I think I've figured it out now:

code:
public int compareTo(Object pass)
{
  Passenger pass2 = (Passenger) pass;
  if(last_name.compareTo(pass2.last_name)==0)
  {
    if(first_name.compareTo(pass2.first_name)==0)
    {
      return 0;
    }
    else
    {
      if(first_name.compareTo(pass2.first_name)>=1)
      {
        return 1;
      }
    }
  }
  else
  {
    if(last_name.compareTo(pass2.last_name)>=1)
    {
      return 1;
    }
    
    return -1;
  }
}
The if body of the outermost if...else statement determines whether the two last names are the same; if they are, it goes to the inner if...else statement, which compares the first names to see if they're the same. If the first names are the same, then my compareTo method returns 0 and breaks out of the method. Otherwise, the two first names are not the same and it checks to see if my passenger's first name would come after the after the one I'm comparing to; if it does, I return 1 and break out of the method.

Then I move into the body of the outer if...else statement, so that the last names aren't the same now. If my passenger's last name comes after the one I'm comparing to, I return 1 and break. Since I'm out of the body of the loop otherwise, I return -1 and break.

It looks like I won't take care of the case where the last names are the same but my passenger's first name comes before the one I'm comparing to, but I think that this actually will because the only time it would return -1 is if my passenger's last name comes before the one I'm comparing to or if I go through all those other cases and don't return anything else, so I still return a -1.

Mill Town, I'd rather not post the whole project because I've occasionally seen the tendency people have to go too far in explaining something, and I don't want that to happen with a part of the project I haven't gotten to just yet. If you guys could take a look at my approach there and see if it makes sense to you, too, that'd be great before I start trying to build this into my other classes. Thanks agian for the help!

Fair enough. This is pretty much exactly where I was trying to point you. As hlfrk414 said, it could be simpler, but really this is perfectly fine for an intro programming course, no one expects your answer to be the most efficient.

If you want to check and make sure that it compares properly when the last names match and the passenger's first name comes first, just try it out. From a quick glance, though, I think what you're doing is correct.

Edit: wait, I think I'm wrong. Do you get a "not all code paths return a value" error while compiling? I think you need to make sure that you really always do return -1 if none of the other comparisons work.

Mill Town fucked around with this message at 09:21 on Apr 21, 2009

Patashu
Jan 7, 2009

zootm posted:

I can't remember if you can invoke non-public classes, but try removing 'public' from before 'class' and calling the class test. If it works you'll save 7 characters on your golf thing too.

Breakthrough! Compiles and runs server-side. :)

Is there a shorter way (in terms of characters) to get one integer from stdin? Can't use a Scanner.

code:
public static void main(String[] a)throws IOException{
z=Integer.parseInt(new BufferedReader(new InputStreamReader(System.in)).readLine());

Mill Town
Apr 17, 2006

Patashu posted:

Breakthrough! Compiles and runs server-side. :)

Is there a shorter way (in terms of characters) to get one integer from stdin? Can't use a Scanner.

code:
public static void main(String[] a)throws IOException{
z=Integer.parseInt(new BufferedReader(new InputStreamReader(System.in)).readLine());

As long as it's in the range 0-9, you could use
code:
System.in.read()-'0'

Pooball
Sep 21, 2005
Warm and squishy.
If you're allowed to use deprecated functions:
Integer.parseInt(new DataInputStream(System.in).readLine())

duck monster
Dec 15, 2004

Anyone have any idea when the website for Hibernate will be back up? Its been down for a bit now, and its a bit frusturating that I need to learn how to use it, but all the documentation is on a website that just says "Down for maintainance. Back up soon" or thereabouts.

:(

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
What do you need to know?

Donald Duck
Apr 2, 2007
Issue with implementing Java.Observable.

I have a JFrame observing another class. And this works fine when I launch the JFrame normally. However when I create the JFrame from within another JFrame, the Observing JFrame does not observe. It just stays with its default values for everything.

I'm adding the observer using object.addObserver(this);

Edit: Just to make it clearer, opening the new JFrame in a new window.

Donald Duck fucked around with this message at 17:30 on Apr 23, 2009

standard
Jan 1, 2005
magic

duck monster posted:

Anyone have any idea when the website for Hibernate will be back up? Its been down for a bit now, and its a bit frusturating that I need to learn how to use it, but all the documentation is on a website that just says "Down for maintainance. Back up soon" or thereabouts.

:(

The docs are included in the latest distro, so just download that.

Citanu541
Dec 1, 2008
Hi guys, I feel bad asking for help here with out having contributed in this thread, yet. My java teacher is just... awful, so I'm really struggling trying to get any help with this, even though I've gone to him twice.

Anyway, we've just started learning about inheritence, which is fine, I understand how it works. However, for our latest assignment, he requests we use the toString class to output our results from these seperate classes. I guess I really don't know how to do that with inheritence. I assumed values needed to be passed through an abstract class before they can be output. If you're printing from inside the class, I don't know how I can pass them through the abstract class, or if I even need to. Anyways, what I have so far...

Main Class
code:
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        PerfectSquare s = new PerfectSquare(2);
        System.out.println(s);
        PerfectCube c = new PerfectCube();
        System.out.println(c);
    }

}

PerfectSquare Class
code:
public class PerfectSquare {

    protected double length;

    public PerfectSquare() {
    }

    public PerfectSquare(double length) {
        this.length = length;
    }

    public String toString() {
        return "Length of perfect Square: " + length * 4;
    }
}

PerfectCube Class
code:
public class PerfectCube extends PerfectSquare implements calcArea {

    public PerfectCube() {
    }

    public PerfectCube(double length) {
        this.length = length;
    }

    public double calc() {
       return super.length * 6;
    }
}
calc Class
code:
public interface calc {
  public abstract double calcArea();
}

If my code looks confusing, I appologize, if anyone could help me out with hints, I would appreciate it.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
The way your class is right now won't let you take advantage of the toString method because you hardcoded the number of sides. So what you should do is declare a variable called sides and define it as 4 in the square and 12 in the cube class. That way you can reuse the toString method you defined in your square class.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
Citanu541, from your post and code it is not clear at all what you are trying to do or what you need to do.

Also, cubes are not squares.

Citanu541
Dec 1, 2008
Oops, I forgot to post the assignment specifications. This is exactly what the sheet says word for word:

Create a class called PerfectSquare. The perfect Square will have a parameter for the length of a side. The square will also have a parameter for surface area. The toString method of class PerfectSquare should print the length of the side(in meters) and the surface area. Create a class called PerfectCube. The cube toString method will print the length of a side and the surface area of the cube. You will also need a method for calculating the surface areas.

I realize cubes are not square, but I'm just following what he's asking. Or following what I can some-what understand from that explination.

MEAT TREAT's suggestion has given me an idea, hopefully I can remember it for when I return home.

Warblade
Apr 10, 2003

Beep Beep, Motherfucker!

Citanu541 posted:

I realize cubes are not square, but I'm just following what he's asking. Or following what I can some-what understand from that explination.
In general, when you make a subclass you want it to be a specialization of the super class.

Here's what I mean by specialization. For example, if you had a Square class you could make a Rhombus class be a subclass of Square, because a Rhombus is a special type of Square. Squares have all equal sides, and all interior angles are 90 degrees, Rhombuses don't have all 90 degree interior angles.

Squares and Rhombuses share similar attributes. The length of a side, surface area and perimeter calculation would all be the same. However if asked a Square to draw it self, you couldn't use the same drawing logic for the Rhombus. That is why you would want to create a special Rhombus class. There is a lot that can be shared, and can be contained in the Square class (length of side, surface area calculation and perimeter) that Rhombus can use, but when it comes time for drawing, the Rhombus class would need to override the drawing method to draw it self correctly.

I think you can figure out the rest now that you know how and when to use inheritance and know that cubes are not squares.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Man, if you are going to use geometric examples, you need to at least get your examples right. A square is a special type of rhombus, and the surface area calculation is totally different.

Citanu541
Dec 1, 2008

rjmccall posted:

Man, if you are going to use geometric examples, you need to at least get your examples right. A square is a special type of rhombus, and the surface area calculation is totally different.

Not to backlash at you, but I know this, also. I'm not exaggerating when I say my teacher is nuts. Those are the calculations he wants. Half the time I don't think he actually know what he wants, so he makes something up. Believe me, I'm embarrassed to post such broken code because of the way I was taught Java. I have a working example of the correct formulas for a square and the surface area of a square if you would like to see. The different is, I wrote it with out using the toString method, so it doesn't help me out on this assignment.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Citanu541 posted:

Not to backlash at you, but I know this, also.

Sorry, that was directed at Warblade, not you.

Your teacher is indeed nuts, and I'm worried that he doesn't know what "parameter" means.

If you have a working function that calculates the area of a square, you can just call it from your toString method.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
An interface might not be the best way to go about this. I envision an abstract Shape class:
code:
public abstract class Shape
{
	public Shape()
	{
	}
	
	public Shape(double length_)
	{
		length = length_;
	}
	
	protected double length;
	
	public abstract double getArea();
	
	@Override
	public String toString()
	{
		return String.format("Area of %s: %f", this.getClass().getSimpleName(), this.getArea());
	}
}
Your PerfectSquare and PerfectCube classes should extend Shape.

Note that you cannot make a new Shape() or new Shape(2.0) or something along those lines, because the class is marked as abstract and there is a method missing. When you extend Shape, you must implement getArea() in the subclass, or it won't compile.


EDIT: Also, in the constructor of a subclass you can call super() or super(whatever parameters you want) to call constructors of the superclass. Like calling Shape(double) from PerfectSquare(double).

idolmind86
Jun 13, 2003

It's better to burn out than to fade away.

It's even better to work out, numbnuts.
I have a JDBC program which in itself is pretty short, it connects to the datbase and does a bit of sql, the most expensive part of this program is the db connect. Now, this program gets called over and over for the same user. I was trying to think of a way to reuse the connection without creating some sort of daemon. Connections aren't serializable so JNDI isn't going to work. RMI is out also.

Connection pooling isn't going to work because the virtual machine exits and so the connection pool closes at this point.

Any thoughts on a good way to solve this?

zootm
Aug 8, 2006

We used to be better friends.
You're not going to be able to share a db connection between runs if the vm stops - in particular the vm will close the connections on shutdown anyway.

Warblade
Apr 10, 2003

Beep Beep, Motherfucker!

rjmccall posted:

Man, if you are going to use geometric examples, you need to at least get your examples right. A square is a special type of rhombus, and the surface area calculation is totally different.

What can I say, I suck at geometry. Hope I didn't confuse you Citanu541.

Warblade
Apr 10, 2003

Beep Beep, Motherfucker!
I'm trying to create some widgets that extend from Component. These will be used on a cable set-top box and there is limited access to Java libraries. I'm stuck with using Java 1.3. Anyway I'm only at the point where I'm trying to paint my widget on the screen but when I try to draw multiple widgets they're not being placed where I would think they should be placed. For example, here's what I'm getting:



The green square is supposed to be at 100, 200 with a width and height of 100. The blue square is supposed to be at 100, 50 also with a width and height of 100. I would think that the blue square should be lined up with the green square on the X axis and there should be a 50 pixel gap between them. What am I doing wrong?

This is my "ScreenFrame" class. It's just the JFrame/container for the widgets.
code:
public class ScreenFrame extends JFrame 
{
	private Spinner blueSquare;
	private Spinner greenSquare;

	public ScreenFrame()
	{
		blueSquare = new Spinner(100, 50, 100, 100, 0, 0, Color.blue);
		greenSquare = new Spinner(100, 200, 100, 100, 0, 0, Color.green);
		
		add(blueSquare);
		add(greenSquare);
		setSize(500, 500);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public static void main(String args[])
	{
		new ScreenFrame().setVisible(true);
	}
}
This is the "Spinner" class, which is supposed to be a spinner box but for now I'm just trying to draw squares.

code:
public class Spinner extends EPGComponent implements Navigable
{
	private int minVal;
	private int maxVal;
	private int currentValue;
	private Navigation nav;
	private Rectangle rectangle;
	private Color color;
	
	public Spinner(int x, int y, int width, int height, int minVal, int maxVal, Color c)
	{
		super(x, y, width, height);
		rectangle = new Rectangle(x, y, width, height);
		this.minVal = minVal;
		this.maxVal = maxVal;
		currentValue = minVal;
		nav = new Navigation(this);
		color = c;
	}
	
	public int getValue()
	{
		return currentValue;
	}

	public boolean isSelected() 
	{
		return false;
	}

	public void setFocusTraversal(Navigable up, Navigable down, Navigable left, Navigable right) 
	{
		nav.setFocusTraversal(up, down, left, right);
	}

	public void setMove(int keyCode, Navigable target) 
	{
		nav.setMove(keyCode, target);
	}

	public Navigable getMove(int keyCode) 
	{
		return nav.getMove(keyCode);
	}
	
	public void paint(Graphics g)
	{
		g.setClip(rectangle);
		g.setColor(color);
		g.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
	}
}

The Evan
Nov 29, 2004

Apple ][ Cash Money
OK, here is a suitably dumb Java question:

I'm using NetBeans on OS X, and I have one directory structure with a set of source packages, and another directory structure with another set of packages. When I load up a source file from the latter set, NetBeans gives me a ton of errors, on every single "import" line that refers to the former set of packages.

I've already gone through Tools > Libraries and added the correct paths to the former set of packages (actually, to both sets, since NetBeans does not recognize source files in the same package as the file I'm editing), but that hasn't fixed it. Do I need to "refresh" the source file somehow to get it to re-check the paths?

8ender
Sep 24, 2003

clown is watching you sleep
Am I doing things wrong by using a Persistence framework like Toplink directly for a web app?

I tried the prescribed EJB 3.0 Entity Bean > Session Bean > Struts Action when building my first sample app but I found the whole process to be incredibly time consuming and annoying just to get some data out of my database. Now I have a project setup where I'm getting data out of Toplink POJOs directly from Struts Actions with named queries and the whole process seems a lot more sane to me.

I'm still not entirely sold on the persistence frameworks either. It looks great for DML but the vast majority of our web work is just getting data out. My experience so far has been that the frameworks sometimes makes this easy and other times a nightmare, especially when I have to try to join a lot of tables together. Is it common to use a combination of plain old SQL queries and persistence frameworks in a web app?

Anyone have any ideas?

The Evan
Nov 29, 2004

Apple ][ Cash Money
Well, on the upside, I think I figured out how to manage external source packages, but I still can't get NetBeans to recognize the actual sourcefile's package.

e: Created a new project, chose the next higher directory in the source tree, fixed that. Now there's just a few packages much further down in the library that it thinks are in the wrong place.

:sigh:

The Evan fucked around with this message at 11:46 on Apr 27, 2009

Kaltag
Jul 29, 2003

WHAT HOMIE? I know dis ain't be all of it. How much of dat sweet crude you be holdin' out on me?
Is there a way to add an actionlister to a tab in a JTabbedPane that fires every time that pane is selected? Google is being stupid.

I'm using swing btw, bosses' orders.

zootm
Aug 8, 2006

We used to be better friends.
The Evan: Sounds like you might have some kind of misunderstanding with how Java or NetBeans works, could you be more specific about your layout here with an example or something?

LilMike
Sep 16, 2003
Im nto a stup1d n00b

Warblade posted:

I'm trying to create some widgets that extend from Component. These will be used on a cable set-top box and there is limited access to Java libraries....

I'll take a quick stab in the dark at this. Because I feel your pain when developing in old versions of Java with a questionably complete/implemented libraries on set-top boxes.

Normally, when using JFrame, you'd see myJFrame.getContentPane().add(component) instead of just myJFrame.add(), but we'll assume the JFrame you're using isn't too far off from normal in that it has a layout manager attached to it. Is it possible whatever layout manager it's using is switching up your x,y coordinates because of how its deciding to pack the components? Something to check anyway.

The Evan
Nov 29, 2004

Apple ][ Cash Money

zootm posted:

The Evan: Sounds like you might have some kind of misunderstanding with how Java or NetBeans works, could you be more specific about your layout here with an example or something?

Yeah I'm probably confused on some level. Basically I have a set of example code, say "packageA". It's a bunch of .java sourcefiles in a small directory structure, and each sourcefile has the correct package declaration (e.g. in packageA/gui, a file is listed as "package packageA/gui". There is a Main.java file (I didn't write this), and it has a series of import declarations, referring to packageB. Everything in packageB similarly has the correct package declarations corresponding to their directory structure. packageB also imports from packageC.

So, I created a new NetBeans project from existing source, viz. packageA, and from the project properties under "libraries > compile" I added packageB and packageC. Now under "libraries" in the project browser it displays all of the packages correctly, e.g. packageB, packageB.framework, etc. HOWEVER, some of the source files in packageB say "incorrect package", and some of the places where they refer to methods in packageC, specifically import statements, it NetBeans says the packages don't exist.

packageC is all .class files, if that makes a difference.

Thanks.

Warblade
Apr 10, 2003

Beep Beep, Motherfucker!

LilMike posted:

I'll take a quick stab in the dark at this. Because I feel your pain when developing in old versions of Java with a questionably complete/implemented libraries on set-top boxes.

Normally, when using JFrame, you'd see myJFrame.getContentPane().add(component) instead of just myJFrame.add(), but we'll assume the JFrame you're using isn't too far off from normal in that it has a layout manager attached to it. Is it possible whatever layout manager it's using is switching up your x,y coordinates because of how its deciding to pack the components? Something to check anyway.

Well here's the thing. The code I posted up is running on a Windows box. I'm coding on Windows just to prototype this thing since it takes 10 minutes to reboot the set-top just to see if something I did "worked". But yeah, layout manager might be what's doing it.

EDIT: This may be a big duh moment for me. Maybe I shouldn't be trying to place things in a coordinate system and instead rely on the layout managers? I guess I could use a GridBayLayout or something similar to place things.

EDIT2: Just for shits, I decided to set the layout manager to null. The squares now appear as they would in a coordinate system. Thanks LilMike!

Warblade fucked around with this message at 16:50 on Apr 28, 2009

Warblade
Apr 10, 2003

Beep Beep, Motherfucker!
Does anyone know of a way to get the compiler to generate errors (or at least warnings) when you're including code that is above whatever target compatibility you've set it at?

For example, I code and build using Eclipse (an old version, 3.2). I'm running JDK 1.6 but I'm building for target and source compatibility with 1.3. The other day I ran into a problem using StringBuffer.append(StringBuffer). Apparently this was added in 1.4, but I didn't get any kind of warning, just a runtime exception since my target didn't support this method call.

I'm also making builds with Ant, but I don't see any errors when trying to compile with that either. I thought turning on -Xlint might give some kind of warning with that, but, no.

standard
Jan 1, 2005
magic
Window -> Preferences -> Java -> Compiler -> Compiler Compliance level.

LilMike
Sep 16, 2003
Im nto a stup1d n00b
Alternatively, Warblade, check out the command line parameters for javac -source and -target, I think you'd want something like javac -source 1.3 -target 1.3... So it would only accept 1.3 compatible java and output 1.3 compatible bytecode. Bonus: you can specify these as attributes to the javac tag in your any build scripts.

Adbot
ADBOT LOVES YOU

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

LilMike posted:

Alternatively, Warblade, check out the command line parameters for javac -source and -target, I think you'd want something like javac -source 1.3 -target 1.3... So it would only accept 1.3 compatible java and output 1.3 compatible bytecode. Bonus: you can specify these as attributes to the javac tag in your any build scripts.

I don't think that would help, since warblade was running into a library issue and not a classload or verifier issue. Eclipse allows you to set up different jvms to build against, I'm on the train right now but I'm pretty sure sun still provides legacy jvms for download.

e: here -> http://java.sun.com/j2se/1.3/download.html

trex eaterofcadrs fucked around with this message at 13:48 on May 1, 2009

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