File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Who said Java is easy? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Who said Java is easy?" Watch "Who said Java is easy?" New topic
Author

Who said Java is easy?

Sergio Campos J.
Ranch Hand

Joined: Jun 01, 2009
Posts: 53
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


"There are times when the easy things should be quick and easy" [...] "and worry about the theory later" -Fred Hamilton-
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
Funny post

You may want to change your name though, the mods will warn you soon enough.


SCJA
~Currently preparing for SCJP6
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18101
    
  39

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

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.


[Jess in Action][AskingGoodQuestions]
Sergio Campos J.
Ranch Hand

Joined: Jun 01, 2009
Posts: 53
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

Joined: Oct 27, 2005
Posts: 19538
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
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

Joined: May 13, 2009
Posts: 679
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

Joined: Jun 01, 2009
Posts: 53
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

Joined: Nov 07, 2008
Posts: 488
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Nov 07, 2008
Posts: 488
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

Joined: Sep 29, 2008
Posts: 12617

I just find Java kinda clumsy is all.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: May 13, 2009
Posts: 679
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

Joined: Apr 13, 2009
Posts: 96
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

Joined: Oct 13, 2005
Posts: 36453
    
  15
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Apr 13, 2009
Posts: 96
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

Joined: Jul 02, 2008
Posts: 329

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

Joined: Jun 01, 2009
Posts: 53
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
Sheriff

Joined: Sep 28, 2004
Posts: 18101
    
  39

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

Joined: Jun 01, 2009
Posts: 53
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

Joined: Jun 01, 2009
Posts: 53
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

Joined: Feb 10, 2009
Posts: 710
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!


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Sergio Campos J.
Ranch Hand

Joined: Jun 01, 2009
Posts: 53
Ok. Now the program successfully accomplish the job. Thank you Joe! Yes! Java is easy! funny ending!
And thanks to everybody.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18101
    
  39

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

Joined: Jun 01, 2009
Posts: 53
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

Joined: Oct 13, 2005
Posts: 36453
    
  15
Data types. Random class. You can read the details there.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Who said Java is easy?
 
Similar Threads
Help needed in Java
random number question
how to generate random numbers ? Random class always generate same number....
Class Random or Math.random()???
how to use Random( )?