Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

What are data structures in Java?

 
Ranch Hand
Posts: 2545
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read that data structures in Java include Stacks , Queues. How is it decided whether a particular member of collections interface is a data structure or not. Thanks
 
lowercase baba
Posts: 13013
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can have a stack or a queue (or many, many other data structures) implemented in just about ANY programming language.

Where exactly did you read this?  It doesn't sound correct to me - at least, not if they are saying these are unique or somehow special to Java.
 
Ranch Hand
Posts: 127
2
Monad Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Data structures are pretty much the same across languages.. They are(in the simplest terms) areas of memory that can hold data.
 
Monica Shiralkar
Ranch Hand
Posts: 2545
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gerard Gauthier wrote: areas of memory that can hold data.



What does areas of memory that can hold data mean. Even a string is also an area of memory that can hold data.
 
Gerard Gauthier
Ranch Hand
Posts: 127
2
Monad Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:

Gerard Gauthier wrote: areas of memory that can hold data.



What does areas of memory that can hold data mean. Even a string is also an area of memory that can hold data.



And a string is a data structure. A integer is a data structure.
 
Ranch Hand
Posts: 179
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:I read that data structures in Java include Stacks , Queues. How is it decided whether a particular member of collections interface is a data structure or not. Thanks



there were a plenty of Data Structure that you've listed above , and each of them have advantages and disadvantages also treating data or process data differently  
 
Saloon Keeper
Posts: 13384
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The name "data structure" really says it all. Anything that is a structured piece of data is a data structure. It's not necessarily limited to in-memory data either. A file or a part of a file on a file system can be considered a data structure as well, or a packet being sent between two systems, or really anything that consists of non-random data.
 
Saloon Keeper
Posts: 24540
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mathematics time.

A Data Structure is a tuple of data items which in turn may be data structures or primitives. A primitive is a single irreducible data item. Depending on how you look at it, that includes Strings, since a Java String is essentally a tuple with a single data value. I'll skip over breaking down a String's value into characters, since that puts us perilously close to the "black box" parts of Java. Arrays, incidentally, are not usually considered to be data structures per se,, although you might consider arrays of arrays to be.

I'd also like to point out the difference between data structures and storage structures. In languages like C, you define data structures (structs), but you can, if you know the characteristics of the compiler and the target system determine precisely to the byte how much memory each element in the tuple takes up and how the item is aligned in memory (some hardware requires fill bytes, for example). Thus, data structures in C are Storage Structures. Though C++ classes are a probable exception, since they have invisible components.

Java doesn't do storage structures. You don't know for certain how much RAM  data structure occupies, where it resides in memory, or hos it is represented as long as it satisfies the Java Language Specs. If a JVM implementer devides to store Strings as compressed bits rather than as a simple array of char, that's fine as long as when you ask it to decant a String into an array of char it can do so. Consider Morse code. E and T are 1 bit long, A and I are 2 bits, S and O are 3 bits, and so forth. You can just as easily keep a String in that form internally, at the cost of some CPU overhead (unless you have the Morse Instruction Set module installed).

So, practically speaking, any concrete class object in Java is a Data Structure. Some are simple, such as Integer and String. Some are more complex, like the Collection classes. Some are really complex. But they all have the same basic properties of containing and associating. And, of course in Java, if it's a class, it's a subclass of java.lang.Object.
 
Ranch Hand
Posts: 82
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

DataStructure is the programmatic way of storing data and organizing data, so that data can be used efficiently.
Data structure and Algorithms is a common asset in any programming language, and it is nothing to do with what programming language you are using. The basic concepts and logics of data structure remains same in all programming languages.
As the way to store and manipulate internal data mostly determines how much resources and time the application consumed to carry out its tasks, choosing an appropriate data structures can boost the performance of your program and, quite often, reduces implementation efforts.

Therefore, an important part of programming is to determine the right data structures for a given problem. For this one must understand the type of data is getting used in the program, and then finding a predefined way of a solution.

The data structure name indicates itself that organizing the data in memory. There are many ways of organizing the data in the memory as we have already seen one of the data structures, i.e., array in C language.

If you are good in Java as compare to C++ then you should continue data structure practice with Java.

I hope this will help you
 
Monica Shiralkar
Ranch Hand
Posts: 2545
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have heard a common interview question "have you worked on data structures ".Seeing what's mentioned in this thread each and every candidate would have worked on String atleast which is also a data structure .
 
Marshal
Posts: 74359
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eric Hehner (A Practical Theory of Programming) page 14 says strings are

unpackaged, indexed

...data structures.
 
Marshal
Posts: 26910
82
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:I have heard a common interview question "have you worked on data structures ".Seeing what's mentioned in this thread each and every candidate would have worked on String atleast which is also a data structure .



But of course you should ask the interviewer "What are data structures?"

And you should also ask what is meant by "worked on". I have been working in Java for many years and I don't believe I ever "worked on" a data structure. If you want to limit yourself to sets and maps and lists and things like that, I never "worked on" any of them. I just chose a suitable data structure for my data and went on with the actual work. Those are wheels which do not need to be re-invented.
 
Tim Holloway
Saloon Keeper
Posts: 24540
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
https://en.wikipedia.org/wiki/Algorithms_%2B_Data_Structures_%3D_Programs
 
Ranch Hand
Posts: 536
10
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:I read that data structures in Java include Stacks , Queues. How is it decided whether a particular member of collections interface is a data structure or not. Thanks



I see you want to understand why are used and asked in the interviews?
Imagine you have a class  called Monica that has a name and age variables. or an array.
Your family say hey Monica to book the flight we need your name and age, and also of your husband and your 3 children.
So you will create a kind of mini database(that is not a real database), where you can store these informations while you need , and when somebody will ask you I do not get your husband age, you are going to get from the list the name of your husband only. A data structure is where more than one item is stored but usually not in a database but in the scope of your program.
You have List, arrayList HashMap and so on, why `you should use one instead of another? Because if you should have one million of items the choice of one instead of another will have a big performance effect, so in general every data structure serves a purpose.
Secondary they are asked in the interview because they are build with algorithms, a concept advanced that help you to solve problems. For instance if you need from a list to take only the age you need  the program will have to go trough  the list and find the particular item you need. This look easy but in reality MR  List class to do this in the proper way is going to do a lot of work for you, is going to load the list of names, see in which position have to go, take what is inside that LIST at that specific position and come back to you.

Knowing algorithms and data structures is not essential to build the majority of the programs because there has been already somebody that thought about this, usually the language you use has data structures. but knowing data structures, algorithms and also design patterns is what will make you a competent developer, and also you will be able to write your self the building block you need if your use case is not common, and finally you will be better in general to write the code because you know what miss machine needs to execute her orders, well almost because miss machine has an unconscious formed by bytes sequences, but this is another fantastic adventure
 
Monica Shiralkar
Ranch Hand
Posts: 2545
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Monica Shiralkar wrote:I have heard a common interview question "have you worked on data structures ".Seeing what's mentioned in this thread each and every candidate would have worked on String atleast which is also a data structure .





And you should also ask what is meant by "worked on". I have been working in Java for many years and I don't believe I ever "worked on" a data structure. If you want to limit yourself to sets and maps and lists and things like that, I never "worked on" any of them. I just chose a suitable data structure for my data and went on with the actual work. Those are wheels which do not need to be re-invented.



Yes..true
 
reply
    Bookmark Topic Watch Topic
  • New Topic