|
6 Nov 2006, 03:05
|
#1
|
☆ ♥
Join Date: Jan 2003
Posts: 3,489
|
[Java] Recommendations
I bought "Java Programming for Everyone" by some Hansen guy but I don't like the book. Doesn't go into enough depth. Rather than spend ridiculous amounts of money on books that aren't good, does Phil & co have any good recommendations for learning java and books for 'beyond' ?
Thanks.
__________________
R3: LegioN (came #32) || R4: BlueTuba
R5: WolfPack Order || R6: Wolfpack
R7: Fury
----------retired-------
R52-R55: Apprime
R56-R57: FaceLess
R58-60: Apprime/Ultores
|
|
|
6 Nov 2006, 03:29
|
#2
|
Insomniac
Join Date: May 2003
Posts: 3,583
|
Re: [Java] Recommendations
Java - How to program 5th edition by deitel+deitel.
It goes to some extremes for detail at times, but is a solid book
ISBN 0-13-120236-7
another one is Java 2- The complete reference by Herbert Schildt
ISBN 0-07-222420-7
both of them are very chunky, heavy ( and expensive ) books, but are fairly good
|
|
|
6 Nov 2006, 05:13
|
#3
|
☆ ♥
Join Date: Jan 2003
Posts: 3,489
|
Re: [Java] Recommendations
Thanks Phil.
Rather than create a new thread, is there a way to call up a method within another method?
e.g. let's I am in this public atm.::
public static void treediagramquiz()
and I have an if statement - if this statement is true, perform another defined method
public static void treediagramquiz_two()
can I call that up within an if statement of a previous method?
Thanks.
__________________
R3: LegioN (came #32) || R4: BlueTuba
R5: WolfPack Order || R6: Wolfpack
R7: Fury
----------retired-------
R52-R55: Apprime
R56-R57: FaceLess
R58-60: Apprime/Ultores
|
|
|
6 Nov 2006, 12:23
|
#4
|
Insomniac
Join Date: May 2003
Posts: 3,583
|
Re: [Java] Recommendations
yes, but why use static methods?
you really want to break out of that context as early as possible.
|
|
|
6 Nov 2006, 14:39
|
#5
|
☆ ♥
Join Date: Jan 2003
Posts: 3,489
|
Re: [Java] Recommendations
That's what we've been learning up until now. Rather than ask a million questions and waste your time, can you point me in any direction where I might be able to find out about static methods and also something else I've seen - private ?
__________________
R3: LegioN (came #32) || R4: BlueTuba
R5: WolfPack Order || R6: Wolfpack
R7: Fury
----------retired-------
R52-R55: Apprime
R56-R57: FaceLess
R58-60: Apprime/Ultores
|
|
|
6 Nov 2006, 15:10
|
#6
|
Insomniac
Join Date: May 2003
Posts: 3,583
|
Re: [Java] Recommendations
no need, static methods are very simple things
They are functions which can be called from a class without having to create an instance of the class, however they cannot due to this access any variables in the class.
static methods are useful only when you have a generic function which takes parameters and returns something - without having to refer to any variables or non-static methods in its containing class. otherwise they are useless.
private functions or variables are only accessible within the class itself. A function inside it is allowed to call them but a function outside of it is not.
they are exceptionally useful things when it comes to data encapsulation - forcing all access to go through a predefined accessor or mutator method for each field - it prevents them from being accessed differently by one function which may corrupt the data for others. By forcing access through specified functions you can control how the data is managed
btw, if youve spent all this time learning exclusively static methods, then your tutor sucks as they arent exploring the strength of object orientated languages - objects, and polymorphism
edit :
http://www.javaworld.com/javaworld/j...1-mrhappy.html
http://today.java.net/pub/a/today/20...taticsSQ1.html
http://java.sun.com/docs/books/tutor...classvars.html
and other pages from a google search may assist you
Last edited by Phil^; 6 Nov 2006 at 15:15.
|
|
|
6 Nov 2006, 21:53
|
#7
|
☆ ♥
Join Date: Jan 2003
Posts: 3,489
|
Re: [Java] Recommendations
thanks dude - i'm kind of getting an idea
we've been doing this basic structure (an example):
Code:
class rtv2
{
public static void main (String[] param)
{
reality2();
System.exit(0);
}
public static void reality2 ()
{
// ------------- program goes in here ------------
}
which is why static has been used - if main isn't used as a method, does that mean I have to follow the example structures in those links? they seem more confusing
thanks
__________________
R3: LegioN (came #32) || R4: BlueTuba
R5: WolfPack Order || R6: Wolfpack
R7: Fury
----------retired-------
R52-R55: Apprime
R56-R57: FaceLess
R58-60: Apprime/Ultores
Last edited by Androme; 6 Nov 2006 at 22:10.
|
|
|
7 Nov 2006, 00:00
|
#8
|
Insomniac
Join Date: May 2003
Posts: 3,583
|
Re: [Java] Recommendations
the example structures utilise object orientated programming to its fullest. The example code you have given is procedural programming, and in java its a bit of a no-no.
Ask your tutor if you will be going into object orientated programming in java, and polymorphism.
if you are not - your tutor is unbelievably crap and i suggest you learn it on your own
to get out of the static context in the example above, use :
Code:
class rtv2
{
public static void main (String[] param)
{
rtv2 program = new rtv2();
program.go();
}
public void go()
{
// this function replaces everything you would ordinarily put in main. If you need args rememebr to pass them
reality2();
}
public void reality2 ()
{
// ------------- program goes in here ------------
}
Note since you have created an object of rtv2, you can refer to it by the object name to call public functions in it
you can also create multiple objects and run that method in all of them too
|
|
|
7 Nov 2006, 11:45
|
#9
|
☆ ♥
Join Date: Jan 2003
Posts: 3,489
|
Re: [Java] Recommendations
Thanks!
Yeah, we are doing procedural programming this semester. Next semester we are doing object orientated programming.
__________________
R3: LegioN (came #32) || R4: BlueTuba
R5: WolfPack Order || R6: Wolfpack
R7: Fury
----------retired-------
R52-R55: Apprime
R56-R57: FaceLess
R58-60: Apprime/Ultores
|
|
|
7 Nov 2006, 21:53
|
#10
|
☆ ♥
Join Date: Jan 2003
Posts: 3,489
|
Re: [Java] Recommendations
I just boughgt the complete ref java 2 by herbert schildt book - quite good thanks.
Here's some coding I've done - I've set it so that it asks for the ratings of 5 films and then prints them out.
How do I also limit the values of the input - e.g. in this case, only the numbers 1 to 10 will be accepted - anything else I have to return an error message?
Also, how do I do a search in them to find the film with the highest value - in other words, find which index stores the highest value?
Code:
int score[] = new int[5];
String rating;
for(int i = 0; i<score.length; i++)
{
rating = JOptionPane.showInputDialog(null, "What is your rating for film " + i + "?");
score[i] = Integer.parseInt(rating);
}
for(int i = 0; i<score.length; i++)
{
System.out.println("Film " + i + " scored " + score[i] + " out of 10");
}
__________________
R3: LegioN (came #32) || R4: BlueTuba
R5: WolfPack Order || R6: Wolfpack
R7: Fury
----------retired-------
R52-R55: Apprime
R56-R57: FaceLess
R58-60: Apprime/Ultores
Last edited by Androme; 7 Nov 2006 at 22:08.
|
|
|
7 Nov 2006, 21:58
|
#11
|
Insomniac
Join Date: May 2003
Posts: 3,583
|
Re: [Java] Recommendations
why are you shoving a string into an integer array?
use Integer.parseInt(JOptionPane.showInputDialog(.... ));
also, theres a missing + sign between i and "?" , which is why its complaining about the bracket.
ie
score[i] = Integer.parseInt(JOptionPane.showInputDialog(null, "What is your rating for film " + Integer.toString(i) + "?"));
as for the other stuff :
You can find which is the maximum through a simple algorithm.
set the current maximum to the first entry in the array
go through the array, if the current entry is greater then the current maximum - set the current maximum to the current entry.
repeat until the array has been iterated through - and you have the highest value.
a similar one can be implemented for the minimum
for limiting the input , use an if statement. if the entry >= 1 and entry <= 10 - continue
Last edited by Phil^; 7 Nov 2006 at 22:04.
|
|
|
7 Nov 2006, 22:27
|
#12
|
☆ ♥
Join Date: Jan 2003
Posts: 3,489
|
Re: [Java] Recommendations
cheers phil
i've modified my code if you look above - what I'm confused about with yours is the toString(i) part - your passing i as a parameter? i'll read up on this in the java api - looks wierd though.
__________________
R3: LegioN (came #32) || R4: BlueTuba
R5: WolfPack Order || R6: Wolfpack
R7: Fury
----------retired-------
R52-R55: Apprime
R56-R57: FaceLess
R58-60: Apprime/Ultores
|
|
|
7 Nov 2006, 22:38
|
#13
|
Insomniac
Join Date: May 2003
Posts: 3,583
|
Re: [Java] Recommendations
the toString function turns an int into a string.
its the Integer class you need to read up on
|
|
|
7 Nov 2006, 23:10
|
#14
|
☆ ♥
Join Date: Jan 2003
Posts: 3,489
|
Re: [Java] Recommendations
cheers phil I've got it all working - one thing though, how do i record the index (pass on the value of i) - can i just define new variable index and then in the for loop in the if statement, just say index = i ? thanks
Code:
int max_score = score[0]; // start with the first value
for (int i=1; i<score.length; i++)
{
if (score[i] > max_score)
{
max_score = score[i];
}
}
__________________
R3: LegioN (came #32) || R4: BlueTuba
R5: WolfPack Order || R6: Wolfpack
R7: Fury
----------retired-------
R52-R55: Apprime
R56-R57: FaceLess
R58-60: Apprime/Ultores
|
|
|
7 Nov 2006, 23:14
|
#15
|
Insomniac
Join Date: May 2003
Posts: 3,583
|
Re: [Java] Recommendations
yes, precisely like that if you want to calculate the maximum value. if you want to store the position it was in then you need another int for max_score_index , and set that to i at the same time you update max_score
|
|
|
8 Nov 2006, 12:19
|
#16
|
☆ ♥
Join Date: Jan 2003
Posts: 3,489
|
Re: [Java] Recommendations
thanks loads phil
__________________
R3: LegioN (came #32) || R4: BlueTuba
R5: WolfPack Order || R6: Wolfpack
R7: Fury
----------retired-------
R52-R55: Apprime
R56-R57: FaceLess
R58-60: Apprime/Ultores
|
|
|
15 Nov 2006, 18:29
|
#17
|
I ♡ ☠
Join Date: Oct 2006
Posts: 834
|
Re: [Java] Recommendations
read the online documentation.
|
|
|
16 Nov 2006, 21:42
|
#18
|
I ♡ ☠
Join Date: Oct 2006
Posts: 834
|
Re: [Java] Recommendations
In light of the painful attack of my internet reputation, I shall clarify. I know C and C++ and when I went to learn Java the only thing I needed was the online tutorials that sun provide: java.sun.com/docs/books/tutorial/
It certainly covers the basics in non-too-technical language and as soon as you've managed to digest all that you can start looking at JavaBeans, Reflection and the rest which covers 'beyond'. It even makes Swing look manageable.
I don't know what you're attempted to create with Java, but I managed to create a few 2d platform games using Java's mobile phone technology (which isn't actually that bad--it's ok in fact) and a multiplayer 2d game.
Seriously, don't spend money on books when the online documentation is fantastic, the best I've seen at any rate. I looked at a friend's deital and deital (sp?) book and it was like hitting your head against a brick wall in comparison.
I still dislike Java, and the fact you have to provide so much scaffolding for it to work, in direct contrast to languages like Python, but I've never been able to knock the online documentation.
There: read the online documentation.
|
|
|
16 Nov 2006, 21:51
|
#19
|
Insomniac
Join Date: May 2003
Posts: 3,583
|
Re: [Java] Recommendations
he's just starting out in java, and it would seem programming languages in general - so books are probably best for him at present.
Im like you, im fairly good with online api references and such - but not everyone is unfortunately.
|
|
|
16 Nov 2006, 21:53
|
#20
|
Henry Kelly
Join Date: Apr 2000
Posts: 7,374
|
Re: [Java] Recommendations
The 'painful attack' was by me (hence signed), and the comment you'd posted was worthless. But good on you to come back and post a better reply.
If you don't know any other object-oriented language then there are tutorials out there to give you the basics. The Java API is indeed very complete if you know what you're looking for. The online tutorials are good, and I would certainly recommend you look through them since most of the concepts are transferrable to any other language. For instance, I learnt object-oriented programming through Java, but the concepts are the same for C++, C# and most other similar languages you would encounter.
__________________
You're now playing ketchup
|
|
|
16 Nov 2006, 22:05
|
#21
|
I ♡ ☠
Join Date: Oct 2006
Posts: 834
|
Re: [Java] Recommendations
I'm not taking about looking at the API first off (anything but), but merely looking at the tutorials. For instance this seems a satisfactory introductions to arrays: java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html
Actually, I wouldn't even recommend learning Java first off, but then I'm a **** and most of the universities seem to disagree with me. C++ can be equally as baroque (if you're adamant on choosing a OO language to learn), but starting off it seems a little clearer in my opinion.
...but I suppose it's harder to create GUIs (or use any external libraries for that matter) at the beginning which is what you want to do if you're just beginning to learn how to program.
[edit] Looking at the previous posts, Herbert Schilidt's book should be quite good. I bought his book on C ( http://www.amazon.com/exec/obidos/AS...rbschildtco-20) when I was learning it, and I found it fantastic.
|
|
|
16 Nov 2006, 22:39
|
#22
|
Avenger of Calamari
Join Date: Aug 2003
Location: Alberta, Canada
Posts: 939
|
Re: [Java] Recommendations
Sorry dude, but I hit you with one as well. Forgot to sign it though. As pab mentioned, I took it to be pretty arrogant, almost as bad as some with "Read the %*$&ing manual"
Cheers for clarifying however
|
|
|
|
All times are GMT +1. The time now is 13:03.
| |