more syntax questions

Thread Solved
Reply

Join Date: Nov 2006
Posts: 23
Reputation: kimbokasteniv is an unknown quantity at this point 
Solved Threads: 0
kimbokasteniv kimbokasteniv is offline Offline
Newbie Poster

more syntax questions

 
0
  #1
Feb 13th, 2007
A friend of mine and I are taking an external computer science test. While studying the review it has become apparent that some of the syntax presented is quite unfamiliar.
Here are a few examples:

Stack<Integer> s = new Stack<Integer>();
For this line of code what exactly is the purpose of "<Integer>"?
Does this make it so Stack only returns objects of type Integer?

A question on the review:
"Which of these regular expressions matches both "aggie" and "longhorn". but not "sooner"?
a. [als].*[enr]
b. .*g.*
c. .....(orn)+
d. [^sooner]

The answer sheet says the answer is b. However, I can only make assumptions as to why, and I would like to know if the other answers are valid in syntax and what exactly the symbols mean. What would be helpful are keywords that I could use to perform a search that returns valid results.

Finally, how is a colon to be used with a for loop.
For example:
for(int a : array)
{
if(a>max) max = a;
}


It appears as if a will take on various values from array. But, I believe I have seen the colon used in a for loop where the realtionship didn't appear as obvious.
What possibilities are there for using a colon in a loop? Is there a name for this?

That seems to sum my questions up. I don't expect explanations of these things (although that would be nice). But I would particularly appreciate it, if anyone was able to give names to these items so I could find more information with that.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 74
Reputation: Cudmore is an unknown quantity at this point 
Solved Threads: 5
Cudmore's Avatar
Cudmore Cudmore is offline Offline
Junior Poster in Training

Re: more syntax questions

 
1
  #2
Feb 14th, 2007
Hmmm. I can't be super helpful before I fall asleep tonight, but..

First thing is working with Generics

Regular expressions? I'm not very good with those.. But you can find tutorials about how to pick them apart / assemble them.

Third thing, the for loop, is called a for-each loop, I think. Basically, yes, the loop moves through each value in the array like with an iterator.

for(int a : array) { ... } could be re-written:
for (int i = 0; i < array.length; i++) { int a = array[i]; ... }

Or, it could be written even more simply.. But I won't go there tonight.
Last edited by Cudmore; Feb 14th, 2007 at 12:25 am. Reason: Adding links
synchronized (theWorld) { System.out.println ("It's all mine..."); }
How many people have code in their Sigs?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: more syntax questions

 
0
  #3
Feb 14th, 2007
You really need to read a modern beginner's tutorial on Java and an introductory text on regular expressions if you can't answer those questions.
They're so basic any ultimate beginner's text should explain them.

By indicating you don't know what it is, you indicate you lack even basic knowledge, which just a few quick answers here won't provide (you'll just get stuck on the next question, and have to ask again, while doing some study of your own will give you the entire picture).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 23
Reputation: kimbokasteniv is an unknown quantity at this point 
Solved Threads: 0
kimbokasteniv kimbokasteniv is offline Offline
Newbie Poster

Re: more syntax questions

 
0
  #4
Feb 14th, 2007
Thanks for the reply cudmore, I should be able to find the information I need with the links you provided.

Jwenting, after searching through the index of the current book I'm using: "Fundamentals of Java" by Lambert and Osborne. It appears as if Generics, regular expressions, and for-each loops have no mention. So I assume my book is the basics of begginers information on Java. But thanks for your reply, I will look into more recently published books.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: more syntax questions

 
0
  #5
Feb 14th, 2007
Your book is outdated, period.
Those features were introduced into the language several years ago. If you don't use current reference literature, expect to get out of date information.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC