• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • paul wheaton
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
  • Himai Minh
Bartenders:

Memory and Time management

 
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java, we can program a Question in number of ways. But, which how to know the memory usage and time required by a particular program to execute?

I think, after knowing this, one can really improve his/her way of coding.

Thanks In Advance
 
Greenhorn
Posts: 7
Opera Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Well, a lot of tools exists to do this for you..

Inside your Java JDK there is a file called: jvisualvm which is found inside bin... Have you tried it??

Which king of problem are you facing exactly?
Is it what you want?

Goodluck!!
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Noel for your reply

I am not having any problem, just wondering, how to improve my coding part. Because memory and time, both is IMPORTANT. And you can code a single program in number of ways. So, how to know which coding is efficient with respect to time consumed and memory.

I haven't tried jvisualvm.

Will you please assist me.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Study algorithms and data structures, so that you understand how much time an algorithm will take or how much memory a datastructure will take as the number of items to be processed or stored grows. See: Analysis of algorithms.

For something concrete, you can study different sorting algorithms, for example quicksort, bubble sort, insertion sort, etc. The question to answer is: if the collection to sort has N items, then how much time (on average) would it take to sort those items? Is it approximately N units of time, or N^2 units of time, or N log(N) units of time?

The book Introduction to Algorithms is a classic university-level book about learning to analyze algorithms and data structures.
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jesper de Jong for your concern

Sorry to say, but i didn't ever studied Data structures and Algorithms as i am from a commerce background.

I know, Data structures and Algorithms will help me a lot, but, is there any other tools provided for fetching memory usage and time consumed by the code?
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Someone please reply.

 
lowercase baba
Posts: 13086
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first, you should EaseUp. everyone here is a volunteer, and gives what time they can.

There are plenty of tools that can help you - search for "java profilers". The problem is that they can only tell you how your EXISTING code runs, not how some theoretical code will run. You don't want to write out the code using one method, see how it runs, then develop it all over again using a new method and see how that runs in comparison. At least, I hope you don't.

Your other option is to learn about data structures and algorithms, and then do some data analysis. The classic example is sorting. There are perhaps a dozen different sort algorithms. Some work great when the data is mostly sorted and you are just sticking in a (relatively) few new data points, but do HORRIBLE if the data is completely random. Others are the exact opposite. This, then requires you to have an idea of what your data will look like, and what you will be doing.

there is no 'magic bullet'.

Finally, your BEST best it to document ahead of time what your requirements are - and they should be SPECIFIC. a spec of "it will run as fast as possible" is meaningless. It is ALWAYS possible to run faster, if you buy bigger/better/badder hardware, but that costs $$$. Write code that is neat, clean, easy to read, and easy to debug (since you will be doing a LOT of debugging). Once that is done, IF it doesn't meet your requirements, use a profiler to find out where you are slow, and work on that part of the code.
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply fred rosenberger.


Actually i never studied Data Structures & Algorithms as i am from a commerce(Accounts) background. But, in many interviews, they ask me these things.

Finally i am going to join a small company relating to web designing and development. And i will be the only programmer. So, i am really confused whether i should go for Data Structures & Algorithms or just stick to what i know.

What do you suggest fred rosenberger?
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kunal Lakhani wrote:Actually i never studied Data Structures & Algorithms as i am from a commerce(Accounts) background. But, in many interviews, they ask me these things.


The fact that you're from a commerce background should not be an excuse to not study data structures and algorithms.

Data structures and algorithms are fundamental building blocks for software engineers - there's a good reason why people ask you about these things in job interviews. If you want to become a serious software engineer, you're going to have to study them sooner or later. Because you'll need to know how to choose the right algorithms and data structures to write efficient programs.
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Will you please suggest a book for that?
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:
The book Introduction to Algorithms is a classic university-level book about learning to analyze algorithms and data structures.



Hi kunal, you have been already suggested a book by jesper.
 
Rameshwar Soni
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Noel Alex wrote:
Well, a lot of tools exists to do this for you..

Inside your Java JDK there is a file called: jvisualvm which is found inside bin... Have you tried it??


Can you tell me how to use this file ?
 
Marshal
Posts: 77577
372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
webpage
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rameshwar Soni wrote:Can you tell me how to use this file ?


In a Windows command prompt window, type the command "jvisualvm".
 
Rameshwar Soni
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:
In a Windows command prompt window, type the command "jvisualvm".


When i tried i got the following
C:\>jvisualvm
'jvisualvm' is not recognized as an internal or external command, operable program or batch file.
C:\>

And yes i path is properly set because when i type javac i get a list of commands.
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After typing the command "jvisualvm". in a Windows command prompt window?


I went through some documentation. But didnt understood how to use jvisualism.
 
Campbell Ritchie
Marshal
Posts: 77577
372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is obviously a path problem, Rameshwar Soni. Open the java installation folder specified in your path environment variable, until you find the "bin" folder; jvisualvm should be inside that. If not, try reinstalling Java.
 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rameshwar Soni,

if I may give you some friendly advice.

The first one: Relax. Don't try to write the "best code ever written". Write code that can be easily understandable and maintained.
The second one: Don't overdo it. A program evolves. Do what you have to do, try it, test it, stress it and learn how to find bottlenecks. When you find them, sort them out by refactoring them and ask specific question to those who are elderly and should know better.
The third one: Relax. And then take up Jespers advice and study algorithms. They have nothing to do with the Java language in specific. They are more general and fit more or less into all languages.
The fourth and final one: Have fun! Play around. Try things. One thing you could do is trying to answer questions asked here at the Ranch. You might not be quickest but at least you will try for yourself and then, most likely, one of the elderly will have a good answer that you can study.
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all of you for valuable suggestions.

I will definitely consider the advice of going through algorithms.


 
Rameshwar Soni
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ove Lindström wrote:Hi Rameshwar Soni,

if I may give you some friendly advice.

The first one: Relax. Don't try to write the "best code ever written". Write code that can be easily understandable and maintained.
The second one: Don't overdo it. A program evolves. Do what you have to do, try it, test it, stress it and learn how to find bottlenecks. When you find them, sort them out by refactoring them and ask specific question to those who are elderly and should know better.
The third one: Relax. And then take up Jespers advice and study algorithms. They have nothing to do with the Java language in specific. They are more general and fit more or less into all languages.
The fourth and final one: Have fun! Play around. Try things. One thing you could do is trying to answer questions asked here at the Ranch. You might not be quickest but at least you will try for yourself and then, most likely, one of the elderly will have a good answer that you can study.


Thanks Ove for your advice, they are always helpful for any beginner like me.
 
Rameshwar Soni
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:That is obviously a path problem, Rameshwar Soni. Open the java installation folder specified in your path environment variable, until you find the "bin" folder; jvisualvm should be inside that. If not, try reinstalling Java.


I will try it out. Thanks for your reply
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic