Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 300,466 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,705 people online right now. Registration is fast and FREE... Join Now!




Problems with the Primitive Data Type Integer

 

Problems with the Primitive Data Type Integer

labyrinth_fufu

3 Jul, 2009 - 02:25 AM
Post #1

New D.I.C Head
*

Joined: 23 Sep, 2008
Posts: 18


My Contributions

How would you set a primitive data type (integer) into null?
In the following code for example.. data[top] = null, creates an error. blink.gif

CODE


    protected int data[];

    @Override
    public int pop() throws EmptyStackException {
        data[top] = null;                         //this line creates an error
        new MyStackClass(top - 1);
        capacity = top + 1;
        return data[top];
    }



In this case, what should I do then? Help? please....

User is offlineProfile CardPM
+Quote Post


bbq

RE: Problems With The Primitive Data Type Integer

3 Jul, 2009 - 02:51 AM
Post #2

omgwtfbbq
Group Icon

Joined: 15 May, 2008
Posts: 725



Thanked: 64 times
Dream Kudos: 125
My Contributions
Ahh perhaps data = null

eg...
java

protected int[] data;

// .. code
data = null;


instead of something like
java

protected int[] data;

// .. code

data = new int[10];


smile.gif

This post has been edited by bbq: 3 Jul, 2009 - 02:52 AM
User is offlineProfile CardPM
+Quote Post

mostyfriedman

RE: Problems With The Primitive Data Type Integer

3 Jul, 2009 - 03:08 AM
Post #3

Striving Student
Group Icon

Joined: 24 Oct, 2008
Posts: 3,148



Thanked: 355 times
Dream Kudos: 600
Expert In: Learning

My Contributions
you cant set a primitive data type to null, only reference data types..anyway you could do something like this..check if top is equal to 0..if it is then throw an exception or print a message that the stack is empy else pop the value
User is online!Profile CardPM
+Quote Post

pbl

RE: Problems With The Primitive Data Type Integer

3 Jul, 2009 - 03:27 AM
Post #4

Java Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 9,537



Thanked: 1126 times
Dream Kudos: 450
My Contributions
QUOTE(labyrinth_fufu @ 3 Jul, 2009 - 02:25 AM) *

How would you set a primitive data type (integer) into null?

You just can't
Object reference are reference which means pointer

Object obj = null;

means obj points to nothing.

Object obj = abc;

means obj points to the Object abc does not mean obj contains abc.

Primitive datatype are not reference they contain what they mean

int x = 0;

means x contains 0

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 02:34AM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month