Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-28-2008, 11:16 AM
Member
 
Join Date: Jun 2008
Posts: 9
littleBean is on a distinguished road
simple question about private data
Hi everyone !
i'm very new to java and I found a this source ( the one below) in internet , but I ' ve a question.

class Test
{
private String surname;
private String name;
private String preferredcolor;
private int age;

public Test(String psurname,String pname,String ppreferredcolor,int page)
[....]
}

why did the compiler use "p" before every variable? is the "p" required, every time I declare a private variable? or he could have written simply (String surname, String name, and so on ?
thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-28-2008, 11:20 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,477
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Yes you can, there is no point to use a such a way. Normally in Java use camel case in naming conversions for variables. That is first letter is simple, and if you want to use more than one word after the first word, all first letter is capital in each word.

Code:
int weight; double distanceRuns;
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-28-2008, 11:52 AM
Member
 
Join Date: Jun 2008
Posts: 9
littleBean is on a distinguished road
ah, so "private String surname" and "public Test( String psurname) " are not connected with each other? they are 2 different variable, not only one that has been used first as private and then as public. Then we can even write

"private String surname" and "public Test( String tree)" and the meaning of the source will not change, isn't it?

another question : why the private variables are one for line, and instead the public ones are all grouped?is it a choice of the compiler or a stardard of java?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-28-2008, 12:03 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,477
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
For the firs question, surname and psurname are two different variables. There is no any connection at the time of your code.

private, public are called access modifiers in Java. Basically it define the accessibility of specific code segment.

Depend on the access modifier you can't group the variables, only you can grouping depends on the primitive types.

You have better to refer some documentations on those things before moving in deep of Java. Explaining on a forum is not easy at all.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-28-2008, 12:13 PM
Member
 
Join Date: Jun 2008
Posts: 9
littleBean is on a distinguished road
yes , I know I just needed some tips on what to search on google , now I will start looking for primitive type
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-28-2008, 12:37 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,477
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Oh dear, you are asking how to Google. You man...

Java primitive data types/variable, access modifiers, and so on......
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 06-28-2008, 07:47 PM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 337
fishtoprecords is on a distinguished road
Java is not C circa 1989. There is no reason to use Hungarian notation, per Microsoft's early Windows SDK.

There is plenty of reasons to avoid Hungarian.

I ususaly make the function parameters' names be related to their use, but not exactly the same as the private members.

Code:
private String fname; public void setFirstName(String aFname) { fname = aFname; }
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 06-28-2008, 08:20 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 563
Nicholas Jordan is on a distinguished road
Start simple.
Little Bean, you are very likely using a tool called an IDE - Integrated Development Environment. Those are very useful but for total beginner leaves you studying the IDE rather than Java. Those become a study of their own.

Have you read any books? Those can be checked out from the library.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 07-01-2008, 07:13 PM
Member
 
Join Date: Jun 2008
Posts: 9
littleBean is on a distinguished road
I' m using NETBeans 6
Quote:
Have you read any books?
do you mean about java? I'm reading one and I' m trying to understand here the things I' m not sure of . Another one question , i wrote this class:

class Piano{
static public double calc(double x1, double y1, double x2, double y2 ){
double z = (x1 -x2)*(x1-x2) + (y1-y2)*(y1-y2);
System.out.println(Math.sqrt(z));
return z;
}}

to calculate distance between two point of cartesian plane, but if I delete the "return z" string , NETBean say that I missed to insert the returned type.
But I 've already declared the type(double) of z , I know return is used to get the result of the operation and return it to the program, but I don' t understand why is necessary here since I' ve only asked to print a line , not to use the result for something else .
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 07-02-2008, 12:31 AM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 152
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
Did you read about "void" and "return" methods,and how they work?
So,when you wanna only print the square root of z so use "public void nameOfMethod(@params)" to declare the method,but if you want just to make the method which will return some type of variable and then somewhere you will use it so declare as "public..." +what type of variable or object you want to return+"nameOfMethod(@params)"

Last edited by serjant : 07-02-2008 at 12:37 AM.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 07-02-2008, 03:48 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 199
Eku is on a distinguished road
hello little bean, may i suggest that you first try your codes using a text editor and compile it manually before you use a IDE. Refer to some books, most of them will teach you to compile and code java programs using the commandline and a text editor. ^_^ Start from the Basics
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 07-02-2008, 04:39 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 337
fishtoprecords is on a distinguished road
OK so @eku and I disagree, reasonable folks can disagree.

I like an IDE for rookies learning because it hides a lot of complexity. You type in your code, push the run button and it tries to run. Push the debug button, and step into your code to see why you have bugs.

I can see how using vi or emacs and a command line compiler can bring some special knowledge. I just think that things like classpath etc just seem opaque to folks at first
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 07-02-2008, 05:09 PM
Member
 
Join Date: Jun 2008
Posts: 9
littleBean is on a distinguished road
Thanks Serjant, very usefull
I ' m reading a book , otherwise I could not write this simple class from nothing, but books don' t speak and if I don' t understand something, I can't ask to him and not always google help like a forum can do . It ' s just this. For the moment I feel more sure programming with an IDE rather than using a notepad, for the simple reason that , for now program correct my syntax so that I can learn it well and reusing it in a notepad.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Method Question Froz3n777 New To Java 2 02-13-2008 03:39 AM
Probably a really simple question... ibanez270dx New To Java 0 11-16-2007 02:27 AM
Simple question of JTable carl AWT / Swing 1 08-07-2007 08:07 AM
Question of private member Felissa Advanced Java 2 06-28-2007 10:08 PM
oracle query with date question orchid Database 1 05-09-2007 01:10 AM


All times are GMT +3. The time now is 05:59 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org