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 05-03-2008, 07:36 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 218
Zosden is on a distinguished road
Stacks
I wanted to bring up the topic of Java's stack class.

Do you think its write that programmers have the ability to iterate through a stack?
__________________
Definition of Impossible = making a good game in Java.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-03-2008, 03:47 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 250
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
What do you mean?
__________________
best regards,
sukatoa
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-03-2008, 05:02 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 218
Zosden is on a distinguished road
What I mean is should you be able to search through a stack without having to pop off all the data first.
__________________
Definition of Impossible = making a good game in Java.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-03-2008, 07:45 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 250
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
No, that is impossible.... (for me)

But, by using toArray() method, i can search those elements.

How about you?
__________________
best regards,
sukatoa
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-03-2008, 08:03 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 218
Zosden is on a distinguished road
You can search through one of Java's stacks with an iterator method because of how Java made their stacks. I believe this breaks down what a stack should be able to do. In a stack you should only be allowed to see the first element, and you should only be able to add or remove to the top of the stack.
__________________
Definition of Impossible = making a good game in Java.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-03-2008, 08:08 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 250
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
....Yep....
__________________
best regards,
sukatoa
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-03-2008, 08:42 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 218
Zosden is on a distinguished road
This topic as become a topic of debate in the Java community. I was wondering what the opinion of this sites members was. Please don't comment if you don't have anything to add to this discussion, it just makes you look incompetent.
__________________
Definition of Impossible = making a good game in Java.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-04-2008, 06:43 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 250
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Yep means, i agree....

Quote:
it just makes you look incompetent.
....For you only....

I've learn stack in C and Assembly.

in C, nice and helpful to implement...
in Assembly, i always use stack implementation
(if all general registers are full)
But for Java? i never use that on my application(just on exercises).

What for?
Can you show us a serious application that uses a stack? And that application is fully dependent on a stack implementation?

Maybe stack in java will be useful if you will design a new higher level language compiler using java.
__________________
best regards,
sukatoa
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-04-2008, 07:43 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 218
Zosden is on a distinguished road
My topic was about the way sun has implemented stacks in their API. A stack should only let the user be able to see the first item int the stack, but Java lets you search through the stack and see whats in the middle of it. An example of this would be a stack calculator. Sorry this isn't the best example, but it works.
__________________
Definition of Impossible = making a good game in Java.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-05-2008, 04:51 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 250
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Quote:
A stack should only let the user be able to see the first item int the stack.
That's an ideal and that theory was maintain in Assembly.

Quote:
but Java lets you search through the stack and see whats in the middle of it.
I think Sun MicroSystems added that feature ( can now access anywhere) for the programmer(implementor) to test if the exact value inserted on that stack are correct or if it is in correct order and able to predict what's the next value to be poped-up ( or the last value to be poped-up) and that is now the advantage.

And it is for debugging purposes only, other purpose makes the stack abused.
__________________
best regards,
sukatoa
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 05-05-2008, 05:18 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 218
Zosden is on a distinguished road
But you shouldn't need to debug like this. If you are then you have deeper problems with your stack.
__________________
Definition of Impossible = making a good game in Java.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 05-05-2008, 05:26 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 250
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
If i will use an Iterator, then problem may occur if failed to do so.

But by using toArray, it only returns a shadow copy of the stack. Its just to browse the content without banging the element on that stack.(value checking only)

If something is wrong, only push and pop should be and recommended to use.

I don't know the other safe options( if any )
__________________
best regards,
sukatoa
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 05-05-2008, 07:44 AM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 117
danielstoner is on a distinguished road
My 2 cents...

I believe there is a time and place for every idea. Yes stacks allow you to work with the top of the stack always but the main idea behind it is not that. The main idea is to maintain an order for doing something and then undoing it. And stacks are just a solution for this problem.
But then, there are other problems to be solved out there. Sometimes after you build the stack you might need to know some information about it. Sometimes you might need to peek inside and make some decisions. The implementation in Java simply allows the programmer to use a versatile library class as he sees fit.
By the way, there are programming languages out there that use stack manipulation at runtime in order to do optimizations and to offer "magical" features.
Nothing scares me in programming and in life more than a dogma and a religious war . The only rule is "there are no rules". Don't take a book definition of a fact and make it your "dogma". This will only make you turn a blind eye to other points of view and other possibilities.
Just think about it. Isn't a stack implementation more useful and flexible and possibly a part of the solution for more problems if it allows you to know more about its internal state at any moment? Of course it is also easier to mess up . But nothing stops you from writing a wrapper that only gives access to the basic stack functionality.
__________________
Daniel @ [www.littletutorials.com]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 05-05-2008, 08:01 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 218
Zosden is on a distinguished road
I agree with you daniel also I just haven't thought of anytime when it would be useful to know whats in the stack. If I have to know then maybe I'm using the wrong thing.
__________________
Definition of Impossible = making a good game in Java.
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 05-05-2008, 09:10 AM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 117
danielstoner is on a distinguished road
As an example just think about two threads:
- thread one is using the stack in a classical way pushing and popping values on the stack
-thread two monitors the stack and it is notified whenever the stack changes; when the stack changes it will go and calculate statistics about the stack content

These two threads use the stack in different ways: one as stack, the other as a list.
__________________
Daniel @ [www.littletutorials.com]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 05-05-2008, 09:16 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 218
Zosden is on a distinguished road
Ok thank you for the example I think that has helped my understanding of stacks.
__________________
Definition of Impossible = making a good game in Java.
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
Using Stacks ravian New To Java 7 11-28-2007 10:53 AM
I want to be able to do this with stacks and queues as well as with vectors carl New To Java 1 08-07-2007 08:05 AM


All times are GMT +3. The time now is 09:22 AM.


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