We help IT Professionals succeed at work.

need assist to change the linked list of C++ into JAVA linked list

David H.H.Lee
on
943 Views
Last Modified: 2013-12-14
these questions is from a friend of mine, hope can get solutions from yours. Thanks

Questions:

1.i had declare an object of a class in my program, when i trying to execute it. it show me this error:
java.lang.StackOverflowError    
<<<< may i know what's the problem with this? by the way, the class which i declare an object with, is using Link-list data structure.is that problem with the link list ?

2 . the question
i'm trying to change the link- list of C++ into JAVA. the problem is, i'm not sure what should i do when it involve struct of C++ and pointer of the struct.

3. by the way, when we assign a null to an object in JAVA, which

(In C++)

Weight *next;

Weight(double w, Neuron sn)
{
    next = (Weight *)null;   //do i have to do the same in JAVA , which when i assign a null
                    //to the object, i will have to put cast of the class for it    
}


4. how to change this code?
(in C++)
Neuron *neuron1;
Neuron *neuronL;
Neuron *nptr;

neuron1=neuronL=nptr;  
(in JAVA, is it change to this? )
Neuron neuron1;
Neuron neuronL;
Neuron nptr;

neuron1=nptr;
neuronL=nptr;

5. sure can call the next object in the link list, when we do like this in JAVA or not ?
 >>  wi =wi.next;   ??

6. how to use the clone method? i mean in what case we should use this method?

7. there is somethings i wish to make sure of is:
>>  Network newNetwork; (In JAVA)
>>  Network *newNetwork; (in C++)

 or do we have to assign a null to each of the object which only declare and not yet been used?
>> Network newNetwork = null; (in JAVA) ?? or Network newNetwork = (Network) null ?????


i'm getting blur and blur already 8-}
i only left with 3 more days to submit the assignment ~.~
help~~~!!!
Comment
Watch Question

Commented:
2 . the question
i'm trying to change the link- list of C++ into JAVA. the problem is, i'm not sure what should i do when it involve struct of C++ and pointer of the struct.

Java has a built in LinkedList class in the SDK... look it up in the docs

Commented:
3. by the way, when we assign a null to an object in JAVA, which

no.

Weight next;
next = null;

Commented:
7.

Network newNetwork = null or
Network newNetwork = new newNetwork(...)

Commented:
4.

Neuron neuron1 = New Neuron();
Neuron neuronL;
Neuron nptr;

neuron2 = neuron1;
nptr = neuron1;

Commented:
the rest of them probably (i didn't read them too carefully) have something to do w/ the linked list you are using... try the java one and come back w/ any issues.
David H.H.LeeDigital Marketing (Hospitality)
CERTIFIED EXPERT

Author

Commented:
yeap, the linked list of C++ involving Struct.
David H.H.LeeDigital Marketing (Hospitality)
CERTIFIED EXPERT

Author

Commented:
this is the error showed while my friend is trying to change compile his code
>>  java.lang.StackOverflowError
may i know the cause of this problem ?

this error occur when he is trying to declare an object for a class. the error capture using the exception handler is as above
a stack trace and code list would be needed probably
David H.H.LeeDigital Marketing (Hospitality)
CERTIFIED EXPERT

Author

Commented:
a stack trace and code list ?
example ?
1.i had declare an object of a class in my program, when i trying to execute it. it show me this error:
java.lang.StackOverflowError    
<<<< may i know what's the problem with this? by the way, the class which i declare an object with, is using Link-list data structure.is that problem with the link list ?

it could be that the linked list implementation isn't deleting objects, simply flagging them as unavailable, this would eat up memory, check what happens on the remove method for each node if you can.
the fact that it's a stack overflow also points to the fact that all the node objects are still taking up memory since the references to the objects are stored on the stack whilst the fields making up the objects exist on the heap.
If you're creating a lot of nodes in your neural net maybe your system doesn't have enough memory.

you can set the default stack size with
 -Xss<size>        set java thread stack size

java -ss sizeofstack ClassA
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
David H.H.LeeDigital Marketing (Hospitality)
CERTIFIED EXPERT

Author

Commented:
the recursively call you mean . is it
>>>>   tryOnly = tryOnly.getNext();
??? by the way, if declaring an new object, which it will use at later.. do we have to assign null to that obejct?
assigning >>  objectTry = (Class)null;
??then later after we have finish using the object, is it compulsory for us to assign null to that object again ?
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
David H.H.LeeDigital Marketing (Hospitality)
CERTIFIED EXPERT

Author

Commented:
24 neuron in input layer. 4 neuron in output layer and 50 neuron is hidden layer
David H.H.LeeDigital Marketing (Hospitality)
CERTIFIED EXPERT

Author

Commented:
ok, i try to check it  out . might need assists in further. thanks
That's a pretty small number of objects, i don't think that's the problem, unless you create new neurons to replace old ones and don't remove all pointers to the old neurons.  Then the GC wouldn't remove them.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
I'd say your recursively calling a method, most probably in an endless loop.
The stack trace for the exception should point you to how it is occurring.

ex.printStackTrace();
David H.H.LeeDigital Marketing (Hospitality)
CERTIFIED EXPERT

Author

Commented:
by the way.. may i know where i can get information about Multilayer Perceptron, which is a Artificial Neural Network design.. i need help in setting the Input layer nodes, hidden layer nodes and output layer nodes.. and
how to solve the input scheme? if the data i got froom user is in "1" or "0" binary representation only....
and how about the output? in any numbers? or have to be same with the input we had set?

your helps will be appreciate...
thanks.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.