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
narbsy
Jun 2, 2007

Doctor w-rw-rw- posted:

Well, seems reasonable to me, then.

I've found the opposite, personally. Different (key)strokes for different folks, I guess

There are lots of ways to customize IntelliJ -- check out Live Templates and the Key mappings -- you can change just about everything. If there's anything in particular, we can try to help out.

Also, you can have a lot of fun tweaking GC settings if responsiveness is part of the issue. I've found parallel + concurrent mark/sweep + incremental to be the most user-friendly and G1 the least. As always, ymmv.

narbsy fucked around with this message at 04:55 on May 10, 2012

Adbot
ADBOT LOVES YOU

Turkeybone
Dec 9, 2006

:chef: :eng99:
So I have an exam tomorrow and there's one pesky little question I can't figure out -- it might just be a typo in the practice exam.

So if an abstract class has an abstract method, say

public abstract int total();


the subclass has a method total, but it's written as

public double total(){

There's a calculation with a double in the subclass method, so when I did the practice test I wrote
public int total(){ etc }
and just cast it back to an int when returning it.

So the question is, is it cool to override the type like that, or is it just an oversight in the answer key?

1337JiveTurkey
Feb 17, 2005

Turkeybone posted:

So the question is, is it cool to override the type like that, or is it just an oversight in the answer key?

There's a case where it's okay and there's a case where it isn't. Put simply, this is when it's not okay, but if you'd like to know more, here's an explanation:

Java allows something called covariant return types on methods. The idea is that if you've got a class or interface defining a method public InputStream getSomeInputStream() then any implementation needs to return an InputStream. The implementation can't return something completely different like an OutputStream.

Let's say you make an implementation which returns a FileInputStream. That's valid since it's an InputStream and that's what the method signature says you'll return. But what if you want to let people using your class that it's always going to return a FileInputStream? Java allows your implementation to declare the method as public FileInputStream getSomeInputStream() and it'll still work. It's generally considered bad form since it allows people to write code that will work with your implementation by expecting a FileInputStream but won't work with anybody else's.

In your case it's a int and a double. Neither type inherits from the other type or from anything else because they're not objects, they're primitives and primitives don't have any inheritance behavior. Even if the abstract parent class had the method defined as public abstract Object total() it's still not allowed because of the whole not being objects bit.

Turkeybone
Dec 9, 2006

:chef: :eng99:
Hmm, thanks for the explanation. They teach us inheritance/real type/apparent type with silly things like Animal and Dog, Cat, etc. So, to put it in cs100 terms for me, in this case I could do public abstract Animal getAge() and then later write extend Animal with something like public Cat getAge() ?

It's probably just an oversight in the exam, then. The next level class is more about abstracts and interfaces, etc, so I don't think they'd throw this at us at this juncture. Thanks for the help :)

pigdog
Apr 23, 2004

by Smythe
It'd be weird for a method that's named getAge() return an animal object rather than some number representing age. :) If you'd replace getAge() with something like getCritter() then yes, you could do that. With the caveat that it's usually not nice form, as 1337JiveTurkey explained. The implementation might be something like public Animal getCritter() { Cat critter = new Cat(); return critter } where it may only use a concrete Cat object internally, but doesn't make the specific claim of returning a Cat; just some kind of Animal.

I'd guess it's not a typo, just something they would expect you to be mindful of when implementing methods.. anyhow a modern IDE would pick up and alert you of the incompatible return type right away.

pigdog fucked around with this message at 09:50 on May 10, 2012

Turkeybone
Dec 9, 2006

:chef: :eng99:

pigdog posted:

It'd be weird for a method that's named getAge() return an animal object rather than some number representing age. :) If you'd replace getAge() with something like getCritter() then yes, you could do that. With the caveat that it's usually not nice form, as 1337JiveTurkey explained. The implementation might be something like public Animal getCritter() { Cat critter = new Cat(); return critter } where it may only use a concrete Cat object internally, but doesn't make the specific claim of returning a Cat; just some kind of Animal.

I'd guess it's not a typo, just something they would expect you to be mindful of when implementing methods.. anyhow a modern IDE would pick up and alert you of the incompatible return type right away.

haha yeah sorry, I've been studying too long and was just grasping for an example. the answer key is doing the illegal thing here, by using double instead of int. And it's a written exam so in this case, the IDE won't be of help (we are babbys who use Dr. Java).

But I realize this is a very specific and convoluted case, so I appreciate all of your insights, and I won't belabor this any further!

etcetera08
Sep 11, 2008

Turkeybone posted:

haha yeah sorry, I've been studying too long and was just grasping for an example. the answer key is doing the illegal thing here, by using double instead of int. And it's a written exam so in this case, the IDE won't be of help (we are babbys who use Dr. Java).

But I realize this is a very specific and convoluted case, so I appreciate all of your insights, and I won't belabor this any further!

Agh gently caress Dr. Java. Had to use it last semester, probably will be using it again next semester for an OOP class with Java. I only used it when I had to run our final programs and print the output in the format my prof wanted. It's slow as hell and awful.

Hidden Under a Hat
May 21, 2003
I'm trying to make a JDialog with a JColorChooser and two buttons, but for some reason the panel with the colorchooser and buttons is way too high. Here's my code:

code:

        GroupLayout customColorLayout = new GroupLayout(customColorPanel);
        customColorPanel.setLayout(customColorLayout);
        customColorLayout.setAutoCreateGaps(true);
        customColorLayout.setAutoCreateContainerGaps(true);

        customColorLayout.setHorizontalGroup(customColorLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
            .addComponent(colorChooser,GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)
            .addGroup(customColorLayout.createSequentialGroup()
                .addComponent(acceptColor,GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)
                .addComponent(cancelColor,GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)));
        customColorLayout.setVerticalGroup(customColorLayout.createSequentialGroup()
            .addComponent(colorChooser,GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)
            .addGroup(customColorLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(acceptColor,GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)
                .addComponent(cancelColor,GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)));

        customColor.add(customColorPanel);
        customColor.pack();

Nowhere in my code do I specify the dimensions of the customColorPanel, however it ends up being too high like I said. For all my other dialog boxes with components inside a panel, the panel sizes itself around all the components, and then the dialog sizes itself around the panel. So why in this case is my panel not correctly sized?

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Worth noting that the forums now have syntax highlighting for new languages including Java. You just put "code=java" instead of "code" in the square brackets.

Java code:
public static void main(String[] args) {
    for (int i = 0; i < 100; i++) {
        System.out.println("Hello Syntax Highlighting!");
    }
}
e: CHOO IS LORD

Grandmaster.flv
Jun 24, 2011
Is there a Java library that would allow me to run a command line executable on a remote server? After searching around a bit I found a few solutions that involved running telnet or ssh through RumTime() but the remote server I'm working with has those locked down for security.

HFX
Nov 29, 2004

origami posted:

Is there a Java library that would allow me to run a command line executable on a remote server? After searching around a bit I found a few solutions that involved running telnet or ssh through RumTime() but the remote server I'm working with has those locked down for security.

Need more explanation on what you are trying to do here and why?

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
origami: Is there a particular reason you want to use Java for that? Is this supposed to be a tool that runs one specific command remotely or something more general-purpose? I think you need to elaborate upon what you're trying to accomplish, because this is soundling like an XY problem.

edit: ^^^ :respek:

Grandmaster.flv
Jun 24, 2011

HFX posted:

Need more explanation on what you are trying to do here and why?


I have a python script I run on a few of my work servers that does some tedious tasks for me including importing oracle data, running sql scripts and configuring applications. I just run it through the command line (while on the server) with a few options; it's pretty simple.

I would like to run this script remotely from my desktop machine or even just run programs from the command line like if I were logged onto the server. The reason I'm using Java for this is because I started futzing around with the GUI creator in NetBeans and I thought it would be nice to add the functionality to what I was already working on.

I can already drop/create users and do other tasks on my remote servers using JDBC but unfortunately I cannot figure how to run other programs like I could if they were local to my desktop machine.

Max Facetime
Apr 18, 2009

There's the Jsch library, which does most things SSH. Apache Ant uses it in tasks that can execute commands or copy files securely.

E: Ooops, I missed the bit about SSH being locked down. If SSH is not open then it's likely the server is not Linux or it's not meant to be remotely accessible.

Max Facetime fucked around with this message at 21:21 on May 25, 2012

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
How would (or do) you do this without Java? You mentioned that the servers have SSH locked down.

Grandmaster.flv
Jun 24, 2011

Lysidas posted:

How would (or do) you do this without Java? You mentioned that the servers have SSH locked down.

I don't think I would be able to just using a command line.

I am in posted:

There's the Jsch library, which does most things SSH. Apache Ant uses it in tasks that can execute commands or copy files securely.

Thanks although I think that would require a listening ssh process on my remote servers.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
That wasn't my question. How do you run this script now? You said that you run them on the servers, but you can't connect to them with SSH? Are you physically at the servers, or something like that?

Grandmaster.flv
Jun 24, 2011

Lysidas posted:

That wasn't my question. How do you run this script now? You said that you run them on the servers, but you can't connect to them with SSH? Are you physically at the servers, or something like that?

Ah, logging in through RDP.

HFX
Nov 29, 2004

origami posted:

Ah, logging in through RDP.

If you can log in through RDP there is no reason SSH can't be run on a non standard port just as safely (use a public key for authentication).

While I know of nothing that meets exactly what you want to do, you can always make a rpc / rmi / your flavor of remote procedure calls here, that runs over ssl and authenticates both sides. It shouldn't take to long to write (couple of days tops).

Edit: Google search reports this: http://properjavardp.sourceforge.net/

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
Mentioning that they're Windows servers early on would have been useful, instead of mentioning SSH being locked down (which implies that it's installed but disabled, which implies some type of Unix) :)

I recommend Sysinternals' PsExec. Making a local psexec call from a Java GUI shouldn't be too difficult.

Grandmaster.flv
Jun 24, 2011

Lysidas posted:

Mentioning that they're Windows servers early on would have been useful, instead of mentioning SSH being locked down (which implies that it's installed but disabled, which implies some type of Unix) :)

I recommend Sysinternals' PsExec. Making a local psexec call from a Java GUI shouldn't be too difficult.

Haha, my apologies. I'll checkout psexec and if I run into issues I'll follow-up on HFX's advice.

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


Does IDEA (free edition) have all the features in eclipse (e.g. search and replace) and if not which are missing? I'm thinking of giving it a go, but I'd like to hear more about it if possible.

Also can you do android coding on it?

Fake edit: The website seems pretty ambiguous about this, which is why I'm asking.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Private Speech posted:

Does IDEA (free edition) have all the features in eclipse (e.g. search and replace) and if not which are missing? I'm thinking of giving it a go, but I'd like to hear more about it if possible.

Also can you do android coding on it?

Fake edit: The website seems pretty ambiguous about this, which is why I'm asking.

Yeah it has search & replace, tons of refactoring tools, debugging tools, etc. I can't think of anything I used in Eclipse that IDEA (free edition) doesn't have.

fletcher fucked around with this message at 04:55 on May 31, 2012

Doctor w-rw-rw-
Jun 24, 2008

fletcher posted:

Yeah it has search & replace, tons of refactoring tools, debugging tools, etc. I can't think of anything I used in Eclipse that IDEA (free edition) doesn't have.
Are you an Android dev? ADT is heavily tied to Eclipse and I'm skeptical that IDEA would have first-class Android support quite so extensive. It's a big deal to me, personally.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Doctor w-rw-rw- posted:

Are you an Android dev? ADT is heavily tied to Eclipse and I'm skeptical that IDEA would have first-class Android support quite so extensive. It's a big deal to me, personally.

Nope, I don't have any experience doing android dev in it.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
How do I adjust a date-time to a future time?

Say I have this date-time object:
May 31 2012 10:54AM UTC

How do I adjust its time portion to something like 10AM but have it go forwards, so I end up with June 1 2012 10:00AM UTC instead of May 31 2012 10:00AM UTC?
I'm really bad at calendar stuff so I have no idea what the hell.

I'm using the ThreeTen alpha builds but I can presumably adapt a JodaTime solution/similar to work with it.

Doctor w-rw-rw-
Jun 24, 2008

Aleksei Vasiliev posted:

How do I adjust a date-time to a future time?

Say I have this date-time object:
May 31 2012 10:54AM UTC

How do I adjust its time portion to something like 10AM but have it go forwards, so I end up with June 1 2012 10:00AM UTC instead of May 31 2012 10:00AM UTC?
I'm really bad at calendar stuff so I have no idea what the hell.

I'm using the ThreeTen alpha builds but I can presumably adapt a JodaTime solution/similar to work with it.

A quick hack, and potentially the best solution, would be to replace the time portion of the date with 10AM, compare it to the old one, and if it's earlier, add a day.

See: http://joda-time.sourceforge.net/apidocs/org/joda/time/DateTime.html
withTime(...) and plusDays(1). Or withTimeAtStartOfDay() and plusHours(10) instead of withTime().

Rescue Toaster
Mar 13, 2003
Has anyone tried out JavaFX 2 & FXML? Is there any point in learning it? I use WPF/xaml/NET at work all day, but at school everything is Java.

Going from building crazy layouts w/ two-way databinding in minutes to hand-coding swing is just killing me, and I figured FXML might be a bit more sane, but if it's just a total dead-end, I don't want to waste the time on it.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I'd say that Java UI applications are a dead end to begin with.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Is there even a decent JavaFX UI designer? The tutorials I tried with it were all written by hand.

In other words, no, it's not going to be as good.

Doctor w-rw-rw-
Jun 24, 2008

MEAT TREAT posted:

I'd say that Java UI applications are a dead end to begin with.

Agreed, but if one *really* wants to do UI on Windows, then SWT is probably the toolkit to use (see http://www.eclipse.org/articles/article.php?file=Article-Understanding-Layouts/index.html for a small example). It'll look typically bland like most Java UIs.

There's also 'clutter' and java bindings for it, neither of which I have ever used, but if you're going to want an application to look good, Java won't help you.

Rescue Toaster
Mar 13, 2003

carry on then posted:

Is there even a decent JavaFX UI designer? The tutorials I tried with it were all written by hand.

In other words, no, it's not going to be as good.

That doesn't bother me, when writing XAML I keep the 'designer' closed all the time anyway. In a way, that's the point of a markup language for UI layout. Doesn't Android use a markup language of some kind for UI?

But I guess Java UI outside of Android seems pretty dead. Unfortunately I'm taking an Image Processing class (like filtering, color manipulation, fourier transforms, etc...) and it's all in Java. Not looking forward to writing a photoshop knockoff in swing...

Butt Soup Barnes
Nov 25, 2008

Nevermind, I am dumb.

baquerd
Jul 2, 2007

by FactsAreUseless
I have an application running continuously. As part of that application, once a day a start condition will be met (items are added to a queue by user). Once that happens, every 30 seconds or so I need to check for an end condition, then perform a task (deal with the queue). After the task is performed, I have no reason to want the timer to keep firing. Is there a better solution?

Java code:
private Timer queueTimer = new Timer("queueTimer");
private TimerTask currentQueueCheckTask = null;

private TimerTask getQueueCheckTask() {
  return new TimerTask() {
    public void run() {
      if (canSendQueue()) {
        sendQueue();
        this.cancel();
        currentQueueCheckTask = null;
      }
    }
  };
}

private void addToQueue(Object val) {
  queue.add(val);
  if (currentQueueCheckTask == null) {
    currentQueueCheckTask = getQueueCheckTask();
    queueTimer.schedule(currentQueueCheckTask, 30000, 30000);
  }
}
There's a bit more to it than that, and it's modified in my code to deal with concurrency issues, but is the basic form good or is there a better way?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
For something like that I'd probably use Quartz:
http://quartz-scheduler.org/

baquerd
Jul 2, 2007

by FactsAreUseless

trex eaterofcadrs posted:

For something like that I'd probably use Quartz:
http://quartz-scheduler.org/

I've used Quartz but I don't see how it would make things more elegant? It seems like I would just be using a SimpleTrigger to execute a Job instead of a Timer to execute a TimerTask.

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

baquerd posted:

I've used Quartz but I don't see how it would make things more elegant? It seems like I would just be using a SimpleTrigger to execute a Job instead of a Timer to execute a TimerTask.

Mostly to externalize the configuration and have an de facto industry standard component for task scheduling. More software engineering than development elegance, I suppose.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I need to split up an array into smaller arrays of a certain size, so I came up with this:

code:
    public static <T> List<T[]> chunkArray(T[] items, int chunkSize) {
        List<T[]> chunked = new ArrayList<T[]>();
        if ((items.length == 0) || (chunkSize <= 0)) {
            return chunked;
        } else if  (items.length < chunkSize) {
            chunked.add(items);
        } else {
            int numChunks = (int)Math.ceil((double)items.length/(double)chunkSize);
            for (int i=0;i<numChunks;i++) {
                int start = i * chunkSize;
                int end = start + chunkSize;
                chunked.add((T[]) ArrayUtils.subarray(items, start, end));
            }
        }
        return chunked;
    }
Is there anything wrong with this? I haven't used generics much, and I get an 'unchecked cast' warning, so I wasn't sure if I was going about this the right way.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Go here:
http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/index.html

and look up Lists:

http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/collect/Lists.html

there's a partition method. Use that.

If you can't add another library to your code, then get it from git and put the guts of that method into yours.

Adbot
ADBOT LOVES YOU

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Awesome, third party libraries are a-ok. I thought for sure Apache Commons would have something to do this, but I couldn't find anything in there. Thanks for the links, definitely gonna use this instead. Looks like there is a ton of other useful stuff in this library as well.

At any rate, can somebody rip apart my method and tell me why it sucks?

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