This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes can some one let me know if this code makes sense? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can some one let me know if this code makes sense?" Watch "can some one let me know if this code makes sense?" New topic
Author

can some one let me know if this code makes sense?

Alain Fallada
Greenhorn

Joined: Nov 11, 2012
Posts: 18
The program works but this is a section i want to have checked. i have dificulties with private, static, public instance variables.

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

Welcome to the Ranch.

In future, while posting code, please UseCodeTags I have added them this time for you. As you can see the tags make the code much more easier to read and understand.
Also, you seem to have missed out on the braces (hopefully while posting) Please edit your post and correct them.

Posting a bunch of code and saying "
i have dificulties with private, static, public instance variables.
" does not really help us help you. Do you have any specific questions?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Welcome to the Ranch.

What difficulties exactly do you have with private, public and static member variables?

Here are some links to the relevant parts of Oracle's Java tutorials:

Controlling Access to Members of a Class
Understanding Instance and Class Members


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37941
    
  22
I have a little rule of thumb about static members.

If you have a good explanation why you want it static, then is should be static.
If you haven’t got a good explanation, then making it static is a mistake.
Alain Fallada
Greenhorn

Joined: Nov 11, 2012
Posts: 18
Hello, thank you all for your help.
i just don't understand how to use methods, and classes.
and when to use static and private.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37941
    
  22
At this stage:
  • 1: Use static for the main method and nothing else.
  • 2: Use private for all fields and public for all constructors and methods.
  • This will change when you are more experienced.

    For classes and methods, try the Java tutorials. Note they don’t always make their fields private as you really should.
    Jayesh A Lalwani
    Bartender

    Joined: Jan 17, 2008
    Posts: 2271
        
      28

    Aside from the static members and making your members private, your code is structured well. It's hard to see what exactly you need to understand, because, as far as I see, this code looks like someone who had a good understanding of modularizing their code.
    Suryanarayana murthy
    Greenhorn

    Joined: Mar 25, 2010
    Posts: 3
    Please learn about static modifier where to use and where not to use

    Regards
    Surya
    fred rosenberger
    lowercase baba
    Bartender

    Joined: Oct 02, 2003
    Posts: 11153
        
      16

    I spent about 2 seconds looking at your code, and would say that it definitely does NOT make sense.

    Why?

    Because there are ZERO comments. Comments may seem like a waste of time at this stage, but trust me, they are vital in every single piece of code you write. Even if it is nothing more than a general statement of what the class/method is for, it needs to be there.

    Next, a variable name like "junk" is not very well named. if it holds junk, then why bother saving it at all? a more descriptive name like "userInput" is MUCH better and tells me immediately what it is for, rather than making me hunt through the code.

    I personally would put in some validation code. If you ask the user to input a value between 1 and 25, you should validate that they did. There are a lot of evil users who will read that direction, and say "I wonder what happens if I put in 87?".


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

    Joined: Nov 11, 2012
    Posts: 18
    Well Thank you all for your help. i will try to look in youtube to find out how to define and call classes. that is what i have more difficulties.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 37941
        
      22
    Suryanarayana murthy welcome to the Ranch
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 37941
        
      22
    Alain Fallada wrote: . . . i will try to look in youtube to find out . . .
    Careful. some of the things you find might be not at all helpful.
    Himanshu bisht bebo
    Greenhorn

    Joined: Jun 12, 2012
    Posts: 16
    Welcome to ranch , where is goodPattern method and read good coding convention for coding . These is not a good code
     
     
    subject: can some one let me know if this code makes sense?
     
    Similar Threads
    Using method on a program
    Add an exception for divide by zero to my fraction class
    Method Creation and debugging.
    Scanner debugging help
    reading input from a file into a array