The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

I get the first part when "CopyFrom" is declared with a bunch of characters but I was thrown off of the declaration of 'CopyTo'. please help me out. I tried searching on google but It just turns up with the syntax(which i dont get).

Re: New to Java/struggling with arrays

Hey Fendaril,

Its my pleasure.

I know the feeling.. Its quite daunting when first starting to write Java code. It seems like there is soooo much to learn.

What I would suggest is that you start your own code library. Create a folder somewhere on your computer and create .txt files containing different code. For example, I would have one containing code for reading files, reading input from the console, an array example etc. Name each file approperatly and then when you are writing new code you can check your library as a reference.

The trick really is to practice. The more real world applications you can write the better. It takes time but eventually things start to click into place and it becomes alot easier.

You will never stop learning. Ive been writing Java code for quite a few years now but im still learning every time I code.

There is an official Java exam called the SCJP "Sun Certified Java Programmer" Take a look at some of the ebooks we have on this site. Because they are designed to help you pass the exam, they cover every aspect of Java and will help you to understand areas you are unsure about.

Re: New to Java/struggling with arrays

That e-book on JAVA really cleared up Arrays for me. To tell you the truth I thought that all arrays had to be named "anArrayOfString;". I had no clue that I could name them what I want and initialize them on the same line. Goes to show how easy it is to misread JAVA sun's tutorials.

I found this cool datatype called "Object" that can hold anything!!!!!

Relating to your other question yes I understand the basic loops and array concepts now. The problem is I looked at the candidate program that was very recently posted here and saw very clever use of loops and arrays. That is what I am aiming toward.

I think this concept first came into Java in version 4/5. They both work the same, its just down to personal preference to which one you use.

for(String item: names){
System.out.println("This name in the array is " + item);
}

The basic for loop was extended in Java 5 to make iteration over arrays and other collections more convenient. This newer for statement is called the enhanced for or for-each loop. Again its down to personal preference which one you use but keeping with the times makes it more readable.

Re: New to Java/struggling with arrays

Yeah the reason it looked hard was because they used a different method of array.

As far as im aware, there is no difference in performance between the for and for-each loop. But if you want to print the content of an array I would get used to learning the for-each loop as its more convenient and no doubt you will encounter it alot in the future.

You need to keep reading even if you don't understand. Each time it will gradually sink in more and more. Try to write code that will help you to understand. For example, try to pass a variable between 2 different classes..

I remember it took me a while to get my head around OOP too. The key really is just to keep writing code.

Re: New to Java/struggling with arrays

I havent done anything related to java in 2 days. I got so stressed out and just played games. I feel so incomplete so I am going to do something worthwhile.

Ok so I think I came upon a good project to start out with. I found out how to pass variables through different methods.

What if I passed variables through methods like 'addition(i,j)' while taking input from the user. It does require me to jump a head a little bit but a calculator is something that is very easy to make. I could use the beautiful if-else ladder. The process I have to take to make it is a bit harder then in c++. Not comparing or anything.