This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

variable not found

 
Mohammad Ahmad
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi to all...iam very new in using Jbuilder i have a small question that if i have built two classes and i have defined a string in the first class that contains a user input file..then in the second class i need to calculate the length of that string(the user input file) so i said
Line.lenght() but i had thr error:
Error #: 300 : variable Line not found in class project_two.Calculate_Padding_bits at line 19, column 10
what i shall do ..by the way the two classes is on the same Package and even that i tried to make import for the first class in the second one...plz help me on this problem....
Mohammad
 
Jeremy Tartaglia
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is that you're not taking into account that you have two classes. The variable is only defined in your first class, not the second. Like this:



In Class2, x is not defined. So the compiler will question why you're using it. If you need to access an attribute in another class, there are two accepted ways: direct access, and accessor methods. Direct access seems to be frowned on, but for low security data, often modified data, or simple projects, I don't see it as a problem. This method is to make the attribute protected (accessible by subclasses), package, or public, and just access them through an object:



With Object Oriented programming, a new idea was created: accessor methods. The idea behind this is to limit all attributes to private, and write functions to view or modify the data:



This has become the most accepted way to deal with attributes, as you can limit a variable to read only, write-only, or read-write depending on the object itself. It also allows you to perform the modification at an appropriate time, to avoid crashes.
 
ak pillai
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go with the second approach i.e using acessors and mutators. the direct access of variables break encapsulation.
 
Mohammad Ahmad
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx a lot for this useful reply...i want to ask another small question that :
if i have defined in my code :
static int length;
then i need to convert and represent this integer into 64-bit big indean what shall i do in java ...can i find any function to do this??
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mohammad Ahmad:
thanx a lot for this useful reply...i want to ask another small question that :
if i have defined in my code :
static int length;
then i need to convert and represent this integer into 64-bit big indean what shall i do in java ...can i find any function to do this??


MULTIPOST
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic