aspose file tools*
The moose likes Beginning Java and the fly likes java newbie: confused Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java newbie: confused" Watch "java newbie: confused" New topic
Author

java newbie: confused

karthik ka
Greenhorn

Joined: Sep 17, 2012
Posts: 4

did any one here did CS101 from udacity ?
i am more of udacity-kind-of guy, rather than reading about concepts, i learn better by doing them.So i am confused about learning java .

so far, as newbie, am i good enough?
if i took OCJP, whether i could be employed as java programmer ?
is ther learning java , has any value rather python or ruby?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
Welcome to the Ranch

No, I didn’t sit Udacity.. Please go back to that code, and edit it by indenting it correctly; it is very difficult to read.
If you show a potential employer code so badly indented, he will throw your application in the bin and never even see things like labelled continue and == on reference types.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

did any one here did CS101 from udacity ?

No, but from what I've seen now (just a quick look) I am not impressed.

i am more of udacity-kind-of guy, rather than reading about concepts, i learn better by doing them.

Not such a promising statement.

if i took OCJP, whether i could be employed as java programmer ?

You'll work as a developer only if you are competent enough and you can actually prove that. The code above shouts that you really need to work a lot and hard (like we all did when we first started) before you start thinking about OCJP and getting a job.


The quieter you are, the more you are able to hear.
karthik ka
Greenhorn

Joined: Sep 17, 2012
Posts: 4

Campbell Ritchie wrote:Welcome to the Ranch
Please go back to that code, and edit it by indenting it correctly; it is very difficult to read.
.

how to do that?
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

Indentation
No need to send private message, we all answer as soon as we can.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

karthik ka wrote:
Campbell Ritchie wrote:Welcome to the Ranch
Please go back to that code, and edit it by indenting it correctly; it is very difficult to read.
.

how to do that?

If the message isn't too old, there should be an 'edit' button on that post itself. Otherwise, edit it on your local machine, and paste in into a new post.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
karthik ka
Greenhorn

Joined: Sep 17, 2012
Posts: 4

SO Except for "continue" and "classnames" , is it indented?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

karthik ka wrote:SO Except for "continue" and "classnames" , is it indented?


Basically, no. Here is an excerpt from your code.



Here is the same code with some indentation.



Notice how much more readable it is?


This may seems like a bunch of grammer police being anal annoying at the moment, but think of it like this. First, if people can't easily read your code, they will come off as badly judging your code. And in the case of a job interview, you don't want that. Second, if people can't easily read your code, it can be argued that you can't easily read your own code. And it may be concluded (correctly or not) that this is a case of "throw away code" and you don't care about it. Your need to come off as a developer who is proud of what is produced (especially during the interview).

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
karthik ka
Greenhorn

Joined: Sep 17, 2012
Posts: 4

thanks for your patience
indented code:


review my code and any suggestions ? or improv?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

So, your question is, "Based on this sample of my code, could I get a job as a Java Programmer?"

That's a pretty fuzzy question, as one simple code sample is not enough information on which to make a hiring decision, unless it's so horrible that I can decide that there's no way I'd hire that person.

And aside from that, even to assess the quality of that code sample itself, there's more context we'd need. For instance, what question were you answering or what problem were you solving when you wrote it? What kind of time constraint did you have? What resources did you have available to you? What other constraints or freedoms where there? (For example, was it required to compile and run, or was it just meant to show a general concept?)

Aside from that, simply looking at the code in a vacuum, I have the following comments/questions:

1. Why is Sub declared package-private?

2. "Sub" seems like a poor class name here. It doesn't explicitly extend anything, and it doesn't appear to be specifically about Submarines, Substituion, Subtraction, Sublimation, or Subaru.

3. Why is ano public?

4. What does "ano" mean? What's the variable for? I should be able to at least guess at an identifier's meaning/purpose from its name.

5. There's never a need to import anything from java.lang.

6. It's generally better to import individual classes, rather than *, although in some shops there may be a standard to use * if you import more than N individual classes from that package.

7. Why are bal, in, name, and type not private?

8. Don't declare multiple variables on the same line (name, type).

9. The Sub() constructor is pointless. It only sets variables to the default values that they're already given before the constructor is even invoked. Get rid of it completely or give it an empty body.

10. It would probably be better to make name and type final, although without knowing more details about the larger context, I can't say for sure.

11. Rather than have getData() that queries the user, the user input should be handled in a separate class. That class should then either call new Sub(name, type) or create a blank Sub and call setters for name and type. (I prefer the former in general, but the latter is also valid, particular in an Dependency Injection context, such as Spring.)

12. Why is getData() package-private?

13. If the user doesn't provide a valid int input, the nextInt() call will throw an exception, which you're not handling. The program will just crash.

14. "j" is a poor variable name for the result of nextInt().

15. If the user provides an int other than 1 or 2 for the type, you print out an error message, but you don't do anything about it. You just end up with a Sub that has an invalid type.

There's more, such as the labeled loop, bad variable name "t", hardcoded "\n" for newline, not using equalsIgnoreCase(), "bank" class name starting with a lower case letter and being package private...

This sample code would not give me a good impression of a job candidate. That's not to say that someone who writes code like this couldn't get a job, and learn as he goes, but it would have to be for a very junior position and there would have to be quite a bit of mentoring or at least oversight and review.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

Using labels in loops and for break and continue statements isn't usual in Java code. I would avoid using them, because it makes the flow of the code hard to follow.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java newbie: confused
 
Similar Threads
Suppressing proceeding statements after if statement fails
Please help me with this scanner object problem
Bank program class or switch problem
Need help with username and password validation
Having troubles with a complex program, need help with an illegal start of type error.