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
TheresaJayne
Jul 1, 2011

mustermark posted:

I've only started to get into Java programming for work, and I gotta say that JDBC makes me physically ill and depressed. Are there any good modern guides on it, or am I stuck with having to write twenty lines of ps.setHate(..., "Fury");?

You could move up from JDBC to hibernate, it does run as a standalone, and if you are using 1.5 or higher you can use annotations...

code:
@Entity
@Table (name="users")
public class Users  implements Serializable{
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)	
	@Column(name="user_id")
	private int user_id;
	@Column(name="user_name")
	private String user_name;
	@Column(name="user_password")
	private String user_password;
	@Column(name="user_level")
	private Integer user_level;
and

code:
      public Users getRecordByUsername(String userName) {
		SessionFactory session = HibernateUtil.getSessionFactory();
		Session sess = session.getCurrentSession();
		Transaction tx = sess.beginTransaction();
                Users tempUser = (Users)sess.createQuery("from Users where user_name = ?").setString(0,userName).uniqueResult();
                return tempUser;
        }

Adbot
ADBOT LOVES YOU

TheresaJayne
Jul 1, 2011

iam posted:

Anyone any tips on the easiest/best method for utilising properties files to store system messages?

I want to move all my "Error parsing comms" etc messages to a properties file, so that the system/API can just import com.x.pz.messages and then use the constants held within (that have been populated from the properties file).

Ideally I'd like the properties file to look like:

code:
COMMS_ERROR = "Error parsing comms"
VALIDATION_ERROR = "Error validating packet"
And then just be able to use the property names as the constant names, without having to manually do something like:

code:
final String COMMS_ERROR = properties.getProperty("COMMS_ERROR");
For the dozens of system messages...

Once I've imported com.x.pz.messages I'd like to then just substitute them in as you'd expect:

code:
throw new CommsErrorException(COMMS_ERROR);
Edit: Ignore, should have spent 30 more seconds Googling :P

code:
for(String key : properties.stringPropertyNames()) {
  String value = properties.getProperty(key);
  System.out.println(key + " => " + value);
}
Edit 2: No in fact, the above snippet doesn't answer the question. HALP. I don't know if it's going to be possible unless there's an elegant method to do it, i.e. there's no way you can do final String <key> = properties.getProperty(key); - the compiler will surely just tell you to gently caress off? I suppose one solution would be to populate a HashMap using the properties file, but then that's not as clean when you have to do:

code:
throw new CommsErrorException(hm.get("COMMS_ERROR"));

Well at a previous place we had a wrapper called CachedTypedProperties
code here https://gist.github.com/1185736

Theresa

TheresaJayne
Jul 1, 2011
XSLT is easy when you start but can get really complex,

I used to take XML output from a Java program and using an XSLT template convert it into XML-FO which i then passed into Apache FOP to make PDF output files.
once i did someone a simple example on irc - everyone said that it was way to complex :)

TheresaJayne
Jul 1, 2011

baquerd posted:

Most likely annotations confuse them and they just don't trust those screwy things.

I worked for a company that refused to use that crazy thing called hibernate because the owner who was old school IT didnt believe it was better and people were fired for suggesting that they use hibernate rather than manually write JDBC interface classes that did the same as hibernate but not as slickly.

(this was in 2010)

TheresaJayne
Jul 1, 2011
brilliant coverage on how to debug, but when you have been programming for a while you KNOW what the problem is..
for me i saw on the marked line in one of the posts inside a loop

if(variable[loop] > variable[loop +1]

instant red alert there...

what happens at the end of your loop

[1,2,3,4]

last one loop = 3

if(variable[3] > variable[4]) <---- out of bounds, the array has 4 entries 0-3 so 4 is out of bounds.

if you are going to do it this way then do it on the loop as
for(a=0; a< variable.length() -2;a++) so it will work


me personally i would probably do it using recursion - too deep into my current epic/stories at work to put my mind to the actual solution though

Just my 2p/c on the comments already made.

TheresaJayne fucked around with this message at 11:11 on Apr 10, 2013

TheresaJayne
Jul 1, 2011

rhag posted:

How would you store the database credentials? I would love to see another idea (properties file, datasource file, whatever other configuration file). I'm asking because I had few years back a security guy saying the same thing that the database credentials were stored in the jboss datasource file on the server in plain text (only the _jboss user could read it, but ... it was there). His idea was to split the password up in at least 5 pieces and encrypt them all. I personally think that's overkill, but I'm open to any ideas that one may have on how to improve that.

I don't know about Tomcat but JBoss has a utility for encrypting DB passwords and creating a hash.

The tomcat docs say the following

quote:

If using digested passwords with DIGEST authentication, the cleartext used to generate the digest is different. In the examples above {cleartext-password} must be replaced with {username}:{realm}:{cleartext-password}. For example, in a development environment this might take the form testUser:localhost:8080:testPassword.

TheresaJayne
Jul 1, 2011

Hard NOP Life posted:

What does JBoss use for a encryption key and does it allow you to reboot the server without prompting for a password?

JBoss has a utility that encrypts the key

quote:

15.1.1. Encrypt the data source password

The data source password is encrypted using the SecureIdentityLoginModule main method by passing in the clear text password. The SecureIdentityLoginModule is provided by jbosssx.jar.

Procedure 15.2. Encrypt a datasource password

This procedure is for JBoss Enterprise Application Platform versions 5.1 and later

Change directory to the jboss-as directory
Linux command

java -cp client/jboss-logging-spi.jar:lib/jbosssx.jar org.jboss.resource.security.SecureIdentityLoginModule PASSWORD
Windows command:

java -cp client\jboss-logging-spi.jar;lib\jbosssx.jar org.jboss.resource.security.SecureIdentityLoginModule PASSWORD
Result:

The command will return an encrypted password.

http://docs.jboss.org/jbosssecurity/docs/6.0/security_guide/html/Encrypting_Data_Source_Passwords.html

TheresaJayne
Jul 1, 2011

Win8 Hetro Experie posted:

My previous post probably read like I was ragging on TheresaJayne, but it wasn't my intention. I don't know much about security, but what I know is that security is hard. There may well be good reasons and proper places for using such simple encryptions. I'd just be wary of anything that smells like security by obscurity, because with my knowledge the first person being obscured is me myself.

I was just raising the issue, I had to look at it for our production systems,
the idea is rather than having in the JBoss config files like this

code:
<datasources>
   <local-tx-datasource>
      <jndi-name>DefaultDS</jndi-name>
      <connection-url>jdbc:hsqldb:${jboss.server.data.dir}${/}hypersonic${/}localDB</connection-url>
      <driver-class>org.hsqldb.jdbcDriver</driver-class>

      <!-- The login and password -->
      <user-name>sa</user-name>
      <password>letmein</password>

</datasources>

you encrypt the password using the parameters and then put the following

code:
<application-policy name = "EncryptedHsqlDbRealm">
       <authentication>
          <login-module code = "org.jboss.resource.security.JaasSecurityDomainIdentityLoginModule"
          flag = "required">
             <module-option name = "username">sa</module-option>
             <module-option name = "password">E5gtGMKcXPP</module-option>
             <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=DefaultDS</module-option>
             <module-option name = "jaasSecurityDomain">jboss.security:service=JaasSecurityDomain,domain=ServerMasterPassword</module-option>
          </login-module>
       </authentication>
    </application-policy>

TheresaJayne
Jul 1, 2011

Fly posted:

Another thing is that I don't want my build going out to the network unless I tell it to do so. This is another reason not to have automatic updates since those would need to check some network resource.

Maybe I should look at Maven 3. It could be nice to grab dependency updates, but only when I ask for them explicitly, such as when I make a new release tag/version in the source control system.

Well Maven will get the latest if you do not specify the version you want.

If you define a version of your dependency then it will never update. but the nice thing is if you say want to use MyBatis with Spring any dependencies needed by the versions on Spring you are using will be automatically installed and you have locked your version to the one you want.

Also if you have it set up correctly you will only hit the network on first add, as after its downloaded once, it resides in the M2 cache.

TheresaJayne
Jul 1, 2011

Fly posted:

Cool. Presumably one could prepopulate the cache with versions from source control, yes?

You can do a maven install which will install the jar/war file into the M2 cache for use in another project.

quote:

The Install Plugin is used during the install phase to add artifact(s) to the local repository. The Install Plugin uses the information in the POM (groupId, artifactId, version) to determine the proper location for the artifact within the local repository.

The local repository is the local cache where all artifacts needed for the build are stored. By default, it is located within the user's home directory (~/.m2/repository) but the location can be configured in ~/.m2/settings.xml using the <localRepository> element.

TheresaJayne
Jul 1, 2011
I know its not really Java but at the weekend i was looking to do some work with minecraftforge and create my own Mod,

I am an Intellij Idea girl and have purchased my own copy.
Could i get it working ? NO

Could i get help in getting it working in Idea? NO

The advice I got from the IRC support was Use Eclipse as we include a preconfigured Workspace

Why can't they be open and tell us how to get it working in ALL IDEs rather than just their favorite version, as I don't want the hassle of 3-4 IDEs on my system when I mainly use 1 .
(3-4 includes, Idea, Eclipse, Netbeans, JCreator(yes i bought this one as well))

TheresaJayne
Jul 1, 2011

General Olloth posted:

Come in #technicdev on synirc sometime and ask around. I'm going to PAX in a couple hours but next week I can be around to step you through it OR someone in the channel might be able to help you anyway. We have a bunch of modders in the channel.

Make sure you stick around and idle though because it's not active at all hours of the day but people will come back and read the logs and ping you/pm you responses.

Well i did the easy way and installed Eclipse, at some point i will work out the config and probably post a blog entry showing how to set it up on Idea.

TheresaJayne
Jul 1, 2011
We have a Converter that works using getters and setters found by reflection, there is a sort of issue with some of the logic with recursion but it works well,

The 3rd party library we use is net.vidageek.mirror.dsl.Mirror

http://projetos.vidageek.net/mirror/mirror/

TheresaJayne
Jul 1, 2011

supermikhail posted:

I've got writer's block.

This application that I want to store preferences for, I just realized that I have to start with something - I have to have a default path where I would store all the non-default paths. I could slap it right in the home folder like the amateur I am, but maybe there's some trick that adult apps use? I'm also worried that if I slap the file there I might overwrite another one that accidentally has the same name but doesn't belong to my program.

Brethren (and sistren), what say ye?

How about you have code in your app that on startup looks in current folder for the file,
if it doesnt exist create it

As an example look at minecraft server, when you first run it will check for the ops.txt file and create it if it is not there.

TheresaJayne
Jul 1, 2011

rhag posted:

Oh, ok, so some flags then should solve the problem:
code:
        boolean containsUnderscore = false;
    	boolean containsUppercase = false;
    	for(char c: ch){
    		containsUnderscore |= c=='_';
    		containsUppercase |= Character.isUpperCase(c);
    	}
    	

I am feeling as if i have been morphed over to the Post code that makes you laugh (or Cry)

why not just try a decent Regex

regexp="^.*(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z0-9!@#$%]+$")

TheresaJayne
Jul 1, 2011

rhag posted:

I've read and re-read his posted requirements. My solution was the simplest thing that met them. And most of the time that's the correct one. He nowhere said that he's trying to learn regex, but that he stumbled upon them while doing his research. My take on it is that, while regexes are useful for a lot of things, this is not one of them.
He can solve the problem with them, but he doesn't have to, and he'll be better of not to at this stage.

Then again ... you're right, I don't have to bother trying to post code. You're doing a fine job, keep going.

Sorry rhag I disagree,

Your solution was clunky and it was just a code smell to me.

The Regex I posted does everything the OP wanted and we use it as a validation regex under Spring MVC validation. Our passwords have to be 8 characters + at least 1 Caps and 1 Number

TheresaJayne
Jul 1, 2011

PlesantDilemma posted:

Newbie here. I'm using Maven and NetBeans 7.4. How do I get maven to copy some xml & properties files from src to target when I run `mvn package`? The files are in src/main/java/com/mycompany/reports/config. When I run the jar it keeps dying saying it cant find the files in target/classes/com/mycompany/reports/config. I've been surfing the maven site for a while but I'm not seeing what I need to put in my pom to get it to copy the files.

Don't you need to put them in the src/main/resources/... folder?

TheresaJayne
Jul 1, 2011

more like dICK posted:



Do I need to manually call afterPropertiesSet on either of these? Why or why not?

I did a tutorial post a while back for Spring standalone maybe that will help....

http://girlcoderuk.wordpress.com/2013/07/14/configuring-hibernate-and-spring-for-standalone-application/

TheresaJayne
Jul 1, 2011

Volmarias posted:

Java also needs an IDE whereas with Python you really can get away with a smart text editor for a long time. Pick up Eclipse or IntelliJ and spend a little time learning to use it.

You can do Java and Python with Vi if you need to, I prefer an IDE but at a push Notepad++ is brilliant for any language.

TheresaJayne
Jul 1, 2011

Lord Windy posted:

In Intellij, is there a way to put a 'build artifact' button up around where the run button is? I'm making a project and due to how I'm making my folder structure it is just going to be easier to run a Jar than faff about changing strings.

The build menu option is next to the run menu option

But you can also set a hot key for build artifacts
I used to build my webpage output with CTRL-SHIFT-'

TheresaJayne
Jul 1, 2011

Kilson posted:

Supposedly the error happened with -Xmx4g also, but I can't directly confirm that.

java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

The VM has 2 CPU cores and 8GB memory available to it. Nothing else is really running on the machine. That should be enough real memory for the JVM.

On my local machine with the same amount of memory, I can start the server with -Xmx8g without issue, even with a billion other things running in the background. The JVM doesn't care about how much memory is physically available until the heap actually becomes full enough for it to matter.

Unfortunately, the machine with the problems is not a machine I have access to, so I can't play around with it. I've looked at a couple VMs with similar allocations and haven't seen the problem there.

I have seen VMs work as 32bit even when supposed to be 64,
I have a 64 bit machine at work but am running a 32 bit eclipse (company build)

I have seen on my machine with 8gb of ram that java can only access the 32 bit amount. meaning i can max use -Xmx1524m

as -Xmx1525m causes a cannot create VM error.

TheresaJayne
Jul 1, 2011

supermikhail posted:

I tried to be fancy with a search field the following way:
code:
    private void filterFieldFocusGained(java.awt.event.FocusEvent evt) {                                        
        if (searchTerm == null) {
            filterField.setText("");
        }
        filterField.setForeground(UIManager.getColor("TextField.foreground"));
    }                                       

    private void filterFieldFocusLost(java.awt.event.FocusEvent evt) {                                      
        if (searchTerm == null) {
            filterField.setText(EMPTY_SEARCH_MESSAGE);
            filterField.setForeground(UIManager.getColor("TextField.inactiveForeground"));
        }
    }
That is, when the field is empty, I put in a message indicating what it's for, but to avoid then searching for the message, I have the searchTerm variable. Now I have a problem that I can't paste the clipboard into the empty field from a popup menu (keyboard shortcuts work). I'm not sure how to approach this - maybe mouse events, or just scrap the message system and replace it with the regular popup hint. What do you goons think?

Hook into the onChange event as well as the focus event

TheresaJayne
Jul 1, 2011
I would actually be more likely to use for(Circle circleFromArray : listOfCircles)

as fromArray doesn't say WHAT is fromArray ...

TheresaJayne
Jul 1, 2011

Yhag posted:

Hopefully a simple question:

Using Netbeans I created most of a small triangulation program for an assignment:



The grid is a seperate JPanel, relevant code:

code:
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);

        g.setColor(Color.white);
        g.fillRect(35, 0, 600, 375);
        g.setColor(Color.black);
        g.drawRect(35, 0, 600, 375);
        g.setColor(Color.LIGHT_GRAY);

        for (int k = 0; k < 14; k = k + 1) {
            g.drawLine(36, 25 + k * 25, 634, 25 + k * 25);
        }

        for (int l = 0; l < 23; l = l + 1) {
            g.drawLine(60 + l * 25, 1, 60 + l * 25, 374);
            
        }
    }
On button click it calculates 2 coordinates xC and yC. I want to draw a line from (xA,yA) to (xC,yC) and from (xB,yB) to (xC,yC), relevant code:

code:
                    class jPanel2 extends Plot {

                        @Override
                        public void paintComponent(Graphics g) {
                            super.paintComponent(g);
                            g.setColor(Color.red);
                            g.drawline(xA, yA, xC, yC);
                            g.drawline(xB, yB, xC, yC);
                            Plot.repaint();

                        }
                    }


I run into two problems:

- Using Plot.repaint(); I get the following error:
non-static method repaint() cannot be referenced from a static context.
Googling it gets me solutions that are more complicated (to me) than this problem seems.

- Using doubles xA, yA, etc in the g.drawline() tells me:
incompatible types: posible lossy conversion from double to int
local variable xA is accessed from within inner class; needs to be declared final
.

My Java experience is pretty much zero so googling these errors doesn't really help much.

Thanks

Well you are trying to access a non static method in a static way,
Plot.repaint() is static

why not try super.repaint();

you have already done that with the paintComponent.

TheresaJayne
Jul 1, 2011

pliable posted:

Is there a particular reason why you're casting all those ints, storing them into ints, then passing those ints along to your setxx methods instead of just casting them and passing them straight?

Like this:

code:
                    

                    pnlPlot1.setxA((int)xA);
                    pnlPlot1.setyA((int)yA);
                    pnlPlot1.setxB((int)xB);
                    pnlPlot1.setyB((int)yB);
                    pnlPlot1.setxC((int)xC);
                    pnlPlot1.setyC((int)yC);
                    
                    pnlPlot1.repaint();
It's not a huge deal but, I'm curious.

Well i have seen stuff like this in the past

code:
           int a = 10;
           int b = 0;
           b = (int)a;
Apparently this is because the person used to be a C++ developer and thats how they code C++ but i just think they had a problem with casting once and now cast everything just to be sure.

TheresaJayne
Jul 1, 2011

thegasman2000 posted:

The modules are:

Object-oriented Java programming (M250)
This module concentrates on aspects of Java that best demonstrate object-oriented principles and good practice, you'll gain a solid basis for further study of the Java language and object-oriented software development.

Software development with Java (M256)
Discover the fundamentals of an object-oriented approach to software development, using up-to-date analytical techniques and processes essential for specification, design and implementation.

I started those at one time about 10 years ago, they started easy and then got mega hard even for a seasoned pro,
I hope you have lots of time as there was soooo much studying.

Although they keep saying that courses are being dumbed down.

TheresaJayne fucked around with this message at 07:22 on Oct 1, 2014

TheresaJayne
Jul 1, 2011

fletcher posted:

Trying to setup SSL on Tomcat (APR):

code:
 
java.lang.Exception: Unable to load certificate key /usr/local/ssl/private/mycompany.com.key
 (error:0200100D:system library:fopen:Permission denied)
code:
[root@server bin]# ls -la /usr/local/ssl/private/mycompany.com.key
-rw-r----- 1 tomcat tomcat 1709 Sep 30 18:54 /usr/local/ssl/private/mycompany.com.key
What does it want from me? ps aux confirms tomcat was running as user tomcat, the owner of that file it can't read.

Whats the folder permission (.) if its owner is root, group root and permission 770 then nothing can see into the folder,

of course for folders you have read write and execute, but they mean different things.
you may need to add execute to allow access to the folder.

TheresaJayne
Jul 1, 2011

Necc0 posted:

Make sure your log entries are verbose enough that someone coming back and reading them three years from now won't be clueless and you'll be fine. If the exception has a good chance of breaking things that are calling your method or if it's a show-stopper you should hand off the exception so that the other objects accessing it know that something went wrong and can handle it at a higher level. If you can recover gracefully handle them locally.

I would like to add NEVER JUST THROW Exception make an Exception you can throw that shows what went wrong,

even if its just a MethodFailedException() we are being slated at work for throwing Exception as its bad coding practice (shame its because we are implementing an interface thats throwing it so its a false positive on SonarQube)

TheresaJayne
Jul 1, 2011

langurmonkey posted:

So I want to get up to speed on hibernate, preferably using maven etc. to get going. All the tutorials I have found seem to be slightly out of date in terms of configuration options or just flat out don't work. Does anyone have any suggestions for good online learning resources for this? Preferably something like an existing project that can then be tweaked to learn about hibernate rather than learning about screwing around with config files.

you could look at my blog post.

http://girlcoderuk.wordpress.com/2013/07/14/configuring-hibernate-and-spring-for-standalone-application/

TheresaJayne
Jul 1, 2011

ManlyWeevil posted:

Well, like you said, the general problem is fighting against java's type system. The problem is that the utility is essentially a translator: I'm working from one set of objects that are all of a single type, basically a serialized data object, and turning that into the corresponding business object. Unfortunately, due to legacy reasons, the business objects don't share any common inheritance hierarchy other than java.lang.Object so I might be stuck going all the way up to that point.

Or just add a new parent above

we had FormBean and ValueObject shoehorned into a previous project because the new head dev wanted it - i will say it made it much nicer and easier to use,
I ended using a similar start to my own project (seriously on hold due to getting bored of writing the boilerplate)
https://github.com/theresajayne/tranquility

TheresaJayne
Jul 1, 2011

carry on then posted:

And the JRE, yes. But obviously if it isn't working when you double-click the file that may not be the best experience. That's weird, though, why would it only work if you run it through the console? Does it take input from System.in or something?

This is common on Devs machines, i cannot double click a jar or war file to run it - i have those extensions in use by winzip (which is a default) meaning it stops it being run from double clicking a jar file - and a good thing too incase of virii

think what would happen if a normal user had a file kitten.jpg.jar

TheresaJayne
Jul 1, 2011

Lord Windy posted:

I was reading up on Java 9 and I was wondering what Modular Source Code means? I don't really understand this new feature that I should be getting excited with, but I guess like with Lambdas I probably will once I know what it is.

it also sounds like the current system where you check for another library existing and if it doesnt you have to currently have selectors to disable the code that needs that library,

so in future you may be able to do something like if(!exist(pixelmonModule)) { removeModule(PixelLinks) }

to remove the modules that cant be used.

TheresaJayne
Jul 1, 2011

rrrrrrrrrrrt posted:

Variable arguments.

Also, I find SO to be good for hard to Google syntax:

http://stackoverflow.com/search?q=java+%22...%22

beaten to the punch.

The nice thing is if you use a vararg in a method then its the same as an array[]

so
public static void main(String[] args)

is exactly the same as
public static void main(String args...)

TheresaJayne
Jul 1, 2011

ROFLburger posted:

This is a stupid question. I'm using java.util.logging and I feel like I'm doing something wrong. Does there exist a logging API where I don't have to create a new logger, level, and handlers in every class that I want to be able log from? It seems wrong to keep copy pasting this in all of my classes(that I want to log from) where the only difference is changing the filename to "classname.log". I'm wondering if theres a better way than jamming all of the logger setup poo poo into the constructor of each class?

Look at SLF4J and LOG4J

TheresaJayne
Jul 1, 2011

foonykins posted:

This is precisely where I'm hung up. Would another set of copies solve this issue? Would it, in sorts, work a kind of save-state when the method is called again?

Also, in terms of IDEs, im using NetBeans. I've never worked with a debugger before. I've heard great things about IntelliJ Idea but was having a hard time configuring it on my Mac. All that talk is for the IDE thread though.

Maybe not the solution, but one thing that makes me feel you are not doing it in the best solution, How are you determining the no repetitions?

The moment I hear no repetitions I start looking at Map HashMap to be precise. as Maps cannot have duplicate keys.and you could also store the nnumber of times the item is seen in the value if needed.

I will admit i an half asleep here just relaxing before heading to bed.

TheresaJayne
Jul 1, 2011

Bleusilences posted:

I am way not finish with my project obviously but I am running problems with my tester, this is the first class of programming and we just have learn about object oriented programming. I am have been at it for hours today without progress. So this is the main class (not finished):

and this is the tester (there is some stuff that is useless in there; it is just a tester) that gives me error:


Error: cannot find symbol
symbol: variable getSuit
location: variable card of type Card
and that error is driving me mad, I don't know why it's doing this and I check the internet and they mostly say that I forgot an ;. Which is not the case.

esit: I just realised my mistake, I forgot the put an () after the getsuit. :Facepalm:

I notice that your getSuitAsString() is not returning the suit.

its returning Ace Two Three Four Unknown instead of Clubs Hearts Spades Diamonds

TheresaJayne
Jul 1, 2011

FateFree posted:

I mean I hate to tell you this now but you really should be using enums for this stuff, enum Suit, enum Card even with a Suit and a value. Would make it a lot cleaner than the ints you have now.

I was about to say that,

TheresaJayne
Jul 1, 2011

FateFree posted:

The single biggest thing that separates a good programmer from a bad one is that a good programmer will go out of his way to make any complicated problem look simple, clean, and easy to understand. That means you gotta spend time commenting your code, breaking up methods that are hard to understand into simpler smaller ones, etc. If it looks bad to you now after youve been studying it, then yes i guarantee your eyes will be bleeding.

unless you follow the Agile - no comments clean code methodology in which case in 6 months you had better remember what it does

TheresaJayne
Jul 1, 2011

headlight posted:

Can anyone recommend what I should be looking at to start programming windows applications in Java (Swing or JavaFX)? I want to build a file explorer and mass renamer that is standalone and looks just like a Windows program.

As background, I'm a novice programmer that has so been working on command line programs in Linux with lots of XML processing. When I last looked at Java GUI making for windows in 2002 everything was ugly and slow, so hopefully things have moved on...

So far I've figured out I should first start using an IDE (netbeans I guess?), and second pick JavaFX or Swing to work on a GUI. I don't need fancy graphics (but keen for it to have a 'Windows' look and feel), so maybe JavaFX isn't worthwhile if I'm going to rely on lots of stackoverflow answers to help me struggle through. However if its much easier than Swing and better if starting from scratch I could look at that.

Any pointers welcome.

DO NOT USE NETBEANS!!!!

intelij idea community edition or eclipse luna at a push... but not the horror that is NETBEANS!

Adbot
ADBOT LOVES YOU

TheresaJayne
Jul 1, 2011

CarrKnight posted:

On the topic, does anybody here unit tests swing? I'd like to know what program you use, but also how to structure gui unit tests (i find it so hard to isolate the gui)

Unit Tests are supposed to test your business logic with some simple interface tests for DB and such.

If you are programming a MVC model you start testing at the controller and stop at the DAO.

If you work for a big corporation you will probably have to test from View Bean down to raw DB code.

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