Advice for a Java newbie taking a Java + Algorithm intro class.

Status
Not open for further replies.
Okay, So I took a class in Python about a year ago with a really nice professor (basically Comp Sci I class), who was extremely supportive of students having problems with learning the language and the syntax. Having passed that course with flying colors, I'm now thrust into a class with a professor that's a total dickwad, the kind that is out to get you (Comp Sci II, with my previous class being the prerequisite). He advertises the class as a focus on data structures and creating efficient algorithms with a side of java, basically its very little java, and a whole lot of other stuff. To me as a comp sci newbie, putting a very syntactic and type literal language of which I have had virtually no prior exposure to (I tried a little self-teaching to no avail) combined with a focus on data structures and algorithms sounds like trying to maneuver a wheelchair up a flight of stairs. The main questions I'm asking are:

- Can I expect there to be some traps with this combination, i.e, lack of java immersion proves to be fatal in the long run or is java actually rather easy for teaching data structures and good algorithm practices.
- What kind of bad habits can I develop from going from Python to Java that I can avoid so I don't get chewed out.

Textbooks are Algorithms and Data Structures and Head First Java
IDE is BlueJ

edit: reworded the thread title for more relevance
 

TheDan666

Ars Tribunus Militum
2,359
Well no one can really say for sure since we can't really know you, this professor, or what the class is going to be about. I think obviously it will be harder for you since you have to learn the lanauage just to be able to even START solving the problem. I've never taken an algo class (wish I had but was MIS major). I think you have 3 possibles good things in your favor:

1) Learning Java. Certainly a good language to know.
2) There are extensive Java resources on the web, books, etc.
3) Because it's an algo class I would think your code would be quite localized and focused. This is pure conjecture on my part, but, you will be doing very localized and specific programming to solve specific problem. It's not as if you're having to write an entire project with multiple packages, layers, etc. So you're lack of not knowing the lanaguage won't be as much as hude impediment. Again, pure conjecture.

--The Dan
 
The Python class covered most of standard topics, (classes, file I/O and basic GUI creation using more simplified libraries than Tkinter) and we spent most of the time writing simple programs, such and dice rollers, poker games usually with simple GUI's. This particular professor is very by-the-book, he most likely will take nearly all the course materials from them. It also seems that hes a "there's one correct way of doing this" kind of criticizer. If you use a for loop to solve a problem that a while loop can do in two less lines, he chews you out. In the first class period alone, he straight up took a python program and translated it into java, but explained virtually nothing about what he was doing and why he was doing it what any of it means.

The more I'm thinking about this, what seems the most hazardous portion of this "essentially" introductory course is the fact that the professors "my way or the highway" approach is going to cause tons of problems in learning the material. Java itself doesn't seem terribly hard, but I have a feeling this professor is just going to make it hard on purpose which is why he smushed an algo class into an introductory course.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
There is a very good chance that, for any data structure out there, there is an open source implementation in Java. The sheer ubiquitousness of it will help there.
Not all of them will be *good* many will have bugs, but they will be out there.

This will make it easier to get a second opinion of sorts on what is being done, not as a means of copying, but to see if the comparison of the two approaches helps you understand.

As to the use of java, for most data structures none of the OO aspects will be remotely relevant so really it boils down to writing C like code on a platform with array bounds checking and null reference checking. This is definitely a net win for what you're doing, be it building reference based structures (many trees and graphs) which would be likely be implemented in terms of pointers if the course was done in C or C++ or for ones based on using arrays (as you might for Heaps and the like).

Since you also get GC memory recovery the tree/graph structures get even easier to do since you don't have to worry about the cleanup (all these benefits would have applied were you using python too, it's just that it could be worse).

I should also point out that some universities take the view that, once you have learnt a 'paradigm'* in one language you should be capable of teaching yourself any other language in broadly the same genre and expect you to do that yourself (certainly that was the case in mine). With the exception of the type system (static verses dynamic) python is pretty much strictly more powerful than java** going to it as a language (as opposed to a platform) should be fairly simple if you can force yourself to be stop using any of the functional aspects of python unless you start dealing with generics.

* sorry
** in terms of the assistance from the compiler in providing more of the implementation compared to boilerplate either via syntactic sugar, support for first class functions/events and closures
 
ShuggyCoUk":pipcs6mz said:
As to the use of java, for most data structures none of the OO aspects will be remotely relevant so really it boils down to writing C like code on a platform with array bounds checking and null reference checking. This is definitely a net win for what you're doing, be it building reference based structures (many trees and graphs) which would be likely be implemented in terms of pointers if the course was done in C or C++ or for ones based on using arrays (as you might for Heaps and the like).

So if I understand you correctly, most data structures in java are basically functional programming rather than being represented as objects. Sounds like the love-child of Python and C. You also make it seem like having static arrays is a good thing but from my experience with Python, being able to change the length of lists and dicts was a godsend on some of the applications that I was working on (other than the occasional error resulting from using a non-existent index on a list).

ShuggyCoUk":pipcs6mz said:
I should also point out that some universities take the view that, once you have learnt a 'paradigm'* in one language you should be capable of teaching yourself any other language in broadly the same genre and expect you to do that yourself (certainly that was the case in mine). With the exception of the type system (static verses dynamic) python is pretty much strictly more powerful than java** going to it as a language (as opposed to a platform) should be fairly simple if you can force yourself to be stop using any of the functional aspects of python unless you start dealing with generics.

* sorry
** in terms of the assistance from the compiler in providing more of the implementation compared to boilerplate either via syntactic sugar, support for first class functions/events and closures

So Essentially once I learn the libraries and get past the syntax its not much different other than not being able to actively use an interpreter to make changes on the fly. It may be difficult to get used to using classes for everything, as only the last two weeks or so in the python class did we actually deal with classes and interactions between them. the rest was purely functional code.
 

fitten

Ars Legatus Legionis
55,634
Subscriptor++
You can have algorithms and data structures classes that use no language at all ;) The language/platform chosen are just implementation details :)

So Essentially once I learn the libraries and get past the syntax its not much different other than not being able to actively use an interpreter to make changes on the fly

Modern IDEs are very fast... so you hit "run" each time instead of "refresh" in your browser... not a big deal, IMO. It'll probably take about the same amount of time for small projects. In fact, some IDEs/platforms let you make some changes on the fly as you debug ;)

You also make it seem like having static arrays is a good thing but from my experience with Python, being able to change the length of lists and dicts was a godsend on some of the applications that I was working on (other than the occasional error resulting from using a non-existent index on a list).

Depends... sometimes it means you don't know enough about what you're doing or what you expect so it's basically slop it in, slop it out. However, most modern languages/platforms have lists and dictionaries that grow as you need them to grow.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
A data structures course normally starts with just arrays or pointers/references because they are the fundamental building blocks of anything else in a flat memory model: something relative to another one (arrays), something positioned absolutely (pointers).

Java's ability in terms of functional programming is close to zero sadly. In many cases you will be forced to create a class that really represents a function for example. This is not too much of a pain if you are starting implementing the structures themselves, though normally it is a bit more verbose. It is more of a pain when you start wanting to implement generalised algorithms over them where you may start to taught the cludge that is the visitor pattern rather than the far more useful concept of catamorphisms.
 

Faramir

Ars Legatus Legionis
36,356
Subscriptor
Fair warning: this course is likely going to suck. It was my least favorite CPS couse I ever took.

With a modern collection library you need to know when to use various different data structures, sorting and searching algorithms. Instead of teaching you that directly this class will make you implement them. It will also probably force you to compute O running times by hand even though it is trivial to look them up.

At least you won't have to deal with pointer arithmetic on top of all that though. Count your blessings on that one.
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
Faramir":18aeo3b6 said:
Instead of teaching you that directly this class will make you implement them. It will also probably force you to compute O running times by hand even though it is trivial to look them up.
Yes. Because implementation is critical to intuitively understand. Knowing that a binary tree is O(log n) for searching is meaningless unless you understand what O(log n) implies.
 

benInMa

Ars Tribunus Militum
2,201
So if I understand you correctly, most data structures in java are basically functional programming rather than being represented as objects. Sounds like the love-child of Python and C. You also make it seem like having static arrays is a good thing but from my experience with Python, being able to change the length of lists and dicts was a godsend on some of the applications that I was working on (other than the occasional error resulting from using a non-existent index on a list).

The Python resizable arrays, lists, etc.. are higher level data structures. Java has them as well, only they are implemented as code rather then part of the language. Actually they are likely just be objects in Python too, and then the language throws in some convenient syntax to use them with. (I haven't done enough Python to get into it's internals much) The entire point of this course is to teach you to write the higher level data structures yourself. While it is not super common to have to create/recreate these from scratch, it's a crucial part of learning Computer Science, and in "serious" software development you will still need to be able to create specialized data structures yourself from time to time.

If you're actually trying to get a CS degree you should be excited about this class. Python is probably too high level to teach this class, and that's why they're teaching you in Java. This material tends to be one of the first "weed out" classes in Computer Science. It'd probably be even better if they were teaching it in C or C++, as even in Java they're still leaving out some very important concepts by allowing you to use the Garbage Collector.

You will need very little of the Java Syntax for this class, and if you're cut out for this field of study you should be able to pick that syntax up extremely quickly. (It is an extremely reasonable requirement in a CS program IMO) Java's core syntax is pretty small if you ignore generics, threading, inner classes, etc.. which you wouldn't need for this class. What takes a while to learn with Java is all the libraries that tend to be used in real world software. Actually if he is good the professor should be teaching generics as part of this class, they fit in well with data structures and it is a natural fit to make you implement the data structures as generic types.

When I was in school (I graduated 11 years ago) our CS2 class covered most of this material in C++. It was the first weed out course and cut a lot of people out of the major. The next class covered algorithm analysis and probably cut the majority of the rest of the people out who were not going to make it. After that there were only a couple more really hard courses, a class on Models of Computation, and a class on Programming Language design. After that a large # of the typical undergraduate elective stuff is very easy in comparison.
 
benInMa":2jc7dbmd said:
You will need very little of the Java Syntax for this class, and if you're cut out for this field of study you should be able to pick that syntax up extremely quickly. (It is an extremely reasonable requirement in a CS program IMO) Java's core syntax is pretty small if you ignore generics, threading, inner classes, etc.. which you wouldn't need for this class. What takes a while to learn with Java is all the libraries that tend to be used in real world software. Actually if he is good the professor should be teaching generics as part of this class, they fit in well with data structures and it is a natural fit to make you implement the data structures as generic types.

When I got back from the first class, I opened up the textbook and started working through a few of the examples and I immediately began to get a majority of the syntax after about 15-20 minutes of typing it. It's some of the stuff from today's lab which was arrays and the ArrayList library which promptly caused my brain to implode trying to figure out the difference between the two (or why the hell I was using ArrayList when making an array could have been much simpler...) It seems like they both perform the same function just that ArrayList allows for fancier stuff.
 

Faramir

Ars Legatus Legionis
36,356
Subscriptor
Blacken00100":4fgi24yv said:
Faramir":4fgi24yv said:
Instead of teaching you that directly this class will make you implement them. It will also probably force you to compute O running times by hand even though it is trivial to look them up.
Yes. Because implementation is critical to intuitively understand. Knowing that a binary tree is O(log n) for searching is meaningless unless you understand what O(log n) implies.

Perhaps, perhaps not. I'm not an expert in pedagogy. But I do know I did not like it at all.

------
Tigranis:
Among other things primitive arrays in java can't grow dynamically. They have to have to have a fixed size when they are instantiated.

Understanding something like this cheat sheet is more or less the point of your class
http://www.coderfriendly.com/wp-content ... ons_v2.pdf
 
Faramir":1y5mtghe said:
Tigranis:
Among other things primitive arrays in java can't grow dynamically. They have to have to have a fixed size when they are instantiated.

Understanding something like this cheat sheet is more or less the point of your class
http://www.coderfriendly.com/wp-content ... ons_v2.pdf

rep++ to you sir, this looks like my new best friend.
 

topham

Ars Legatus Legionis
13,756
Subscriptor
benInMa":j4ri68zt said:
It'd probably be even better if they were teaching it in C or C++, as even in Java they're still leaving out some very important concepts by allowing you to use the Garbage Collector.

No, it isn't better to teach it in C or C++.

You're better off teaching it in a language that will alert you to memory faults, or one that doesn't allow it in the first place. I learned linked-lists, and a few other basic structures in C on my own before College. In college we did them with fixed sized arrays in COBOL (of all languages, yuck). I can say without a doubt that doing it in COBOL was far better than C because it was exceedingly difficult to end up working out of bounds. I helped out in a C class that was being expanded for newer students and it took a lot of work to get them to understand pointers, never mind how they trashed memory when they did things wrong.

It's difficult to teach data structures in C without pointers, and it's impossible to teach pointers and structures effectively at the same time. A good understanding of one is of a fantastic benefit to learning the other if you're performing those tasks in C. Doing both means only the top couple percent in the class are likely to actually learn both.
 
Status
Not open for further replies.