• Post Reply Bookmark Topic Watch Topic
  • New Topic

What's the most important aspect/area of Java for a beginner  RSS feed

 
michael Hannigan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a beginner who is learning Java, are there any key areas that are especially important when it comes to Java?

Is it the concept of objects? since everything we do in Java basically involves objects interacting with each other, and the instance variables, methods within those objects being called and used by one another. Though the concept of objects is not very hard, but sometimes when i'm doing these beginner exercises from the book, eventhough it's extremely simple, you still have to be careful to make sure to keep track of each object's instance variables and methods and how to call upon them.

i'm almost done with headfirst java's section on objects (maybe there's more later on in the book, but at least the major concept and usage of objects), and just to be sure, i'm going to read Thinking in Java and Dietel's Java's section on objects as well... just to make sure I am crystal clear on it. =)

For a larger, more complicated program, I can definitely see people getting overwhelmed by all the objects and variables and end up getting confused. Does anyone have a tip for this?

In addition, are there any other aspect of Java that you think is extremely cruicial for a beginner ? something that one MUST absolutely have a very good understanding of while studying java?

And, lastly, my goal for learning Java is so that I can eventually start learning android programming... are there anything I should pay especial attention to now while i'm studying Java?
 
Claude Moore
Ranch Hand
Posts: 923
9
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I learned java at university. Both C++ and Java were the "target" languages for Software Engineering class, and I confess that my learning path of C++ and Java was heavily influenced by seeing those languages
as different implementations of OOP principles in real languages, so my opinion on this topic may be biased by this approach. This said, I like very much to compare learning an artificial language to learning a natural
language (like English, Russian or whatever else). Generally you need strong knowledge of grammar, syntax, and idioms. Counterparts in Java may be knowledge of OOP (the real semantic) at first place, followed
by strong knowledge of language syntax and knowledge patterns / best way of coding (idioms), that you can learn by studying not only books but even code written by other people.

No matter what language you're studying, you should always try and learn not only how things are made, but expecially why thing are done in a particular way. You should be comfortable with Java syntax
and with most common pitfalls. I'm not able to suggest you a particular area on which focus your learning efforts, besides of java syntax and semantic: I believe that, on a strong basis, learning Java related technologies
is only matter of time and experience.
 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a few basic principles, not hard and fast rules:

Do one thing well. For methods and objects, a beginner's error is to have a method or an object do everything. A method/object should be well defined and do one thing. If it is doing more, split it out into other objects.

Division of labor. This is related to the first. If your method/object is getting input, validating, applying logic, etc., think about having separate methods/objects do each of these.

Keep scope as short as possible. Define variables just before you use them. Avoid class ("global") variables. Favor passing values to methods rather using class variables.

Format consistently. Format so that syntax is clear. Being consistent is better than being "right".

Comments: Goldilocks. Do comment. Tell why you're doing something. Comment the input and output of methods. But don't repeat what is obvious from the code. x = x + 1 // Add one to x <-- No!

Write for reuse. If there is a reusable way to write a piece of code, do it that way.

Write maintainable code. Think about someone else looking at your code. Is it clear? Would it be easy to change?
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the most important thing to learn is what objects are and what they do.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
michael Hannigan wrote:For a larger, more complicated program, I can definitely see people getting overwhelmed by all the objects and variables and end up getting confused. Does anyone have a tip for this?

Yes: Read Knute's post and Write Dumb Code.

And just a few practical tips:
1. Write out all the steps required to solve your problem IN ENGLISH (or your native language) first - before you write a single line of code.

2. When you're thinking about problems that involve more than one object, or type, concentrate on WhatNotHow.

3. main() methods should be very short; so if yours is more than 10 lines long, it's probably wrong.

4. Almost no method should be more than you can fit on a screen. My rule of thumb is 20 lines; so if I find myself writing one longer than that, my first thought is always: Can I break this up? Maybe you can't; but it should always be at the back of your mind.

5. When writing an application, separate what it does (ie, the problem it solves), from what it looks like (ie, the display/GUI) as completely as possible. In general, problem classes should never contain anything beginning with 'J' (JFrame, JTable, JMenu etc).

6. The above point also applies to classes: separate what they do from what they look like. A Java Date, for example, is NOT:
23/12/2013 11:48:30 GMT
it's:
2847874890720L   (or probably not )
That is to say: it's contents are a single long integer; the date and time in written form are what that integer represents (or "looks like" to us puny humans).

7. Document, document, document. It's basically part of Knute's "Write maintainable code" point. My advice: learn the basics of javadoc, and use it...ALWAYS.

I'd just add that there is one possible exception to rule 4 above: GUI code, which often requires a fabulous amount of boilerplate. However, that brings us to the last (and probably most important) tip:

8. If you find yourself writing the same thing more than once: put it in a method (or possibly even a class).

HIH

Winston
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are new features in Java8 which are a bit awkward to learn for the first time, but reduce the amount of boilerplate code considerably, so use them if you can. If you are not familiar with the term boilerplate code, look here.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say it is important to learn to compile and test a lot.

Don't write a method that is 20 lines long and then compile. I write 2-3 lines at most before i compile and test. The more often you re-compile and test, the faster you will complete your code. You'll find bugs sooner, and they'll be easier to fix.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!