Question:
Completely confused on Java, NO IDEA on what things mean and what to do!?
johnson
2009-05-01 05:11:27 UTC
I have been trying to learn Java for 5 months now and yet I am not able to figure things out and what they mean.. like what is a while loop? what the heck is an array? how do you make them? what are they used for?

Every time my teacher gives me a program to make, I sit there like dumb idiots who don't have the slightest idea of how to start. I really am frustrated by myself.. i just don't know what to do! everyone can do java programs in my class but I can't do anything...

could anyone please give me some help on that? perhaps providing a link where you can learn java from scratch... please reply
Five answers:
Germann A
2009-05-01 05:31:29 UTC
Well, if after 5 months of learning you still can not understand loops and arrays I am afraid it may be wrong subject for you...



NOT everybody has to be (good) programmers, some people have it, some don't...
Ben S
2009-05-01 13:16:38 UTC
You need to tell this to your teacher and to go at one pace at a time. I'll answer your questions though:



* Arrays are to group more than one value into a variable. Variable's are simply a reference to a value. Let's say you wanted to output a story multiple times, instead of "pasting" the story multiple times you can store the story in a variable and you'll simply only need to call the variable and it'll output the story:



story = "My Long Story here"

output(story) << this will output the sentence "My Long Story"

output(story)

output(story) << I can do this multiple times instead of having to paste the long story multiple times.



On with that, arrays are a way of storing multiple values in a variable.



array = new String[10] << we tell Java we want to make an a variable that has 10 values (arrays). So now we can do this:



array[0] = "Hi"

array[1] = "Hello"

array[2] = "Hey"

array[3] = "Hola!"

array[4] = "Hallo"

array[5] = "Bye"

array[6] = "Cya"

array[7] = "Goodbye"

array[8] = "Byebye"

array[9] = "Hiiiii"



Now we did tell Java we wanted 10 array values, and yes we used these 10 array values...but array value 1 starts at index 0. So we told Java we wanted array = new String[10] (10 array values in the variable array) but the first array value starts at 0, so array value 9 is in human terms value 10. Just accept the fact this is what is what, as there's no other reason why but that's how computers work.



Why would we want to use arrays? Let's say we wanted to use a different hello and goodbye greeting everyday, instead of needing 10 variables to hold each greeting, we just store them in arrays and we call them by there array index number, which like I said starts at 0. So, we can call the greeting "Hi" with:



array[0]



and "Hiiiii" with:



array[9] ... what we did above was simply assign the array values to greetings. Now we can use these greetings like above.



While loops: lets say you have a list of all your friends, and you had them in a document and you really couldn't be bothered to copy and paste them to output them on a Java application. Simple, while loops come to play. This is not a proper example, but its just to explain why you'd use while loops. Let's do a random example:



The good part in learning is testing, make a Java file and put this code in:



class Test {

public static void main(String[] args) {

while(int i = 1) {

System.out.println(1);

}

}

}



...save as test.java and compile the application (javac test.app then java test) - it'll continually print 1 on the screen, and it won't stop...since i is always equal to 1. This is just a quick example of while loops.
2009-05-01 12:21:10 UTC
You're trying to use a tool for purposes you don't understand. Learn programming before you learn languages to do it in. Start with http://www-old.oberon.ethz.ch/WirthPubl/AD.pdf It's free, and Wirth is about the best programming teacher who ever lived. (If your school doesn't teach programming BEFORE it teaches programming languages, the dumb idiots are the ones who designed the course.) You can't learn how to write a while loop in Java before you learn what a while loop is and why you use one.
Andrew
2009-05-01 12:20:15 UTC
I recommend either talking to your teacher and explaining to her that you have no idea how to start. Or, what I did with beginning flash is, I bought a book for $20 at Barnes and Noble and it really is very helpful! Get the "For Dummies" series because those tend to be more fun and they are for dummies so it starts you off in the beginning where you are. Good luck and programming can be a beach sometimes but when you make your first game its fun =D.
no1home2day
2009-05-01 12:16:19 UTC
Perhaps you should start with something a little easier than Java.



I would recommend learning BASIC (well, actually, it's Visual BASIC).



Good luck, and happy programming.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...