Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java programming like pro?

 
sahar eb
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This might sound a little silly but I am going to start my first job as a JAVA developer and I need to be confident about this! So please bear with me! I start programming by C++ and then moved to JAVA. I developed an academic project for 3 years. Now I am going to be a java developer and dealing with industrial project. I am a little worried about my programming skills. I was able to code almost every thing that I have needed, but I think I have some mistakes in the way I code, Although I am not sure. I have listed them below. can you tell me as a professional weather they are bad habits or its fine to do these things in programming:

1) If the program gets complicated I will end up with a class including 1000 lines. Is that a mistake? Is it professional?
2) I do understand the meaning of OO and Interfaces and synchronization but I never happened to use them a lot? for OO some cases I used, for Interfaces Never used (in 3 years).
3)many times I look at other developers code and there are lots of classes and methods which each include just a couple of lines!. That is the Professional way to do it? or its just another method of coding?
4) Are there any kind of method to evaluate the quality of a code?
5) Are there any sources that can teach me how to program like a Pro?
6)Installing some tools like "CodePro Analytix" will help me or just make me depend on the tool itself?
7) Of course there are differences in programming an academic project and an industrial project. Is there any list of questions or Errors that may be helpful in my case?

Sorry, too long and too many questions.
Thank you sooooooo much for your help, in advance ! ;)
 
D. Ogranos
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know so much about professional, but there are a few guidelines to follow to produce "good" code:
- don't go for "clever" code, instead go for easily readable, understandable code (-> maintainable!)
- refactor often: if a method/class grows in length, see if you can extract parts as methods, or if you can split classes
- follow the "one method/class, one purpose": a method/class should do one thing, not try to do everything

Google for "clean code" as one starting point for more ideas.

Also google for PMD and Checkstyle, these are tools for static code analysis. They can help you to evaluate and improve your code.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very short methods are usually a good thing.
A class which contains only a few lines might be a subckass where it is only necessary to provide a constructor. This is an acceptable class in its own right:-
 
Winston Gutkowski
Bartender
Pie
Posts: 10417
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sahar eb wrote:1) If the program gets complicated I will end up with a class including 1000 lines. Is that a mistake? Is it professional?

Very possibly. A class should be as big as it needs to be. java.lang.String, for example, contains over 3,000 lines of code; and I'll bet it's the first class you ever learned about. At the same time, when developing you should always be asking yourself "do I need this?".

4) Are there any kind of method to evaluate the quality of a code?

Sure. Run your code by other programmers - or indeed, post it on a forum like this. We love trashing other people's work.

5) Are there any sources that can teach me how to program like a Pro?

Tons; but personally, I'd start with the Java tutorials. Once you're past the basics, I'd also advise getting this book. You may also find this article useful.

6)Installing some tools like "CodePro Analytix" will help me or just make me depend on the tool itself?

I suspect that the tool checks code correctness rather than quality. Any fool can write a program that works; only someone else can tell you how good it is (see above).

7) Of course there are differences in programming an academic project and an industrial project.

Actually, if you were taught well, there shouldn't be that big a difference.

HIH

Winston
 
K. Tsang
Bartender
Posts: 3444
13
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each company may have its own coding convention/style. The project may need to follow the client's coding style.

Yet long story short, aim for maintainable, easy to understand (think like junior programmer), document code (write comments) as you go along,
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think a major difference between “academic” code and “industrial” code is that “academic” people trust their users and use far less of a defensive style. The “industrial” people assume every user is about to write rubbish in the input and include code to take care of that.

Of course “academic” people should teach prospective “industrial” people to write defensive code!
 
J. Kevin Robbins
Bartender
Posts: 1759
19
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sahar eb wrote:Hi,
This might sound a little silly but I am going to start my first job as a JAVA developer and I need to be confident about this!


This is normal. For the first few months in my first professional developer job, I wondered what the hell I had gotten myself into. I felt completely overwhelmed. If at all possible, find someone at the new job who will mentor you and help you get familiar with the environment and tools.

sahar eb wrote:
1) If the program gets complicated I will end up with a class including 1000 lines. Is that a mistake?


Opinions differ on this, but I would say probably. Anytime my classes run more than 200 lines or so, I step back and take a good, hard look at it to see if I can break it down into smaller classes. Sometimes I can, sometimes I can't, but it pays to consider it because large complicated classes are harder to maintain and unit test.

sahar eb wrote:
2) I do understand the meaning of OO and Interfaces and synchronization but I never happened to use them a lot? for OO some cases I used, for Interfaces Never used (in 3 years).

I would say this is a weakness that you need to address. Coding to interfaces is an important concept that you should learn to use.

sahar eb wrote:
3)many times I look at other developers code and there are lots of classes and methods which each include just a couple of lines!. That is the Professional way to do it? or its just another method of coding?

This gets back to my answer about unit testing and maintainability.

sahar eb wrote:
4) Are there any kind of method to evaluate the quality of a code?
5) Are there any sources that can teach me how to program like a Pro?

I haven't tried it yet, but I've heard good things about the Cattle Drive here on Javaranch.

I would also second the suggestion on the book Effective Java. It probably did more to improve my skills than any other single book I've read. And it's one that you can go back and read again once a year and learn something new every time.

Lots of luck in your new job!

 
sahar eb
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,
thank you sooo much for all these replies and wishes. most of the comments were really helpful!
may be that is the problem. i never had an "academic" teacher and no one have ever looked at my code. I learned java and developed a fairly big project only by the help of java tutorial and this lovely forum. thanks to you guys!
I am still confused on when i should use Interfaces and stuff like this. i will read the sources and google on those suggestions and will come back to you!
thanks again!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic