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
Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug

Fly posted:

Correct. The last time I tested this, throwing an exception was at least two orders of magnitude slower than using a conditional. Sometimes a 100x slowdown does not matter. However, the slow part is generally creating a new Throwable since the JVM has to figure out the stack, so if you throw an existing Throwable, or a singleton instance of one, it won't be so bad, and you could do that very easily when the exception does not originate from an exceptional condition. It's still not idiomatic Java style, so I would avoid it.
To elaborate on this, catching a NullPointerException is almost never the right thing to do. If you have to ask whether this is the right time, it isn't.

Adbot
ADBOT LOVES YOU

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa

Lysidas posted:

I'm under the impression that in Java*, exception handling is slow compared to conditional statements and that it is not intended to be part of the normal flow of program execution.

Going into technical specifics, most Java Virtual Machines out there only produce a scarce call stack which in the case of an exception is then converted to full stacktrace with all the relevant linked info and on top of this the actual Exception class contains some additional logic for combining stacktrace branches and whatnot to create the final thrown exception.

I currently know of only one VM which creates the full subcomponents needed for fast stacktrace generation for every branch execution and that VM would be IBM's one which does all kinds of small things like TCO.

zootm
Aug 8, 2006

We used to be better friends.
A relatively common pattern is to override fillInStackTrace for exceptions where you don't expect to actually expose it, i.e. for "control flow" exceptions. It's not all that idiomatic to use exceptions for control flow in Java, of course, but there are situations where it's warranted, and some other JVM languages use this pattern more. For example Scala has a trait called ControlException to mark classes for this purpose (see Breaks for an example of the sort of thing this can do).

Boz0r
Sep 7, 2006
The Rocketship in action.
Is there some way in Eclipse to run a single method without making a main method, just to test it?

yatagan
Aug 31, 2009

by Ozma

Boz0r posted:

Is there some way in Eclipse to run a single method without making a main method, just to test it?

You could run it as an applet, but that's just more work than copy pasting this:

code:
public static void main(String[] args) {
   runSingleMethod();
}

zootm
Aug 8, 2006

We used to be better friends.

Boz0r posted:

Is there some way in Eclipse to run a single method without making a main method, just to test it?
You could try actually writing a trivial unit test, which will at least let you run it, and might even tempt you to write a real test.

wwqd1123
Mar 3, 2003
Hey guys, sorry for making GBS threads up this thread with my worthless question but I hope you guys don't mind helping out someone who is very new to programming and java and trying to understand the basics.

I noticed that in simple drawing programs they use something like

public void paint(Graphics g){

g.setColor(Blue);
g.drawString("Words",50,50);

}

which would draw a blue string on the screen. I understand that that Graphics g creates an object in memory called g and the setColor method changes the object color to blue before it is drawn.

What I don't understand is why don't you have to go paint(Graphics g = new Graphics()) { because earlier on they mentioned that any object has to be created with the new command. I noticed that any time they create a new object from a class they always use the new command but not here?

PIGEOTO
Sep 11, 2007

wwqd1123 posted:

Hey guys, sorry for making GBS threads up this thread with my worthless question but I hope you guys don't mind helping out someone who is very new to programming and java and trying to understand the basics.

I noticed that in simple drawing programs they use something like

public void paint(Graphics g){

g.setColor(Blue);
g.drawString("Words",50,50);

}

which would draw a blue string on the screen. I understand that that Graphics g creates an object in memory called g and the setColor method changes the object color to blue before it is drawn.

What I don't understand is why don't you have to go paint(Graphics g = new Graphics()) { because earlier on they mentioned that any object has to be created with the new command. I noticed that any time they create a new object from a class they always use the new command but not here?
You haven't really explained your issue particularly well as I'm having trouble trying to suss out whether you want to know why you don't do 'public void paint(Graphics g = new Graphics())', or whether you want to know why people don't call the paint method explicitly.

Graphics g does not create a new object in memory. It would in a language like C++, but not in Java. In Java, objects are passed in to functions by reference (the pointer to their address in memory). What the parameter is actually doing is declaring a variable 'g' that is of type Graphics, and then assigning it the reference of the object passed in.

The other answer to your possible question is that paint() is invoked by the toolkit you are using when it is time to paint, for instance when the window is resized or the mouse cursor moves over it. When a component is created, a graphics object for that one component is generated by the toolkit and is passed in when the paint() method is invoked. Basically, the programmer should never create their own Graphics objects (rather, they can't) and shouldn't ever call paint() explicitly.

I hope that's answered your question.

PIGEOTO fucked around with this message at 03:14 on Dec 24, 2009

Zweihander01
May 4, 2009

wwqd1123 posted:

Hey guys, sorry for making GBS threads up this thread with my worthless question but I hope you guys don't mind helping out someone who is very new to programming and java and trying to understand the basics.

I noticed that in simple drawing programs they use something like

public void paint(Graphics g){

g.setColor(Blue);
g.drawString("Words",50,50);

}

which would draw a blue string on the screen. I understand that that Graphics g creates an object in memory called g and the setColor method changes the object color to blue before it is drawn.

What I don't understand is why don't you have to go paint(Graphics g = new Graphics()) { because earlier on they mentioned that any object has to be created with the new command. I noticed that any time they create a new object from a class they always use the new command but not here?

The snippet of code you posted is a method. It doesn't assign an instance of a class to g because "Graphics g" is an argument for the method. The instance of Graphics will be supplied later on by the code that actually calls the paint method.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

wwqd1123 posted:

What I don't understand is why don't you have to go paint(Graphics g = new Graphics()) { because earlier on they mentioned that any object has to be created with the new command. I noticed that any time they create a new object from a class they always use the new command but not here?

You could, but it would look more like:

code:
paint(new Graphics());
But what would happen to "g" after paint() is done? It would disappear! You would probably want something like:

code:
Graphics graphics = new Graphics();
paint(graphics);
//now you can do something else with the graphics object

Sebbe
Feb 29, 2004

Boz0r posted:

Is there some way in Eclipse to run a single method without making a main method, just to test it?

You could grab DrJava for Eclipse. It's basically a REPL for Java, which automatically loads your active projects.

There've been a few problems with the latest version, but v0.9.8 has worked pretty well for me.

Jo
Jan 24, 2005

:allears:
Soiled Meat
What is the most common (and cross platform) way to deal with movie files in Java? The Java Media Framework 2.1 API says it works with AVI and a few other formats, but when it comes to things like mp4 or others, what are my options.

As an additional question, is JMF still the preferred way to deal with Media in Java, or has it been replaced/outdated?

Jo fucked around with this message at 00:17 on Jan 5, 2010

FateFree
Nov 14, 2003

I have an architecture question that surfaced after a huge refactoring of my web app framework (thanks to ignoring generics for so long).

I have a GenericDao<T> class to retrieve objects from the database with type safety. Standard methods like save(T), List<T> findAll(), etc.

I want to add a new method that adds restrictions to queries to enable things like finding all Users by username. The method signature would look something like List<T> findBy(String field, Object property).

However I want to offer some protection and not actually accept Strings and objects, but something more type safe. For instance, I should only allow the GenericDao<User> to call findBy like so: findBy("username", String), where "username" is a fixed value in the form of a constant or even better, an Enum.

I can define an Enum of acceptable values but I run into an inheritance problem because I want all of my objects to be able to accept the common properties such as Long id, Long timeCreated, Long timeModified. As I understand I can't extend an Enum class which has some common values.

Can anyone give me some insight to how the best way to architect this may be? Even if its not a solution, some direction might help clarify things for me.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Think of the built-in enum/Enum as just being one basic implementation of a more general pattern. In this case, you need something more advanced, both because there's a hierarchy associated with the enumeration and because you want to tie a type to the enumerators. Two types, actually: first, the type of object that has that field, and second, the type of data stored in that field.

code:
public class Field<Owner,Data> { ... }

public class Record {
  public static final Field<Record,Long> LAST_ACCESSED = new Field<Record,Long>();
  public static final Field<Record,Long> ID = new Field<Record,Long>();
  ...
}

public class Widget extends Record {
  public static final Field<Widget,String> COLOR = new Field<Widget,String>();
  ...
}

class GenericDao<T> {
  public <U> List<T> findBy(Field<? super T, U> field, U value) {
    ...
  }

  // or even this, to be slightly more efficient:
  public List<T> findBy(Field<? super T,Long> field, long value) { ... }
  public List<T> findBy(Field<? super T,String> field, String value) { ... }
  ...
}

rjmccall fucked around with this message at 02:33 on Jan 5, 2010

Fly
Nov 3, 2002

moral compass

FateFree posted:

Can anyone give me some insight to how the best way to architect this may be? Even if its not a solution, some direction might help clarify things for me.
You might want to look at using Annotations, such as the javax.persistence.* annotations for Entity classes, which are the things you are loading via your DAO. The GenericDao can lookup the mapping of database fields to object properties using the Column annotation. You don't have to do an implementation of the Java Persistence Architecture but only use the useful annotations. This allows you to avoid creating a whole separate hierarchy of classes that mirrors your data object hierarchy.

wigga please
Nov 1, 2006

by mons all madden
Hi, my education focuses on .NET but I'm trying to get some Java experience under my belt as well. I was trying my hand at Hibernate, specifically the exercise from the Netbeans site using the default MySQL sakila DB.

First thing I noticed is that in said exercise I'm supposed to use a concatenated string to build the HQL query so naturally the :siren: injection vulnerability:siren: went off in my head.

I tried to use a parametrized query but ran into some trouble:
code:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: 
Parameter value does not exist as a named parameter in [from Actor a where :column like '%:value%']
in this method:
code:
private void executeHQLQuery(String column, String value)
    {
        String qString = "from Actor a where :column like '%:value%'";
        try
        {
            Session session = HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();
            Query q = session.createQuery(qString);
            q.setString("column", column);
            q.setString("value", value);
            List resultList = q.list();
            displayResult(resultList);
            session.getTransaction().commit();
        }
        catch (HibernateException he)
        {
            he.printStackTrace();
        }
    }
I'm not sure what causes this (maybe the '%:value%' part?), any ideas?

Max Facetime
Apr 18, 2009

I haven't used HQL that much (I'm more either Criteria or native SQL kinda guy), but a little googling produced this.

Basically your query should be "... where :column like :value" and have the %-characters in the parameter value itself. It probably has to do with how HQL is parsed.

RussianManiac
Dec 27, 2005

by Ozmaugh
By what factor are function calls more expensive from within a native program and calling a java native method?

Azerban
Oct 28, 2003



I'm feeling loving retarded right now, hopefully someone can point out my obvious mistake and relieve some of my horrifying shame;

code:
public int alphaBeta(int ply, int alpha, int beta){ 
		
                if(ply == 0){
		    System.out.println(evalBoard());
		    return evalBoard();
		}

	        ...
	  	
	  	for(int a = 0; a < moveList.size(); a++){
	  		newBoard = new Board(getPlayerIsWhite(), getWhitesMove(), getWhiteDJ(), getBlackDJ(), getBoardRep());
	   		newBoard.move(moveList.get(a));
	   		newBoard.switchSides();
	  		score = -(newBoard.alphaBeta(ply-1, -beta, -alpha));
	  		...	  		 
	  	}
	 return alpha;	
}
The for loop is supposed to create a fresh version of the current board, and try different moves on it, blah blah, alpha beta pruning, but it never actually reverts back to the old version of the board, it continues to use the same version throughout, like it's using some global version. Someone mind pointing out where I'm stupid?

RussianManiac
Dec 27, 2005

by Ozmaugh

Azerban posted:

I'm feeling loving retarded right now, hopefully someone can point out my obvious mistake and relieve some of my horrifying shame;

code:
public int alphaBeta(int ply, int alpha, int beta){ 
		
                if(ply == 0){
		    System.out.println(evalBoard());
		    return evalBoard();
		}

	        ...
	  	
	  	for(int a = 0; a < moveList.size(); a++){
	  		newBoard = new Board(getPlayerIsWhite(), getWhitesMove(), getWhiteDJ(), getBlackDJ(), getBoardRep());
	   		newBoard.move(moveList.get(a));
	   		newBoard.switchSides();
	  		score = -(newBoard.alphaBeta(ply-1, -beta, -alpha));
	  		...	  		 
	  	}
	 return alpha;	
}
The for loop is supposed to create a fresh version of the current board, and try different moves on it, blah blah, alpha beta pruning, but it never actually reverts back to the old version of the board, it continues to use the same version throughout, like it's using some global version. Someone mind pointing out where I'm stupid?

Post implementation of Board. Are you doing a shallow copy or deep copy when you are constructing newBoard? getBoardRep() I assume you return the board state to the constructor?

Azerban
Oct 28, 2003



RussianManiac posted:

Post implementation of Board. Are you doing a shallow copy or deep copy when you are constructing newBoard? getBoardRep() I assume you return the board state to the constructor?

The constructor just sets a bunch of instance variables, in this case. I figured since I was creating a new Board in each iteration in the loop, that it was equivalent to a deep copy, but I suppose that's not happening.

RussianManiac
Dec 27, 2005

by Ozmaugh

Azerban posted:

The constructor just sets a bunch of instance variables, in this case. I figured since I was creating a new Board in each iteration in the loop, that it was equivalent to a deep copy, but I suppose that's not happening.

What could be happening is that you are probably using standard containers somewhere and when you are assuming you are deep copying them you really are shallow copying. Also if you just say new_vector = old_vector; or something like that you are just copying a reference, not underlying object (like assigning pointers in C++), so that could also be happening as well.

wigga please
Nov 1, 2006

by mons all madden

I am in posted:

I haven't used HQL that much (I'm more either Criteria or native SQL kinda guy), but a little googling produced this.

Basically your query should be "... where :column like :value" and have the %-characters in the parameter value itself. It probably has to do with how HQL is parsed.
Thanks, that link was a good start, but a new problem has arisen. Somehow the parameters aren't used in the query string. When I'm debugging I can see that the parameters are being added to the query but the query itself changes to
code:
from Actor a where ? like ?
ignoring both the single quotes and percent signs.

Max Facetime
Apr 18, 2009

wigga please posted:

code:
from Actor a where ? like ?
ignoring both the single quotes and percent signs.

That looks like parameterised SQL. Having a parameterised column name like that is probably not supported on your database out of the box. Try it by hard-coding the column name before handing it over to Hibernate.

zootm
Aug 8, 2006

We used to be better friends.
That's actually probably a problem with your debugging rather than your database driver. That query looks like exactly the correct one to send to JDBC, and most debugging systems cannot show the "full" version of the query (it really doesn't actually work that way, except in the internals of some drivers).

log4jdbc can often decipher this sort of thing and log out what you'd "expect" to see sent (although, as mentioned, this is not how it works, and the raw SQL string is unlikely to ever be sent).

wigga please
Nov 1, 2006

by mons all madden
I'm afraid the logging part isn't for me, I'm just starting out and have no idea where to even begin putting the .jar files I downloaded, the only language I ever used logging in is perl.

What I can tell is that if I hardcode the string everything is just dandy.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

wigga please posted:

Hi, my education focuses on .NET but I'm trying to get some Java experience under my belt as well. I was trying my hand at Hibernate, specifically the exercise from the Netbeans site using the default MySQL sakila DB.

First thing I noticed is that in said exercise I'm supposed to use a concatenated string to build the HQL query so naturally the :siren: injection vulnerability:siren: went off in my head.

I tried to use a parametrized query but ran into some trouble:
code:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: 
Parameter value does not exist as a named parameter in [from Actor a where :column like '%:value%']
in this method:
code:
private void executeHQLQuery(String column, String value)
    {
        String qString = "from Actor a where :column like '%:value%'";
        try
        {
            Session session = HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();
            Query q = session.createQuery(qString);
            q.setString("column", column);
            q.setString("value", value);
            List resultList = q.list();
            displayResult(resultList);
            session.getTransaction().commit();
        }
        catch (HibernateException he)
        {
            he.printStackTrace();
        }
    }
I'm not sure what causes this (maybe the '%:value%' part?), any ideas?
While your desire to avoid injection is admirable, unless HQL parameterized queries are significantly different from most SQL parameterized queries, you can't do what you want to do. Things like table and column names cannot be parameters in a query, so if the column name is dynamic, you will have to build at least part of the query string dynamically. Obviously you should take care to ensure that you are only building the query with valid column names, but there is no way around it.

As for the bit with :value, you can either put the % on either side of the string before you bind it to the query parameter, or you can do '%'+:value+'%' in your query.

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys
It turns out I need one more generic CS course for school, and I picked intermediate Java. The description reads "[f]undamentals of encapsulation, inheritance, polymorphism, abstraction, method overloading and overriding, exception handling, GUI components, event handling, multimedia programming, and input/output streams are introduced."

Now I know C, C++, C#, Ruby, and a smattering of other languages to varying levels of proficiency, but not Java. Given that, what's the best way to quickly get up to speed with Java?

As you can see, the course isn't hard -- all of the things listed are topics I'm familiar with in other languages. C# is also close enough to Java that the syntax and overall concepts are all familiar. But I'm unfamiliar with the specifics of Java, especially it's libraries and quirks.

I'm perusing some "Learn Java" books right now, like Head First Java, and while they'll work, they're a bit basic. I mean, I'm still at their start, but they mostly have "this is a 'Class'. Can you say 'Class'?" I've thought about just going over the Java API docs, but I feel that won't give me a good working base knowledge. Being a school course, I can't spend time bumbling through each assignment trying to kludge through the syntax quirks and language gotchas I never learned.

Is there a book out there that already assumes OO familiarity, and that I'm not an idiot, that can teach me Java? I just need it to an intermediate level, but I do need a strong grounding in Java itself.

Fly
Nov 3, 2002

moral compass
I like the language specification: http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html

Magicmat
Aug 14, 2000

I've got the worst fucking attorneys

Fly posted:

I like the language specification: http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html
I'm looking for something a little less dry, and a little less, uh, intensive. I only have a month to brush up on this. I also need more than just a language spec, but also to know the Java Way[tm] to do things, which the prof will presumably expect my programs to use, as well as the non-specified behavior, Java ecosystem, and common library APIs.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Magicmat posted:

It turns out I need one more generic CS course for school, and I picked intermediate Java. The description reads "[f]undamentals of encapsulation, inheritance, polymorphism, abstraction, method overloading and overriding, exception handling, GUI components, event handling, multimedia programming, and input/output streams are introduced."

Now I know C, C++, C#, Ruby, and a smattering of other languages to varying levels of proficiency, but not Java. Given that, what's the best way to quickly get up to speed with Java?

As you can see, the course isn't hard -- all of the things listed are topics I'm familiar with in other languages. C# is also close enough to Java that the syntax and overall concepts are all familiar. But I'm unfamiliar with the specifics of Java, especially it's libraries and quirks.

I'm perusing some "Learn Java" books right now, like Head First Java, and while they'll work, they're a bit basic. I mean, I'm still at their start, but they mostly have "this is a 'Class'. Can you say 'Class'?" I've thought about just going over the Java API docs, but I feel that won't give me a good working base knowledge. Being a school course, I can't spend time bumbling through each assignment trying to kludge through the syntax quirks and language gotchas I never learned.

Is there a book out there that already assumes OO familiarity, and that I'm not an idiot, that can teach me Java? I just need it to an intermediate level, but I do need a strong grounding in Java itself.
The "pre-requisite" Java courses are probably just the equivalent of the Learn Java books, so skimming those should be more than enough to get you up to speed.

Besides, Java is just C# but more verbose and with the sharp edges left unfiled.

zootm
Aug 8, 2006

We used to be better friends.

Jethro posted:

Besides, Java is just C# but more verbose and with the sharp edges left unfiled.
Yeah, generally speaking the similarity between C# and Java should serve you very well. C# effectively started out as a carbon copy of Java, and worked from there with less legacy holding it back. I've heard that Java in a Nutshell is a good text if you're already familiar with programming similar languages.

I wouldn't recommend the JLS. I don't think I've ever understood the approach of learning a language from the specification; the docs I've read tend to be written for implementers rather than programmers, and the feel of the language gets drowned out by its corner cases. Having said that the specification tends to be the go-to place for finding those corner cases when you run into them.

zootm fucked around with this message at 11:38 on Jan 8, 2010

wigga please
Nov 1, 2006

by mons all madden

Jethro posted:

While your desire to avoid injection is admirable, unless HQL parameterized queries are significantly different from most SQL parameterized queries, you can't do what you want to do. Things like table and column names cannot be parameters in a query, so if the column name is dynamic, you will have to build at least part of the query string dynamically. Obviously you should take care to ensure that you are only building the query with valid column names, but there is no way around it.

As for the bit with :value, you can either put the % on either side of the string before you bind it to the query parameter, or you can do '%'+:value+'%' in your query.
Ahhh I see, that's disappointing, guess I was spoiled from working with .NET ORMs and the like.

I think I'll just go with stored procedures then, thanks for the help, others too!

mcw
Jul 28, 2005
Greetings, and thanks in advance for any help you guys are able to provide. I initially posted this in the Web Development Stupid Questions thread, but was advised to try posting here instead.

I've been asked to learn about Java web development using GlassFish. Since this is completely new to me, it's very likely that I've gone about this the wrong way, but here's what I've done: I have a VPS, cPanel is running on it, Apache is the web server, and I've managed to get GlassFish v2 up and running as well.

The problem is that I don't know how to put all this stuff together.

Let's say I'm running domain.com, and the host IP for domain.com is 12.34.56.789. In the root directory, there's the GlassFish folder, and right alongside it is the public_html folder. Anything I put in GlassFish is going to be running on port 8080, whereas the main website is running on port 80, right? And my understanding was that nothing on the site is publically viewable unless it's in a subfolder of public_html, anyway.

So what do I need to do to make the GlassFish stuff viewable on domain.com? I could put the GlassFish folder inside of public_html and start it up from there, but it would still be running on port 8080.

If anyone knows of a good book, or some sort of guide, that I could read to answer all these newbie questions, that would be amazingly helpful.

wwqd1123
Mar 3, 2003
What is the best way to put a multiple form application together? Is it best to design and program and bunch of panels first and then add and remove them to a JFrame as the user navigates the application? Or is there some better way?

FateFree
Nov 14, 2003

I am a reflection noob. I have a class with holds serveral static IProperty interfaces, and some static IReference interfaces. If I pass an object into a utility method, could I use reflection to get the instances of all these interfaces, without knowing their property names, so I could do a for(IProperty property : properties) loop?

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa

FateFree posted:

I am a reflection noob. I have a class with holds serveral static IProperty interfaces, and some static IReference interfaces. If I pass an object into a utility method, could I use reflection to get the instances of all these interfaces, without knowing their property names, so I could do a for(IProperty property : properties) loop?

Well sort of, I've written an utility (linky!) which does something like that for arbitrary bean-like classes. How to really do what you want to do depends on the actual structure of the class though. What I'm really trying to say is that feel free to look through the source of my utility to see if that helps you and ask further (with further details) if this post doesn't help.

PS. If you think my utility could help you, basically the syntax for looping through properties of some class with my utility would be
code:
BeanPropertyController controller = BeanPropertyController.of(SomeClass.class);
for (String propertyName : controller.getPropertyNames()) {
    if (controller.typeOf(propertyName).equals(IProperty.class)) {
        // do something with the propertyName
    }
}

FunOne
Aug 20, 2000
I am a slimey vat of concentrated stupidity

Fun Shoe
Ok, so I'm building an application that needs to store a time of day (IE, 2:00pm) and it links back to a database so I should use java.util.Date rather than constructing something.

This should be easy, but I'm having a hell of a time with it. How do I just use Date() to represent not July 1, 1978 2:00 pm /EST but 2:00pm in the afternoon.

Should I just use Date as a proxy for a numeric (2+12)*60*60*1000 and do the translate in and out myself?

lamentable dustman
Apr 13, 2007

🏆🏆🏆

FunOne posted:

Ok, so I'm building an application that needs to store a time of day (IE, 2:00pm) and it links back to a database so I should use java.util.Date rather than constructing something.

This should be easy, but I'm having a hell of a time with it. How do I just use Date() to represent not July 1, 1978 2:00 pm /EST but 2:00pm in the afternoon.

Should I just use Date as a proxy for a numeric (2+12)*60*60*1000 and do the translate in and out myself?

There is java.sql.Date that is pretty much that. A thin date object for for jdbc that handles the translations.

Adbot
ADBOT LOVES YOU

zootm
Aug 8, 2006

We used to be better friends.
Yeah, java.sql.Date is a subclass of java.util.Date anyway; it is "the way" you send dates to databases (although util usually works too). Of course both classes are definitely glorified number wrappers, a fact that's pretty obvious when you look at how many of their methods are deprecated.

For what it's worth for most date manipulation Joda Time is your best friend. Don't be the guy who fails to account for time zones or whatever.

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