944,132 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 1442
  • Java RSS
Feb 13th, 2007
0

more syntax questions

Expand Post »
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.
Similar Threads
Reputation Points: 13
Solved Threads: 4
Light Poster
kimbokasteniv is offline Offline
49 posts
since Nov 2006
Feb 14th, 2007
1

Re: more syntax questions

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
Reputation Points: 20
Solved Threads: 6
Junior Poster in Training
Cudmore is offline Offline
74 posts
since Nov 2005
Feb 14th, 2007
0

Re: more syntax questions

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).
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Feb 14th, 2007
0

Re: more syntax questions

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.
Reputation Points: 13
Solved Threads: 4
Light Poster
kimbokasteniv is offline Offline
49 posts
since Nov 2006
Feb 14th, 2007
0

Re: more syntax questions

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: How to align components
Next Thread in Java Forum Timeline: Javac





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC