Learning JAVA, any advice?

Status
Not open for further replies.

AytrusTekis

Smack-Fu Master, in training
77
I am trying to learn Java. I have been following along with the courses available through Oracles site, but feel as if the pace is a little slow, and their method is not really the best for me. I prefer a more hands on approach.

I understand the basics of how Java is structured, and I have made a few very very simple print.ln programs.

Any advice on other places I can go to really get a more hands on learning?

What I would really like to see, is complete programs with explanations on each piece of the program. Something like that... Here is a program, here is why it works and how it works.
 

AytrusTekis

Smack-Fu Master, in training
77
1) HTML from over a decade ago, and I have dabbled in scripting batch files and such. In other words, not really.

2) I like the modular object oriented structure of it. I like that I can develop plug in objects that would allow me to make complex programs from smaller simpler pieces that can be mixed and matched. And after doing some brief poking around I was directed to it as being a good starter language.

Honestly, this is more of a hobby thing than a career builder. I might really start to dig it and turn it into a career piece, but for right now, Im just testing the waters.
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
I would suggest not starting with Java, then. You can get all the stuff in #2 from a much better starter language. Python is often a good recommendation. It's not as performant as Java (which should not be an important consideration as a beginner), but it's conceptually simple and easily modularized.

The biggest reason I've seen to learn Python first are the beginner's resources, though. Here's the best beginner's book I've ever found for any language: http://learnpythonthehardway.org/book/
 
Yeah, I'd start with Python, or Ruby if you don't like the whitespace-for-block-indication style of Python. With Java there's a lot of overhead you have to learn just to get stuff running that isn't really needed for the basic goal of just learning how to program. Python you can just open a file (or shell session) and star writing code, and then build up to more complicated structures.
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
Python is in a hell of a lot of places. If you've run a Linux machine in the last ten years, you've (unknowingly) run thousands of lines of Python. Loads of people, Google included, use it extensively for web stuff--outside of the ASP.NET and Java stacks, which are pretty enterprisey, the web choices are basically PHP, Python, and Ruby. (No, not Perl. Fuck Perl. Don't even start.)

That said, "where is it used" is not a particularly relelvant question if you want to learn to program--because it'll run where you are. Once you've attained some level of familiarity with one language, moving to a similar language (and from Python, C# or Java probably count) is much easier.
 

dredphul

Ars Tribunus Angusticlavius
6,341
Subscriptor++
AytrusTekis":2l6r2fje said:
Starting off as hobby, aka In my free time. But if I really get into it, I can see it as a job option. That was part of the reason for choosing Java. However if Python will be a good place to start which can lead into Java, then I see no problem going that route.

If you are doing it as a hobby, choose a language like Python or Ruby. These are languages that are easy to get into and will have a quicker payoff. In many cases, you can get a working program in Python/Ruby with fewer lines of code than Java.

What ever language you choose, make sure you learn to use the interactive shell. The interactive shells allows you to just type in code and experiment.
 
dredphul":30zmhzow said:
What ever language you choose, make sure you learn to use the interactive shell. The interactive shells allows you to just type in code and experiment.

And that's one particular area where Python has a big advantage over Java.

Python will let you learn programming concepts and get a handle on some basic patterns for solving problems with code with a lot less worrying about the details. Stuff just takes a lot less lines of code since it has a neater syntax and is more expressive, so you can focus more on "how do I get this to do something cool" and less on "ok, so I want to turn this list of numbers into a list of strings... this will take me a few lines...".

There are good reasons for all the overhead required when writing in Java or a similar language, but none of them are "because it makes it easier to learn."
 
I think beginners get hung up on the fact that Programming Languages are called "Languages".

It is not a language like French or Russian, where if you spend 5 years learning Russian and decide you want to learn French, you have to start over from the beginning.

Programming Languages are more like driving a vehicle. A beginning driver might ask "what kind of car should I get to learn to drive?" to which there would be a myriad of opinions and answers given.

In the end, it probably doesn't matter that much. Regardless of what vehicle you start on, you will learn skills that are wholly transferable to a new vehicle. Sure, driving an 18 wheeler is significantly different than driving a Ford Taurus, but there is commonality that transfers, and very much so at the fundamental levels. Even if your end goal is to drive an 18 wheeler, it would probably be better to start with a smaller, more conventional vehicle with less complicated distractions so that you can focus on and master the fundamentals. This is why you are hearing Python a lot. Whatever language you start in, good programmers usually end up working in a variety of languages over their career and have solid fundamentals which allow them to be effective in a variety of languages.
 

AytrusTekis

Smack-Fu Master, in training
77
@techix

Makes perfect sense. And that is why I started here looking for advice :D



I figured the basics would be the same and different languages would simply compound onto learned skills, just was unsure where best to start. It would seem that the vote is almost unanimously "Python".

I really appreciate all of the helpful advice and quick response from everyone. I have a pretty clear starting goal now and think I should be able to progress it without too much trouble. I already picked up a lot of basics of Java while researching, so I will see how that impacts the change of gears toward Python. Might give me a boost, might have to think about things a little differently.
 
D

Deleted member 43669

Guest
techix's point's pretty good.

The languages mentioned are pretty close conceptually. Java, Python and Ruby are:

Procedural. Code is composed of statements which execute one after the other, you can create functions which can be called from different points in your code, etc. There are other language such as SQL, Prolog, etc. which are not very procedural

Object oriented. You can create data structures with associated code and features such as inheritance and polymorphism. There are loads of non-OO languages, such as C, Lisp- or languages with different OO models such as Javascript.

Variable-based. You can write statements such as a := a + 1, and probably you rely a lot on that to implement algorithms (i.e. loops). However, variable variables are not the center of the universe in all languages, e.g. Haskell and SML.

Languages which are not procedural or variable-based have their perks. SQL is extremely concise for expressing data queries and can be very optiming due to it not being procedural, Prolog allows you to solve complex problems in a very special way for the same reason. Lots of programming bugs are due to flaws in mutating variables and are pretty much non-existent in SML and Haskell code- which also can be optimized in ways that are not possible on languages with variable variables.

This probably will only manifest if you dabble in SQL and find yourself in a strange non-procedural land; it's not that probable that you find yourself in a situation where working in SML, Haskell or Prolog is worthwhile.

There is one notable feature that Ruby/Python have over Java- they favour higher-order programming. Higher order programming is a great technique to implement algorithms- it basically means using functions as parameters to other functions. Say you have a list of numbers and you want to filter this list to eliminate all odd numbers. A typical procedural approach would be:

Code:
filter_odd([1,2,3,4,5]);

function filter_odd(list):
  result = []
  for i in 0 .. list.length:
    if list[i] % 2 = 0:
      append_element_to_list(result, list[i]

Now, a higher-order based approach could work like this:

Code:
filter_list([1,2,3,4,5], { x -> x % 2 = 0})

Which calls the function filter_list with the array and a function that tells which elements should be kept.

Now realize that filter_list is a function you can reuse a lot, avoiding writing tiresome list-iteration code again and again (and therefore, if filter_list is implemented correctly, avoiding entirely bugs when rewriting its functionality). That is interesting in its own way, but looking further, if someone reimplements filter_list to leverage multiple cores, all code that uses filter_list would automatically be made faster.

Now, you can use this approach in Java, but the syntax required is *terrible*, so you end up never doing it. However, both Python and Ruby provide terse syntax to do it.

That would be my reason to learn Python/Ruby, because that will let you learn about this pretty cool technique.

Java, on the other hand, does not seem to offer anything of this caliber over Python/Ruby. It does have its benefits, but they are basically:

  • There's a very healthy Java opensource community which means there are lots of awesome libraries and frameworks
  • Java having static types means that IDEs can help you a lot more coding than in Python/Ruby
  • Eclipse is awesome for some things (but it's also dog slow)

... and I believe it's a more marketable skill than Python/Ruby, at least in my neck of the woods.
 

Richard Berg

Ars Legatus Legionis
43,037
Subscriptor
Lots of programming bugs are due to flaws in mutating variables
This, a thousand times this!

...

Perfect example why I became so enamored of Think Like a Computer Scientist over similar books, including Python the Hard Way: it warns against mutability within a few sentences of introducing "what is a variable?" Same for many, many other traps into which other intro books lead entire generations of unwitting programmers. Meanwhile, TLACS gives a far better top-to-bottom overview of the computing stack, while encouraging readers to internalize what computation actually means.

Every chapter includes a section on debugging. Every chapter includes a section on debugging. Every chapter includes a section on debugging.

In short it's simultaneously conceptual, exploratory, and hands-on at every turn. All this without leaving the beginner level, nor becoming bloated & wordy, nor treating the reader like a humorless retard. I've never seen anything like it.

IMO the choice of text is not close.

Higher order programming is a great technique to implement algorithms
Everyone knows that functionals are nice when solving problems that are naturally phrased as mathematical functions, or something close to it.

But lately, improvements to general-purpose languages have made them valuable in pretty much every problem domain. Got threads? Try continuations. Got huge data sources? Try lazy iterators. Got funky, ill-defined business requirements? Try any number of higher-level programming techniques that make the DRY principle easier to implement; you'll thank me when the specs change (again). More and more, I find that functional idioms and encapsulation (the one truly important piece of "OO") run hand in hand.

...

So: want something a more powerful / robust / marketable than Python? Fine. Make C# 4.0+ your 2nd language. Not hardcore enough for ya? Yeah...get back to me when you understand weak references, the WPF threading model, how to manipulate expression trees, when & why the compiler emits beforefieldinit... Prefer low level work? Learn CUDA. Like math/science/finance? Learn the ML family (O'Caml, F#) or maybe R if your problems are stochastic. Wanna job in the megaenterprise? Brush up on your COBOL. Have legacy code tied to the JVM? Jython will be natural once you finish TLACS -- but also see Scala, Groovy, etc.

In no case is it worth your time to wade through the stagnant Java language and the innumerable fluffy "patterns" its community has invented to compensate. Like someone else said:

What's marketable is knowing Hibernate/Servlets/Spring/Struts/etc., not the language itself
++++++
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
Richard Berg":22hnflby said:
All this without leaving the beginner level, nor becoming bloated & wordy, nor treating the reader like a humorless retard.
This is the part I disagree with. I think that ThinkPython has a tendency (and I'm not saying it's a game-breaker) to become boring and a little unapproachable. Not a lot, but a little. It's enough to put some people off, which is why it's my #2 recommendation these days instead of #1.

LPTHW, on the other hand, is very engaging (I don't think Zed can be otherwise) and I think gets far, far more right than it gets wrong.
 

levine

Ars Tribunus Militum
1,986
Richard Berg":27xkqvhk said:
Got funky, ill-defined business requirements? Try any number of higher-level programming techniques that make the DRY principle easier to implement; you'll thank me when the specs change (again).
A bit off topic, but can you expand on this? Really, all the information you care to dump would be appreciated :)
 

Richard Berg

Ars Legatus Legionis
43,037
Subscriptor
I think [LPTHW] gets far, far more right than it gets wrong
Yes. It avoids innumerable flaws that plague most beginner books. I just didn't see as many (or as broad) benefits.

This is the part I disagree with. I think that ThinkPython has a tendency (and I'm not saying it's a game-breaker) to become boring and a little unapproachable. Not a lot, but a little. It's enough to put some people off, which is why it's my #2 recommendation these days instead of #1.
FTR, I'm proceeding from the assumption that the reader *wants* to "think like a computer scientist." Not merely "learn python in 21 days" like most crappy intros assume. (either because they don't respect their audience, the author lacks a deep understanding, or simply sucks at clear concise explanations)

Does TLACS pull it off? I am impressed, obviously, but the proof is in the pudding: I surveyed these books & others so I could give one to my GF. She can barely operate her Mac, but is super smart, and expressed interest in learning about what I do. We shall see :)
 

Richard Berg

Ars Legatus Legionis
43,037
Subscriptor
levine":13e46je5 said:
Richard Berg":13e46je5 said:
Got funky, ill-defined business requirements? Try any number of higher-level programming techniques that make the DRY principle easier to implement; you'll thank me when the specs change (again).
A bit off topic, but can you expand on this? Really, all the information you care to dump would be appreciated :)
Let's say you want to refactor several places in your code that have similar (but not identical) business logic. Ideally you'd do it in such a way that one function (or perhaps one class) encapsulates a particular chunk of logic entirely, while remaining flexible enough to handle the special cases that real world customers & bugs have thrown at you -- a list that will no doubt grow in the future.

Common techniques include:
1) having the inputs & outputs be substitutable types. (fancy term: "parametric polymorphism")
*** in the statically typed OO world this means some form of inheritance. In Java/.Net in particular, interfaces >> superclasses
*** in dynamic languages, it usually means duck typing or prototyping
*** in languages without reified generics, you cry a lot
2) putting extreme care into the overall API design, such that:
*** every function is small, robust, well defined, and easy to unit test
*** the inputs & outputs of various functions are highly composable

#1 is where you find a lot of programmer holy wars, because the best known "patterns" all have drawbacks: annoyingly verbose boilerplate, compiler/platform limitations, or code that somehow becomes *less* maintainable after the so-called refactor.

#2 is similar to the classic Unix ethos. (whether or not *nixes actually achieve those ideals is another debate...). Everyone agrees with it in principle. Main problem is the sheer time & talent it would take to get a large, complex API into this state and keep it there through the codebase's evolution.

Functional programming^ does not change the fundamental picture. But it makes each technique more effective, and each compromise less painful.
** Taking anonymous fns as input & output offers similar flexibility to inheritance or duck typing, but with less overhead.
** Closures can encapsulate local state, kind of how object instances do, but without the temptation to make that state mutable. Screwing with locals inside a lambda looks, "feels", and often behaves wrong -- as it should -- while screwing with class member vars is practically encouraged.
** Coroutines (eg lazy iterators, continuations) make it easier to put logically independent code into small, independent functions without turning your control flow into spaghetti
** Applying a more math-y, function-based, set-aware style of problem solving will help just about any CS project approach the "clean API" ideal. (ok, this one is pure subjective opinion, sue me)
** The techniques themselves are composable too. You can write an inheritance hierarchy whose methods accept/produce functionals. Iterators can have loose/duck typing. Etc etc.

Hmm. I realize my elaboration became just as abstract as my initial statement -- perhaps moreso. Was the concrete intro enough to understand what I'm getting at, or did I fail miserably? I know I could not write Think Like a Computer Scientist nearly as well as its author did, despite agreeing 100% with his goals and methods.

^by which I refer to style more than language purity....though some languages make this style far easier!
 

levine

Ars Tribunus Militum
1,986
Richard Berg":1evhkxot said:
. . . I realize my elaboration became just as abstract as my initial statement -- perhaps moreso. Was the concrete intro enough to understand what I'm getting at, or did I fail miserably? I know I could not write Think Like a Computer Scientist nearly as well as its author did, despite agreeing 100% with his goals and methods.
No, I get it, insofar as you've enumerated a set of examples. I'm doing all of that, to the best of my ability... I guess I'm more interested in if there's some kind of authoritative/best-practice book, or essay, or literature in general on the subject. Something that treats highly mutable specs as a first-order condition to defend against in development.
 
D

Deleted member 43669

Guest
The thing is, if you can express the business requirements tersely and they are not scattered all over the place, the easier it will be to change them. If you repeat yourself, changing requirements will be more work, hence DRY. If things are scattered, it will be easier to forget to change something.

The other area I tend to insist is trying to be declarative. Your code should be 'what' as much as you can, and only 'how' when it absolutely needs to.
 

Zanshin

Ars Praefectus
4,460
Subscriptor
I also think you should consider how much effort you want to put into making your code "do stuff".

For me, I enjoy using Ruby, but if I had to pick a stack that was easiest to get up and running, I'd choose C# and .NET (assuming you're on windows). Ruby has a wonderful standard api, but getting a whole stack configured can be a giant pain in the ass, and it's not good to have config issues blunt your enthusiasm for learning to program.

Now, it's been nearly 10 years since I've done anything in the .NET world, so others will know exponentially more than me about it, but from what I recall: The basic flavors of Visual Studio and SQL Server are free. Visual Studio comes with a good WYSIWG editor for desktop applications.

Have a student create an address book that runs through a terminal session (the old roll and scroll), and they scratch their heads wondering when would they ever use something like this. Have the same student create an address book as a desktop app, and you can see lightbulbs going off as they imagine all the wondrous things they could code. The MS documentation is very deep, very technical, and very dry reading, but at least it IS there. Also, with doing desktop apps you're running windows, and it already has .NET on it, so your config work is 50% done before you've even started.

If you don't mind doing some config work, or are nifty with the IT skills, then by all means, welcome to Ruby and/or Python. But the MS world can be very, very nice.
 

Richard Berg

Ars Legatus Legionis
43,037
Subscriptor
The other area I tend to insist is trying to be declarative. Your code should be 'what' as much as you can, and only 'how' when it absolutely needs to.
Yes, a great point I forgot.

You may want to check out the (Python-based) Computer Science playlist at Khan Academy if the online books feel a bit dry.
Am I weird if I find those vids (the CS track anyway) more dry than either book recommendation?
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
Richard Berg":1ti14w5b said:
Am I weird if I find those vids (the CS track anyway) more dry than either book recommendation?
I don't think so. Videos about CS/programming seem to universally suck. One of the biggest roadblocks I had when learning to deal with Rails (just behind "it fucking sucks to use if you dare disagree with The Holy DHH") was their curious obsession with screencasts and video presentations.

Just because you can YouTube doesn't mean you should.
 

Alamout

Ars Legatus Legionis
27,285
koala":hyfvvnvy said:
If you want to land a job, .NET or Java.
With the caveat that in the current environment, you're unlikely to get a job without a degree and/or a kickass portfolio of programming work you've already done.

No one is going to hire a self-taught, non-credentialed programmer right now unless they're pretty fantastic. It's just too easy to find someone who has a CS degree or similar.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
Obviously this is not the standard--unless you're claiming that every currently-employed programmer is "fantastic".

It is clearly non standard. But is likely to be a goal (if not perfectly realized) in several of the places where fora dwellers live simply because many of the regulars here are clearly heavily into programming as a discipline, and work at places which reflect this.
 

Malyk

Ars Tribunus Angusticlavius
8,558
Subscriptor
Zanshin":18fgh67h said:
For me, I enjoy using Ruby, but if I had to pick a stack that was easiest to get up and running, I'd choose C# and .NET (assuming you're on windows). Ruby has a wonderful standard api, but getting a whole stack configured can be a giant pain in the ass, and it's not good to have config issues blunt your enthusiasm for learning to program.

Really? Ruby + RubyGems + Bundler + Rails + Heroku is stupid simple to get running!

Mike
 

JustinS

Ars Legatus Legionis
10,123
Richard Berg":28gaxfjb said:
Python++

Actually wait, let me revise that. Anything_but_Java++

Having skimmed a large portion of both, I definitely recommend How to Think Like a Computer Scientist over Learn Python the Hard Way.
I'm late to this thread but that is an excellent recommendation. It's the only truly introductory text I'm aware of that deals with recursion.

The text has some other great qualities, as Richard mentioned. The recursion thing is a pet peeve of mine. Downey proves with this textbook that the subject's difficulty is not great enough to justify its omission from an introductory text. I seriously don't know why it's always missing.
 

Zanshin

Ars Praefectus
4,460
Subscriptor
Malyk":2sd2cfxt said:
Zanshin":2sd2cfxt said:
For me, I enjoy using Ruby, but if I had to pick a stack that was easiest to get up and running, I'd choose C# and .NET (assuming you're on windows). Ruby has a wonderful standard api, but getting a whole stack configured can be a giant pain in the ass, and it's not good to have config issues blunt your enthusiasm for learning to program.

Really? Ruby + RubyGems + Bundler + Rails + Heroku is stupid simple to get running!

Mike

It's not easier than .NET and Visual Studio's WYSIWYG editor.
 
Status
Not open for further replies.