Sign in to follow this  
tolsg

[java] Hurdles to learning Java

Recommended Posts

tolsg    122
I am not a greatly experienced programmer by any means, but I do know a thing or two about it, and am currently interested in learning more Object Oriented programming and in particular, learning Java. I have done some Cpp and various other languages, but Cpp always seemed to show you how to "Do stuff" and then kind of tack the object oriented part on in particularly odd and confusing ways(at least they confused me.) I was told that Java would be a nice way to get a firm grasp on the finer points of OOP. (I know it uses automatic GC, but I figure I can learn GC once I am used to OOP itself) Enter http://www.faqs.org/docs/javap/, a really nice tutorial. I really appreciate its approach, and it definitely has already taught me a lot. I think what I have read in it will even make it easier to use the OOP parts of C++ for me. (I *finally* grasped the concept of Classes spawning Objects, and the difference in static and nonstatic, which was a stumbling block for me because it was described poorly or in pure jargon to me in most Cpp tutorials, just as an example) Unfortunately, then I run into the "This tutorial of course assumes you are using JavaLavaLamp 1.3.4.5.6a on a modified, over clocked Macintosh Speak&Spell using the Commodore 64 OS" Of course, this is huge exaggeration, but the point is, I find that I am often spending 99% of my time struggling with things unrelated to the actual language. The Author uses a nice TextIO class that facilitates easier learning by letting the reader receive input from the user (something that I understand can be non-trivial to a Java newbie.) Now, I have tried both BlueJ and Netbeans, and they don't quite seem to work. Unfortunately, when I compile to an executable JAR file, it seems like it is missing huge amounts of information needed for an executable JAR to work.(It gives me an error that looks like it's missing a whole ream of definitions for displaying it) In short, I cannot get the program to actually "run" in a way that allows me to use TextIO properly, which the tutorial basically relies on. Converting each example to an I/O applet might work, but that would be a huge distraction for me. Perhaps this is the only way :/ ? What I need is advice regarding what the best combination of a tutorial, and an environment, to minimize the finicky details of the specific environments long enough for me to study the language(and OOP of course, which I am still very much learning) and do some experimentation without having to fight with reams and reams of unrelated issues. I'm not afraid to get my "hands" dirty, it's just that these little IDE and SDK details are too much for me and are stressing me out and effectively preventing me from going any further. I want to shave it down as close as I can to learning the pure language, and then dealing with the detail demons later. Any advice would be appreciated :)

Share this post


Link to post
Share on other sites
mako_5    103
What type of text i/o are you trying to do?

If you run your programs through windows command prompt a.k.a. "java program_class" this is how you can get text input.



import java.io.* ;

String str;
BufferedReader io = new BufferedReader(new InputStreamReader(System.in));
try{
str = io.readLine();
}catch(Exception e){}





Once you have the string you can extract whatever type of data that you need.



float f = Float.parseFloat(str); //works for Float, Integer, Double...etc.





Text output can be printed using "System.out.println(...)" or "System.out.print(...)" (println moves on to the next line after the text is printed).

In terms of the best IDE, there's a whole bunch of speculation on that. JCreator (http://www.jcreator.com) is what I use and works pretty well. You can get a freeware (LE) edition on the site.

Sun's Java tutorials are a good starting point.

GameDev also has some good articles in the Java section.

Once you get the fundamentals down jumping into graphics with Java is not simple, but not really hard at the same time. Definitely look into the full-screen mode tutorial section in the sun tutorials.

Check out here for a list of all standard library java classes. Very helpful for reference later on.

Let me know if these resources work out for you, and I'll see if there are any more that I've used that would be helpful.

Share this post


Link to post
Share on other sites
stormrunner    720
Quote:
The Author uses a nice TextIO class that facilitates easier learning by letting the reader receive input from the user

First, and foremost, I have to say that I intensely dislike tutorials that require the use of external classes or libs when teaching language fundementals. Second, it's not hard to obtain input from a user, just use a Reader like so :

InputStreamReader inputStreamReader = new InputStreamReader ( System.in );
BufferedReader stdin = new BufferedReader ( inputStreamReader );
boolean hasRequestedQuit = false;
String line = null;
try {
while (!hasRequestedQuit) {
// read a line from the console
line = stdin.readLine();
// parse for quit here
// echo whatever it was that was inputed
System.out.println(line);
}
}
catch ( IOException ex ) {
System.err.println(ex);
}



All TextIO is doing is casting the string input to the relevant data type, something that isn't hard just a mite bit tedious (for all the types). Imho, the developement of a class for such a task should be left as an exercise only.

Quote:
In short, I cannot get the program to actually "run" in a way that allows me to use TextIO properly, which the tutorial basically relies on. Converting each example to an I/O applet might work, but that would be a huge distraction for me. Perhaps this is the only way :/ ?

If it's such a simple program, and you're a Java beginner, why are you messing with executable JARS ? You should only create a JAR of your project when you plan to distribute it, because a JAR includes everything your program needs to run (data files, .class files, ect). It's just a pain to create one everytime you want to test your program. Furthermore, your IDE - even if it's the command line - should display your console output either in a command window, or a tab of it's own when you push "run" (or compile + run). After reading the relevant sections (of TextIO), you seem to have misunderstood what he's saying : an executable JAR != a .class file. To obtain a class file, all you need to do is compile the TextIO.java file (either by pushing the "compile" button, or javac TextIO.java on the command line), and then keep it in a directory on the classpath. That way, all the classes can use it.

Lastly, (and I apologize for the length of this) I'd recommend that you read The Java Tutorial, written by Sun Microsystems. If you're deadset on JARS, it's got a bit on that too. They also have a section onYour First Steps for those trying to get up and running with Java quickly.

<edit :: Wow, I'm slow ;). I'd like to add that should you need a quick reference for Java classes, a simple Google search should find the relevant Java docs as it's first entry.

Share this post


Link to post
Share on other sites
tolsg    122
Thanks for the advice, both of you. I will follow your advice and try the official Sun tuts and Jcreator. I'll post in this thread again if I need any more help:)

Share this post


Link to post
Share on other sites
daviangel    604
If you are serious about learning java get this book:
http://www.wickedlysmart.com/HeadFirst/HeadFirstJava/HeadFirstJavaIndex.html
References as remote controls to objects idea in pictures is worth the price of the book alone!
And it really pounded in the value vs reference types into my brain that I never really got before I guess.
If you download and look at the sharpen your pencils and book code it'll give you an idea if the book is for you not to mention they stick with the simple sdk from commandline while you learn.

Share this post


Link to post
Share on other sites
Darragh    308
I found these college notes really useful- in particular the stuff about object oriented programming:

notes

This is where i got to grips with all those strange object oriented programming terms such as 'abstract', 'polymorphism' and 'inheritence'. They are all explained nicely with some real world examples. I recommend you download the lot.

Best of luck,
Darragh.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this