• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question for Beginners  RSS feed

 
Barry Burd
Author
Ranch Hand
Posts: 133
10
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kinds of examples do you like to see online and in books? Rich examples that illustrate alternatives and best practices for using Java features, or bare-bones examples that illustrate a feature's usage in isolation? (I have a bias in this regard, but I don't want to reveal it until I hear from others.)
 
Frank Palmeri
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best examples are when you start with a basic example and then add onto it. This way you get the basics covered and then advance step by step. Something like a simple console based menu program. Then you would add more choices, more features, and then eventually build a GUI based version. This way you get to start simple and build up layer by layer. These to me are the best examples. It's always best to start with the simple concepts and then, little by little, add in more features and concepts.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch FP

Barebones examples are nice because you can see how the language works without lots of extraneous stuff.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it depends on what you are hoping to gain from the example. For beginners learning Java the approach outlined by Frank is good, for more experienced programmers wanting to learn a new concept, how to use a particular library etc I think the bare bones approach works best although sometimes it's also nice to have a complete demonstration application so you can run it and see the code in action.
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like it if the content has the required bits of both and it does not miss out on subtle details. I also prefer those books in which the authors add details to a working example with every chapter. I like it even more if they mention what are the good practices and in what context and why they should be followed and what should be avoided.

A certain book I had started reading a few months back had the first six chapters cover just the barebones examples covering details of what each of the methods provided by the API did. What exception they would throw and when. That part was required, I agree, cause it taught me how to use that API. But if those chapters had also covered the parts that I found out while actually experimenting with those methods, I mean if those chapters covered at least some of the important bits, I would have loved that book. But I think ( and I may be wrong cause I didn't read that book after that sixth chapter ), that part was missing.

Those chapters were just like ..
<SomeClass> - ok fine, these are the methods. This is what they do. This code shows how.
Next chapter -<AnotherClass> - ok fine .. here you go. These are your methods. Here is the code that shows how to create an object and then invoke those methods.

I would have loved that book, if it contained a real world application that the authors would add something to with every chapter. This way the reader sort of graduates as you unfold the advance concepts. It's nice to allow the readers to have those questions in the first few pages. This gives them a chance to find their own answers and to think. And it's wonderful if you explain that concept later.

That sort of gives the reader a feeling that the reader and the author are on the same page.






 
Barry Burd
Author
Ranch Hand
Posts: 133
10
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I posted the question, I expected everyone to answer that they wanted all real-world examples, so I'm surprised to read that some people want to start with bare bones examples. For my work, I prefer bare bones examples. When I'm struggling with a concept, it's usually because I don't understand a certain technical point, like how a certain sequence of API methods are supposed to be used. So when I search for a solution, I'm usually looking for the simplest use of that API feature that I can find. I become frustrated when the only examples I can find on the Web are "best practices / test lots of features" examples. With these richer examples, it usually takes me a lot more time to wade through the code to understand the essence of the method calls. I also find "full featured" examples that aren't very helpful because they have dependencies and other requirements that I can't easily set up. (Instead of quickly running some example code, I spend my time trying to recreate the environment in which the example can run.)

Your thoughts? (I'd really like to hear from people about this.)
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barry Burd wrote:Your thoughts? (I'd really like to hear from people about this.)

Well, I think I go with the general trend in that I like to see simple examples, but also agree with Frank that the best of those are ones that can be embellished as you go on.

However - and possibly contradictory - I do prefer examples that use real-world types. The classic:
Animal → Canine → Dog
one for inheritance is a bit lacking IMO because you're never likely to write an "animal" based hierarchy; whereas something like:
Person → Employee → Manager
illustrates the point just as well, but is likely to be something that a programmer might actually run into.

Conversely (and maybe I'm arguing against myself here; it wouldn't be the first time ) the old chestnut of
Shape → [Circle, Triangle, Square]
with a draw() method to illustrate polymorphism is extremely effective, especially when you actually implement the subclasses.

Winston
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shape → [Circle, Triangle, Square] can also be used to demonstrate breaching LSP (=Liskov Substitution Principle).
BTW: the first example I ever read of that particular problem was signed Barry Burd. I couldn't find it again; do you have a link for it please?
 
Barry Burd
Author
Ranch Hand
Posts: 133
10
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell, ... Sorry, I don't know where you'd find that link. I'll think about it, though.
 
Phillip Larson
Ranch Hand
Posts: 31
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I enjoy working with bare-bones examples at first, then working up to Rich examples.
 
Scott Halepaska
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I would like to see would be an example or exercise that continues through all the chapters of a book. For example, the small class we build in chapter one would be added to in chapter two when we learn about methods and added to again in chapter 3 when we learn about I/O. I have never found a book designed in this way.
 
Sresh Rangi
Ranch Hand
Posts: 54
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like simple, self-contained examples if possible. I find some examples difficult to follow when they're full of debug conditionals, logging, command-line processing, or long comments. They can obscure the main control flow in the example. In a production program you might need to add some of that back again, but never exactly as in the example.

Compare:
SimpleAudioPlayer1
SimpleAudioPlayer2
 
Heena Agarwal
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scott Halepaska wrote:What I would like to see would be an example or exercise that continues through all the chapters of a book. For example, the small class we build in chapter one would be added to in chapter two when we learn about methods and added to again in chapter 3 when we learn about I/O. I have never found a book designed in this way.


Bet you haven't checked this book yet. It's a beautiful book. It has an example that the authors add various things to with every chapter.

And this one too. This book has an example that the authors constantly improve as they explain a new concept.

I think there are many authors who have written that kind of books. We just have to look well.

By the way, this Lambda Expressions tutorial example - http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html#use-case - Isn't that a very nicely written example now.


Edit : Corrected the lambda expression example link.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barry Burd wrote:Campbell, ... Sorry, I don't know where you'd find that link. I'll think about it, though.
Thank you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!