Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How java programs store in Heap and Stack.

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    19
    My Mood
    Confused
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question How java programs store in Heap and Stack.

    Hi.
    I started java programming few weeks ago. Im trying to understand how java objects, variable and main program stored inside heap and stack.
    I marked with question marks for places where i want to know. Please help me to understand.
    class Student{
        int age;               // ?
        String name;     // ? 
     
        public Student() //  ?
        {
            this.age = 0;
            name = "Anonymous";
        }
        public Student(int Age, String Name) // Parameter int Age and String Name ? 
        {
            this.age = Age;
            setName(Name);
        }
        public void setName(String Name) // method and parameter ?
        {
            this.name = Name;
        }
    }
     
    public class Main{  
    	public static void main(String[] args) { // public method ?
                Student s;                   // ?
                s = new Student(23,"Jonh");
                int noStudents = 1;          //local variable
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How java programs store in Heap and Stack.

    Where the java program puts the parts of the program when the program is executing depends on the java program's implementation. Usually class objects go in the heap and method variables on the stack.
    Why are you interested in where data is put in memory?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    19
    My Mood
    Confused
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: How java programs store in Heap and Stack.

    Thank you for your reply. Currently im studding java in a Institute. I got some programs to resolve. But i have to explain in a way how java programs work with memory when running these programs.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How java programs store in Heap and Stack.

    i have to explain in a way how java programs work with memory
    Why is a beginning programming course concerned about how the java program uses memory?
    There is so many other things to learn.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. heap size vs heap used
    By aueddonline in forum Java Theory & Questions
    Replies: 5
    Last Post: February 10th, 2012, 01:59 PM
  2. programs of java
    By chinu in forum Java Servlet
    Replies: 2
    Last Post: July 26th, 2011, 12:08 PM
  3. Implementing a queue or stack using a heap
    By tla280 in forum Java Theory & Questions
    Replies: 1
    Last Post: December 1st, 2010, 12:29 AM
  4. Java Heap Space
    By aussiemcgr in forum Java Theory & Questions
    Replies: 4
    Last Post: September 8th, 2010, 05:05 PM
  5. AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
    By nasi in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 25th, 2010, 10:37 PM

Tags for this Thread