The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > General Programming > Java


Welcome to the The ProgrammersTalk Community 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), respond to polls, upload content and access many other special features. 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 contact us.
Reply
 
LinkBack Thread Tools    Display Modes   
  #21 (permalink)  
Old 07-31-2007, 02:49 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Quote:
Originally Posted by nogono View Post
difference between DefaultListModel and LinkedList in Javai got the basics ...i want answer of above question.....
LOL, you got the basic but still don't understand the difference between private, protected, and public

Anyways, I personally haven't used DefaultListModel
but by just looking at the API's description and the methods that it has. It seems that DefaultListModel is more likely a Singly Linked List while LinkedList is the Doubly Linked List

Singly Linked List - Allow you to add from the head of the node
Doubly Linked List - Allow you to add from the head and tail of the nodes

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #22 (permalink)  
Old 08-01-2007, 07:48 AM
Bench Bench is offline
Full Programmer
Join Date: Jul 2007
Location: UK
Posts: 113
iTrader: (0)
Bench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished road
Quote:
Originally Posted by HelloWorld View Post
protected - anybody from the same package can accesss
Just a minor nitpick. 'protected' in general OO design means that a class member is visible/accessable to derived classes (sub-classes).

I believe package-wide visibility is the 'default' specifier in Java which is given when the private/protected/public keyword is omitted from the name of the class member entirely. Since packages are a Java-specific thing, there's no general OO term to describe it

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
The Following User Says Thank You to Bench For This Useful Post:
HelloWorld (08-01-2007)
  #23 (permalink)  
Old 08-07-2007, 12:06 PM
nogono nogono is offline
Novice
Join Date: Jul 2007
Posts: 35
iTrader: (0)
nogono is on a distinguished road
Icon12 Look

public class dust
{

int latin=200;


public static void main(String[] args)
{
int sand=0;

if(args.length==1)
{
sand=Interger.parseInt(args[0]);
}
else
{
//when i am trying to access my latin variable over here i am getting n error
//why is it so

sand=latin;
}
}
}

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by nogono : 08-07-2007 at 12:13 PM.
Reply With Quote
  #24 (permalink)  
Old 08-07-2007, 12:45 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Code:
public class dust
{

int latin=200;


public static void main(String[] args)
{
int sand=0;

if(args.length==1) 
{
sand=Interger.parseInt(args[0]);
}
else
{
//when i am trying to access my latin variable over here i am getting n error
//why is it so

sand=latin;
}
}
}
First of all, it's always a good thing to also post the error message that you're getting. But by just looking at your code, it seems like you haven't declared your latin variable as static. Change your code to be like this:

Code:
public class dust
{

private static int latin=200; // I edit this one


public static void main(String[] args)
{
int sand=0;

if(args.length==1) 
{
sand=Interger.parseInt(args[0]);
}
else
{
//when i am trying to access my latin variable over here i am getting n error
//why is it so

sand=latin;
}
}
}

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #25 (permalink)  
Old 08-08-2007, 11:03 AM
nogono nogono is offline
Novice
Join Date: Jul 2007
Posts: 35
iTrader: (0)
nogono is on a distinguished road
Icon4

public class dust
{

private static int latin=200; // I edit this one


public static void main(String[] args)
{
int sand=0;

if(args.length==1)
{
sand=Interger.parseInt(args[0]);
}
else
{
//when i am trying to access my latin variable over here i am getting n error
//why is it so

sand=latin;
}
}
}



But i didn't get why int latin=200 should be static......

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #26 (permalink)  
Old 08-08-2007, 01:24 PM
rpgfan3233 rpgfan3233 is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jul 2007
Posts: 118
iTrader: (0)
rpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura about
Code:
public class Dust {
    private static int latin_static=200;
    private int latin_instance=100;
    
    public static void main(String[] args) {
        Dust dust1 = new Dust();
        Dust dust2 = new Dust();
        dust2.latin_instance++;    //dust2.latin_instance = dust2.latin_instance + 1
        dust2.latin_static++;    //dust2.latin_static = dust2.latin_static + 1
        System.out.println("\t\tdust1\tdust2");
        System.out.println("static\t\t" + dust1.latin_static + "\t" + dust2.latin_static);
        System.out.println("instance:\t" + dust1.latin_instance + "\t" + dust2.latin_instance);
    }
}
What I did was create two instances of the Dust class, dust1 and dust2. I then changed both the latin_instance and latin_static variables of the dust2 instance. Then I outputted the values of latin_instance and latin_static for both dust1 and dust2. The result is that dust1.latin_static and dust2.latin_static are the same value while dust1.latin_instance was its default value (100) and dust2.latin_instance was 101 because it was changed. This illustrates that static members are owned by the class itself, which means that instead of dust1.latin_static, you could use the recommended Dust.latin_static. non-static members are known as "instance" members, which means that for each instance of a class, a new instance of its members are created specifically for that instance, or the instance members are owned by the instance of the class, not the class itself.

You need to make your latin variable static because main is a static method. The alternative is to create an instance of the Dust class and then use it: sand=new Dust().latin;.

Why can't you use instance variables within a static method? Well for one thing, which instance of the class would the instance variable be taken from? There are no instances of the Dust class in your original code!

If you are up for some reading, you can check out Understanding Instance and Class Members (The Java™ Tutorials > Learning the Java Language > Classes and Objects) for more information.

__________________
"C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off."
-- Bjarne Stroustrup, creator of what is now known as C++
For more quotes by Bjarne Stroustrup, check out http://www.research.att.com/~bs/bs_faq.html#really-say-that.
Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
The Following User Says Thank You to rpgfan3233 For This Useful Post:
HelloWorld (08-09-2007)
  #27 (permalink)  
Old 08-14-2007, 08:26 PM
nogono nogono is offline
Novice
Join Date: Jul 2007
Posts: 35
iTrader: (0)
nogono is on a distinguished road
Icon4 Java

An access modifier used in a method, field or inner class declaration. It signifies that the member can only be accessed by elements residing in its class, subclasses, or classes in the same package. //this is the definition of protected

consider two classes in same package
in first class i declare variable as protected

//warning both classes are independent...there is no subclass
if i now make an object of first class in second class still i am able to access
variable(protected) of first class.....how come...
if yes how come...if no how come

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #28 (permalink)  
Old 08-14-2007, 09:45 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Quote:
Originally Posted by nogono View Post
An access modifier used in a method, field or inner class declaration. It signifies that the member can only be accessed by elements residing in its class, subclasses, or classes in the same package. //this is the definition of protected

consider two classes in same package
in first class i declare variable as protected

//warning both classes are independent...there is no subclass
if i now make an object of first class in second class still i am able to access
variable(protected) of first class.....how come...
if yes how come...if no how come
Yes, because of the definition of the protected. Where it says that it also can be accessed from the other class that is in the same package as the class that you declared as protected.

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #29 (permalink)  
Old 08-19-2007, 12:03 AM
nogono nogono is offline
Novice
Join Date: Jul 2007
Posts: 35
iTrader: (0)
nogono is on a distinguished road
Icon13 help

difference between static final and just final defining as variable....
public static final int =2;
and
public final int=2;

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #30 (permalink)  
Old 08-19-2007, 04:00 AM
Bench Bench is offline
Full Programmer
Join Date: Jul 2007
Location: UK
Posts: 113
iTrader: (0)
Bench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished road
Quote:
Originally Posted by nogono View Post
difference between static final and just final defining as variable....
public static final int =2;
and
public final int=2;
The difference between static and "non"-static is the life-time of the variable. (the final keyword just means its constant/un-modifiable)

a static variable exists exactly once in the program, for the entire duration of that program - its created before main() runs, and destroyed after main() finishes. Furthermore, that variable belongs to the class inside which it (the variable) is declared

On the other hand, a "non"-static variable exists as part of an object. When an object is created by new, the variable is created as a part of that object - and that variable is destroyed whenever the object is destroyed.
- If another new object is created, then again, that "non"-static variable is created, again, as a component of the new object. Essentially, the variable belongs to the obejct.



In the context of your problem, you were attempting to access a non-static variable which didn't exist, because there was no object attached for it to exist with. making the variable static ensured that the variable did exist when you needed it inside main()

if you had done something like this, you could have omitted the static keyword from your earlier program
Code:
public class dust   //class is called dust
{
    int latin;   //latin is "non"-static

    public static void main(String args[])
    {
        dust my_dust = new dust();   //make a new dust class object in 'my_dust'

        my_dust.latin = 5;   //OK, latin belongs to the object inside 'my_dust'
    }
}

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by Bench : 08-19-2007 at 04:17 AM.
Reply With Quote
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



All times are GMT -7. The time now is 05:04 PM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50