Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Who said Java is easy?

 
Sergio Campos J.
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I built a program in Java for my mobile phone. Sort of a logic game.
It worked fine except for the fact it should generate a random number to be guessed
but it always produced the same number. I read the documentation looking for "random number generation",
made some corrections and, this way, the program, din't work. I decided to rebuild the whole code in a very structured way and followed closely the documentation and then, the program, at last..., didn' work!

This process took about a week..., a month..., two months!
enough to responsibly say: JAVA IS NOT EASY / DOCUMENTATION IS TOO COMPLEX

---

This is my first post here and I've just realized I know anything about Java.
Could someone, please, suggest a quick way to understand Java.
I used to be brilliant learning new code, so I can hardly bear slowness.
Thanks! Greetings from a far off land!

Sergio Campos / Venezuela
 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Funny post

You may want to change your name though, the mods will warn you soon enough.
 
Henry Wong
author
Marshal
Pie
Posts: 20998
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Legg wrote:
You may want to change your name though, the mods will warn you soon enough.


"firifirito firifirito",

As mentioned, please read this...

http://www.javaranch.com/name.jsp

Henry
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, you're going to need to change your display name to a real (sounding) name, and soon. Thanks.

But to answer your question: nobody who knows what they're talking about said that. Java is a lot of things -- including predictable and unambiguous, which make it a good teaching language -- but it's not easy, because programming is not easy.
 
Sergio Campos J.
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest Friedman-Hill wrote:nobody who knows what they're talking about said that.


The people of Sun Java Tutorials says "it's easy to learn"
(http://java.sun.com/docs/books/tutorial/getStarted/intro/changemylife.html)

Obviusly they are mistaken. Or they can't put themselves in the shoes of the average programmer.

Thanks for your advises.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be honest, if someone from Sun says Java is easy or Java is good, ignore that statement. Likewise, if someone from Microsoft says C# is easy or C# is good, ignore that too. Listen to independant sources instead.

We had a commercial a few years back: "we from company X advise company X". In other words, of course they are going to tell you their product is the easiest, best etc.

Still, with enough tutorials, books and mostly practice, you should be able to get quite far.
 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Java is "relatively" easy compared with other front runners like C++. It also depends on what experiences you've had in the past. Coming from a procedural programming background may actually be more of a hindrence than an asset as compared to a newcomer. Java has a rich language, plenty of documentation (although sometimes to techy), lots of tutorials, a huge community, and a large array of open source tools available. I think all of these factors combined can make Java quite a bit easier than learning other languages. I wouldn't let the fact that you couldn't find resources to help you with 1 thing (random numbers) sway your entire opinion of Java. Give it another shot, more time, and more visits to these here forums.
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hear you Sergio. I have often struggled with the same sort of thing. The Sun Tutorial and API docs are excellent, very thorough but, as has been pointed out in another thread somewhere, they are not task centric. Using the Sun documentation is an acquired skill in and of itself. It can be a pain to zero in on specific information. But you will get better at that with time.

Anyways, Sun is not the only place to learn java. Google is your friend.
 
Sergio Campos J.
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Legg wrote:I think Java is "relatively" easy
(random numbers) sway your entire opinion of Java.
Give it another shot [...] more visits to these here forums
Thanks Mr. Legg. I feel welcome to theese forums.
I did find help for random numbers. I haven't fixed my program.
All the example codes I found didn't work when placed in my program.
The conclusion is clear:
I must go back to the basis of Java (how to contruct a Java class)
Ain't doing it rightly.
 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sergio C. Campos J. wrote:All the example codes I found didn't work when placed in my program.


That is alarming! If you have specific examples of code that you could not get to work that you found in the Java Docs/Tutorials you should definately post your code here for review. Figuring out why a Sun provided example doesn't work on your machine would be my top priority.

Also, it's just Brian, and your welcome
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMO Java-the-syntax is easy. It's like hammering--hammering is easy, you just bang on stuff, and it obligingly gets hit.

Learning how to hammer *well* is harder: ever watch a little kid hammer stuff? Heck, even adults manage to smack their own appendages more than seems reasonable. Now take that hammer and imagine there are a million ancillary tools necessary to get work done in the most efficient way possible. That's Java.

When Java is your hammer, everything starts to look like a thumb.
 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:When Java is your hammer, everything starts to look like a thumb.


Hmmm... you didn't say everything starts to look like a nail, so I assume that using Java makes you worried that anything you hit will break something (like your finger)?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just find Java kinda clumsy is all.
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:IMO Java-the-syntax is easy. It's like hammering--hammering is easy, you just bang on stuff, and it obligingly gets hit.

Learning how to hammer *well* is harder: ever watch a little kid hammer stuff? Heck, even adults manage to smack their own appendages more than seems reasonable. Now take that hammer and imagine there are a million ancillary tools necessary to get work done in the most efficient way possible. That's Java.

When Java is your hammer, everything starts to look like a thumb.


Exactly!!!, and therein lies the problem with most documentation, especially Sun's. You look for specific information, or a simple and to the point example, and you find it all wrapped up in all those anciliiary details needed to do things properly. You want to know how to add a button to a JPanel, and you end up reading about implementing runnable and run later and create and show GUI, and nested classes and extends this and that, blah blah blah.... Or a simple case of using random numbers becomes a graduate course in object oriented programming.

rarrrgghhh

thanks for listening
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you mean about the random number things, that's pretty easy.

The thing is this: the JavaDocs aren't where you learn how to program Java--they're the ancillary reference material. For learning how to *use* the classes you do tutorials, read books, read source code, etc. The JavaDocs (in general; things like Mockito embed usage info and mini-tutorials) aren't tutorials. That said, I strongly encourage people to spend a fair amount of time with the JavaDocs, because there's a lot of hidden stuff in there.

It's a matter of time: the Java ecosystem is huge. There are no shortcuts.
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:
...
It's a matter of time: the Java ecosystem is huge. There are no shortcuts.


That's for sure. Anyways, I understand what the API docs are supposed to do, my rant was about being able to cut to the chase with a particular task you might be working on. Sure there's no substitute for time and effort, and understanding the bigger picture, but there are times when the easy things should be quick and easy, or maybe you just need to get it done and worry about the theory later, in which case you are probably better of with google than anything Sun has to offer, and that includes the Tutorial.

But that's just me. And a few others that I have noticed. But I guess not everyone will agree.

regards.

 
John Kimball
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For all the API bloat & language quirks, the one thing I can't stand is the standard Calendar/Date APIs.

Good lord, someone really dropped the ball when they came up with that design.

And then there is Java's generics.

Sigh.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quite a lot of people think the Date APIs are rubbish. And generics is the result of not implementing it in Java1.0; it is awkward to add such a feature later on and maintain compatibility with old versions.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nobody likes Date; that's why there's JodaTime and JSR-310--loooong overdue.

Generics, designed and implemented by smart people, had to maintain compatibility :/ They're a reasonable partial solution given their goals, and fine for simple usecases. As noted, not every usecase is simple.
 
John Kimball
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this topic has been hashed out to death but still, many people would've been happy if they broke compatibility while easing the transition; or not support generics at all.

In the end, Sun's compromise doesn't offer enough over the non-generic approach but adds to the list of language quirks.

 
Sumit Bisht
Ranch Hand
Posts: 331
Python Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Kimball wrote:For all the API bloat & language quirks, the one thing I can't stand is the standard Calendar/Date APIs.

Good lord, someone really dropped the ball when they came up with that design.

And then there is Java's generics.

Sigh.


I guess, learning design patterns makes some sense here as these APIs can give you a lot of practical examples.
Generics is somewhat ok, but closures and functional programming ?
 
Sergio Campos J.
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Legg wrote:That is alarming! If you have specific examples of code that you could not get to work that you found in the Java Docs/Tutorials you should definately post your code here for review.


Here It is... the whole thing:
Two Errors at line 20:

int Posicion = Aleatorio.nextInt(4536) + 1;

1) cannot be applied to (int)
2) incompatible types

both errors disappear if I change the line for any of these:
int Posicion = Aleatorio.nextInt(); // This produces values out of the range of Vector Validos
or
int Posicion = 3000; // Obviusly produces always the same value
...
Thanks for your help

 
Henry Wong
author
Marshal
Pie
Posts: 20998
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sergio C. Campos J. wrote:
Here It is... the whole thing:
Two Errors at line 20:

int Posicion = Aleatorio.nextInt(4536) + 1;

1) cannot be applied to (int)
2) incompatible types


What version of JavaME are you using? The Random.nextInt(int) method is not available for some versions.

Henry
 
Sergio Campos J.
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
What version of JavaME are you using? The Random.nextInt(int) method is not available for some versions.
Version 2.2 (25/10/2004 10:21 PM)
Copyright 2004 Sun Microsystems, Inc. All rights reserved.
SUN PROPRIETARY/CONFIDENTIAL.
Use is subject to license terms.
For more information on Java 2 Platform, Micro Edition (J2ME),
visit http://java.sun.com/j2me.

I'm not sure if I am using the proper documentation...
Let me find out in other forum.
 
Sergio Campos J.
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well..., I found a solution to generate a random number between 1 and 4536 without using java.util.random

int Position = (System.currentTimeMillis() % 4536) + 1

But I got a new error: possible loss of precision


The error can be fixed changing Position to type long
But I need the variable to be type int

Someone can help?



 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sergio CamposJ wrote:Well..., I found a solution to generate a random number between 1 and 4536 without using java.util.random

int Position = (System.currentTimeMillis() % 4536) + 1

But I got a new error: possible loss of precision


The error can be fixed changing Position to type long
But I need the variable to be type int

Someone can help?


Use an explicit cast:

int Position = (int)(System.currentTimeMillis() % 4536) + 1

The reason you are getting this is because it is a narrowing converstion. You are taking a long and trying to fit it into an int, which the JVM knows is smaller. Therefore you have to tell it through an explicit cast that you are aware that it is smaller but are willing to take that risk.

Now, if you were converting from an int to a long you wouldn't have to explicitly cast since it would be a widening conversion.

And by the way, it was me. I said Java was easy. I admit it! I also claim the Earth is flat and the Sun revolves around the Earth! Geocentric universe!
 
Sergio Campos J.
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Now the program successfully accomplish the job. Thank you Joe! Yes! Java is easy! funny ending!
And thanks to everybody.
 
Henry Wong
author
Marshal
Pie
Posts: 20998
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sergio CamposJ wrote:Well..., I found a solution to generate a random number between 1 and 4536 without using java.util.random

int Position = (System.currentTimeMillis() % 4536) + 1



I don't get it.... It is nextInt(int) that is unavailable in J2ME. The nextInt() method *is* avaialble. Why use the system time, when you have nextInt()? Doing a mod on a random number is definitely better than doing a mod on a time value.

Henry
 
Sergio Campos J.
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doing a mod on a random number is definitely better than doing a mod on a time value.

Thank you Mr. Wong.
int types in Java range to negative numbers also?
or nextInt() returns only positive numbers?
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Data types. Random class. You can read the details there.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic