This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Code porting nightmare: Javascript to Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Code porting nightmare: Javascript to Java" Watch "Code porting nightmare: Javascript to Java" New topic
Author

Code porting nightmare: Javascript to Java

Carlos Romero
Greenhorn

Joined: Feb 06, 2013
Posts: 3
Hello again! I'm still stuck with this.

I have a Javascript code that I have to port to Java, but after doing it the results are different.

I hate to ask and bother you with my problem, specially this, which is pretty complicated.

I assume the Javascript is correct, it's the one that it was working after all...

Javascript
Input is: width=19, depth=19, height=19
Result: count=581, total_z=0, total_y=19, total_x=19, and a long map of trues and falses.

Java
Input is: width=19, depth=19, height=19
Result: count=1093, total_z=19, total_y=19, total_x=19, and a long map of trues and falses.

First of all I don't know how to properly translate the .hasOwnProperty method, I think that what I made is fairly correct.
I think that the problem is on the loops: In the .js code uses arrays and I used Lists, and I also don't know how to do that part.

Well, here is the code. I hope you can understand it!

Javascript:


Java code:


Please, help. ;_;
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

There is no hasOwnProperty method in Java. Nor is there a need for one. Java and JavaScript are very very different languages. A line by line port is not going to be effective.

I think you'd be better of reverse engineering rather than trying to port.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Code porting nightmare: Javascript to Java
 
Similar Threads
Strange Vector3(double, double, double) symbol not found?
Having trouble choosing a data structure
problem of MediaTracker and paint(Graphics)
When I use MediaTracker , the method "paint(Graphics)" will be invoked ceaselessly!!
Please Explain (Hashcode)