Register FAQ Calendar Search Today's Posts Mark Forums Read

Go Back   Java Programming Forums > Java Programming > New to Java

Reply
 
LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 03-11-2008, 08:42 PM
Junior Member
 
Join Date: Nov 2008
Posts: 11
Fendaril is on a distinguished road
Default New to Java/struggling with arrays

I dont want to make this a lengthy post so I just started to learn JAVA a few days ago so that I could have a better understanding of programming when I get out of highschool.

I was reading up on the JAVA tutorials when I neared the end of the array section. I understand everything else except at the very end when arrays are copied.

Here is the code from the tutorial

Java Code:
 
class ArrayCopyDemo {
public static void main(String[] args) {
char[] copyFrom = { 'd', 'e', 'c', 'a', 'f', 'f', 'e',
             'i', 'n', 'a', 't', 'e', 'd' };
char[] copyTo = new char[7];
 
System.arraycopy(copyFrom, 2, copyTo, 0, 7);
System.out.println(new String(copyTo));
}
}
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).
Reply With Quote
  #2 (permalink)  
Old 03-11-2008, 09:50 PM
JavaPF's Avatar
Java Programmer
 
Join Date: May 2008
Location: Deep inside the Eclipse IDE
Posts: 172
JavaPF will become famous soon enoughJavaPF will become famous soon enough
Default Re: New to Java/struggling with arrays

Hello Fendaril,

Welcome to the Java Programming Forums

copyFrom and copyTo are actually just variable names. These are unique names you declare to your variables in order to identify them later on.

In this case you have 2 char variables called copyFrom and CopyTo but you could easily have something like

Java Code:
String myName = "John";
There you have created a String variable called myName containing the String 'John'

The code:

Java Code:
char[] copyTo = new char[7];
Declares an char variable array which will hold 7 characters.

The System.arraycopy basically prints out the array data from position 2 through to 7.

These char array variables could be called anything you want. They are not actual java code. I hope you understand what I mean..
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 12:42 AM
Junior Member
 
Join Date: Nov 2008
Posts: 11
Fendaril is on a distinguished road
Default Re: New to Java/struggling with arrays

Thanks for your help JAVApf. Do you know how I can increase my code time intuitiveness. I practice alot but my mind forgets alot and I cant structure code correctly all the time. thanks in advance.
Reply With Quote
  #4 (permalink)  
Old 04-11-2008, 12:44 PM
JavaPF's Avatar
Java Programmer
 
Join Date: May 2008
Location: Deep inside the Eclipse IDE
Posts: 172
JavaPF will become famous soon enoughJavaPF will become famous soon enough
Default 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.

http://www.javaprogrammingforums.com...-new-post.html

Remember, google is your friend. You will find nearly all your answers there and posting in forums like this one will also help you on your way
Reply With Quote
  #5 (permalink)  
Old 04-11-2008, 02:23 PM
Junior Member
 
Join Date: Nov 2008
Posts: 11
Fendaril is on a distinguished road
Red face 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!!!!!

I can even create arrays with it!!!

What is the catch. Will is affect the speed of my program by alot?

Last edited by Fendaril; 04-11-2008 at 02:34 PM.
Reply With Quote
  #6 (permalink)  
Old 04-11-2008, 03:14 PM
JavaPF's Avatar
Java Programmer
 
Join Date: May 2008
Location: Deep inside the Eclipse IDE
Posts: 172
JavaPF will become famous soon enoughJavaPF will become famous soon enough
Default Re: New to Java/struggling with arrays

I'm glad that ebook has helped you. There is lots of useful information in there!

Check this link out and read about what an Object is.

What Is an Object? (The Java™ Tutorials > Learning the Java Language > Object-Oriented Programming Concepts)

This is the very fundamentals of object oriented programming.

Welcome to the world of Java
Reply With Quote
  #7 (permalink)  
Old 04-11-2008, 11:54 PM
Junior Member
 
Join Date: Nov 2008
Posts: 11
Fendaril is on a distinguished road
Default Re: New to Java/struggling with arrays

ah you seemed to have misread me.

I meant this:

object test= 1234;(Is this more efficient then declaring an int?)
Reply With Quote
  #8 (permalink)  
Old 05-11-2008, 12:16 AM
JavaPF's Avatar
Java Programmer
 
Join Date: May 2008
Location: Deep inside the Eclipse IDE
Posts: 172
JavaPF will become famous soon enoughJavaPF will become famous soon enough
Default Re: New to Java/struggling with arrays

Quote:
What is the catch. Will is affect the speed of my program by alot?
Java is powerful. You would need some really heavy code to slow down your program by a noticable amount. You do not need to worry too much.

Quote:
Originally Posted by Fendaril View Post

I meant this:

object test= 1234;(Is this more efficient then declaring an int?)
You must use the correct variable for whatever type of data you are trying to hold. String, int, char, byte, double, etc.

This makes it easy to identify exactly what you are doing and makes for good programming.
Reply With Quote
  #9 (permalink)  
Old 05-11-2008, 03:07 PM
Junior Member
 
Join Date: Nov 2008
Posts: 11
Fendaril is on a distinguished road
Default Re: New to Java/struggling with arrays

Thanks. Now one more question.SOrry for all of them. What are good places to do excercises?
Reply With Quote
  #10 (permalink)  
Old 05-11-2008, 07:54 PM
JavaPF's Avatar
Java Programmer
 
Join Date: May 2008
Location: Deep inside the Eclipse IDE
Posts: 172
JavaPF will become famous soon enoughJavaPF will become famous soon enough
Default Re: New to Java/struggling with arrays

Quote:
Originally Posted by Fendaril View Post
Thanks. Now one more question.SOrry for all of them. What are good places to do excercises?
Its no problem Fendaril... Thats what we are here for

How do you mean by exercises? Are you looking for inspiration in what to code or are you looking for step by step instructions you can follow?

If your looking for a few simple ideas then im sure I can chuck a few your way.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.javaprogrammingforums.com/new-java/150-new-java-struggling-arrays.html
Posted By For Type Date
Java Programming Forums - JavaProgrammingForums.com This thread Refback 04-11-2008 03:04 PM

Custom Search
100 most searched terms
Search Cloud
"bad endpoint type" com.sun.xml.internal.messaging.saaj.soapexceptionimpl com.sun.xml.internal.messaging.saaj.soapexceptionimpl: bad endpoint type com.sun.xml.internal.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception com.sun.xml.internal.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: message send failed com.sun.xml.internal.messaging.saaj.soapexceptionimpl: message send failed com.sun.xml.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception com.sun.xml.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception: com.sun.xml.messaging.saaj.soapexceptionimpl: message send failed convert arraylist to map date_format_now eclipse shortcut keys ejb3 quartz java convert double to binary java forum java forums java jtextarea bold java jtextarea color java jtextarea font java jtextarea font size java programmer forum java programmers forum java programming forum java programming forums java read last line java read last line of file java sendkeys java.security.privilegedactionexception java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: bad response java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: message send failed java.security.privilegedactionexception: com.sun.xml.messaging.saaj.soapexceptionimpl: message send failed javapf javaprogrammingforums jtextarea bold jtextarea font jtextarea font color jtextarea font size programing forums programming forums reset jcombobox saaj0008 saaj0008: bad response; bad request saaj0008: bad response; not found severe: saaj0008 severe: saaj0008: bad response; bad request severe: saaj0008: bad response; not found soap java.security.privilegedactionexception soapexceptionimpl: bad endpoint type textpad java

All times are GMT. The time now is 12:51 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.