wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes regex import Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "regex import" Watch "regex import" New topic
Author

regex import

Lovleen Gupta
Ranch Hand

Joined: Feb 26, 2007
Posts: 63
Hi,
In import statements - if I write import java.util.*, it doesn't let me use Pattern, Matcher classes in the program.
However, if I use import java.util.regex.*, it let me do it..

Now, the question is -- Is java.util.regex.* not a subset of java.util.* ?
So, if I am using only util.* , it should let me use the regex classes also..

Please explain.

Thanks.
Antonio Trapero
Greenhorn

Joined: Mar 24, 2007
Posts: 11
With import sentence, you will bring only one package at time or one class, not subpackages.

import java.util.*; only brings this package, no subpackages like regex.
import java.util.regex.*; only brings package regex.
import java.util.regex.Pattern; only brings Pattern class.
Lovleen Gupta
Ranch Hand

Joined: Feb 26, 2007
Posts: 63
Right..!
But regex is a part if util.
So, when we import regex, util will also come.
No?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18141
    
  39

Originally posted by Lovleen Gupta:
Right..!
But regex is a part if util.
So, when we import regex, util will also come.
No?


As Antonio mentioned. No, the import statement only specify classes. Hence...

import java.util.*;

means import all the *classes* in the java.util package. Although regex is in the util directory (as an implementation detail), it is not a class, hence, not imported.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Lovleen Gupta
Ranch Hand

Joined: Feb 26, 2007
Posts: 63
All right..!! Thanks Henry & Antonio.
I am clear on it now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regex import
 
Similar Threads
jar files
Collection(regarding order elements)
Visual J++ beginners question
doubt in page 774 and 775 of K& B book
replacing content in a file