USage of import java.util.* & using another package

When we use import java.util.*; from where does JAVA take the class that are related to util, when I did search for "util" in my machine, I got about 50 results for folders named util and also some where in a folder called "java" when I opened it it did not have the classes, that I was expecting. So I am not clear where does it get the class files from. This is not only for this but for any import commands like import java.io.*;
When we get another package or source code which was written in java and want to use it in our code where do we have keep the files ? eg. i have the java code that i m writing in c:\java then do I put all the downloaded related files in that folder and then run the code ? or i keep a folder inside java folder and then import them into my code ?
please do advice.
Thanks in advance.

When we use import java.util.*; from where does JAVA
take the class that are related to util,It means when you use a classname in your code, and that classname is neither in the same package as the class you're writing, nor imported specifically by classname, that it will search for it.
Where it searches is every folder called util whose parent folder is called java which in turn is at the root level of one of the classpath elements. That is, if classpath contains "A" and "B", and you refer to a class called "Foo", then it will look for "A/java/util/Foo.class" and "B/java/util/Foo.class".
search for "util" in my machine, I got about 50
results for folders named util and also some where in
a folder called "java" when I opened it it did not
have the classes, that I was expecting. So I am not
clear where does it get the class files from. This is
not only for this but for any import commands like
import java.io.*; All the java.* and javax.* and whatever else it part of the core API is in rt.jar, which lives inside the Java distribution. Classpath elements can be directories or jar files or zip files.

Similar Messages

  • Question on import java.util.ArrayList, etc.

    Hi,
    I was wondering what the following meant and what the differences were. When would I have to use these:
    import java.util.ArrayList;
    import java.util.Collections; <--I especially don't understand what this means
    import java.util.Comparator; <---same for this (can I consolidate these into the bottom two?)
    import java.io.*;
    import java.util.*;

    MAresJonson wrote:
    Also, what does this mean:
    return foo == f.getFoo() ? true : false;
    (more specifically...what does the "? true : false" mean and is there another way to code that?)It's called the ternary operator. For your specific example, you could just do:
    return foo == f.getFoo();But, more generally,
      return foo == f.getFoo() ? "equal" : "Not equal";means:
    if (foo == f.getFoo()) {
       return "equal";
    else {
       return "Not equal";
    }As everyone else said at the same time...

  • The import "java.util.scanner" is not vaild

    I am experiment with the java.util.scanner API after compiling the code below I received the following error:
    The import "java.util.Scanner" is not valid, since it does not name a type in a package.
    I declared a string variable should that suffice?
    import java.util.Scanner;
    public class Echo {
    public static void main (String[] args)
    String message;
    Scanner scan = new Scanner (System.in);
    System.out.println ("enter something:");
    message = scan.nextLine();
    System.out.println ("hey you entered: \"" + message + "\"");
    }

    Most IDEs let you select and installed JDK for them to use. Check out that IDE's preferences.
    Otherwise, start here and learn to do it with a simple text editor or programmer's editor, and the command line.
    http://java.sun.com/docs/books/tutorial/getStarted/cupojava/

  • Error when importing java.util.Scanner

    Agh! I'm in an introduction to computer science course, and I am writing a program as an assignment that's due tomorrow.
    I have imported java.util.Scanner before, but I've only run it on the Windows PCs in the lab, whereas I am currently on a Mac. I've updated to the latest version of Java (through the software update), and I'm running Tiger (also fully updated).
    I'm using Dr. Java to write the programs, but I tried using the very same thing in Eclipse and it didn't work. Here's my program:
    import java.util.Random;
    import java.util.Scanner;
    public class Password {
    public static void main(String[] args) {
    //create a Scanner object to read from the keyboard:
    String password;
    Scanner scanner = new Scanner(System.in);
    Random randomizer = new Random();
    System.out.println("Please enter a string containing candidate characters.");
    String input = scanner.next();
    int charLength = length(input);
    System.out.print("Random password: ");
    System.out.print(input.substring(randomizer.nextInt(charLength)));
    System.out.print(input.substring(randomizer.nextInt(charLength)));
    System.out.print(input.substring(randomizer.nextInt(charLength)));
    System.out.println(input.substring(randomizer.nextInt(charLength)));
    And, here's my errors:
    4 errors found:
    File: /Users/brianmoore/Desktop/Password.java [line: 11]
    Error: cannot resolve symbol
    symbol : class Scanner
    location: package util
    File: /Users/brianmoore/Desktop/Password.java [line: 18]
    Error: cannot resolve symbol
    symbol : class Scanner
    location: class Password
    File: /Users/brianmoore/Desktop/Password.java [line: 18]
    Error: cannot resolve symbol
    symbol : class Scanner
    location: class Password
    File: /Users/brianmoore/Desktop/Password.java [line: 22]
    Error: cannot resolve symbol
    symbol : method length (java.lang.String)
    location: class Password
    Any ideas?

    Ok. I figured it out. On the Dr. Java page, this is what helped me:
    Please verify the following:
    - Open "/Applications/Utilities/Java/J2SE 5.0/Java
    Preferences";
    make sure "J2SE 5.0" is at the top of the list under
    "Java
    Application Runtime"
    - Open DrJava; go to Edit->Preferences; make sure
    "Tools.jar
    Location", "JSR-14 Location", and "JSR-14
    Collections Path"
    are all blank
    - Open the Help->About dialog box; make sure the "DrJava
    Version" listed is 20050601-0007 or later (that is, later
    than
    June 1, 2005)
    - Go to the "System Properties" tab in the
    "About" box; make
    sure "java.version" is 1.4.2.
    Let us know what you find out if you're still having
    trouble.
    Thanks for your help!

  • When included  import java.util.* then why include import java.util.Gregori

    Hi,
    In my program I hava inported the java package like
    import java.util.*;
    import java.sql.*;
    import java.text.*;
    then for using some classes like Gregorial calender,Date etc,I have to again import
    import java.util.Date;
    import java.sql.PreparedStatement;
    import java.util.GregorianCalendar;
    As far as I know if I have import the above like
    import java.util.*; then it means I can use any classes in java.util ,but if I am not importing
    import java.util.GregorianCalendar;
    import java.util.Date;
    my program is giving error.Can somebody tell me,where my concept is wrong.
    Thanks

    import java.sql.*;
    import java.util.*;
    //import java.util.Date;  // <-- needed to avoid "the type Date is ambiguous"
    public class PackageEg {
        public static void main(String[] args) {
            Date test = new Date();
    }This code gives an error when I compile it, but if I include the
    java.util.Date import it is good. The reason is that there are two
    possible Date classes - one in java.util and one in java.sql. The
    compiler cannot figure out which one I mean.
    If I include a specific class like java.util.Date, then this one will be used
    in preference to any .* imports. (These are called "imports on demand")
    This explains why you need java.util.Date, but the other two are a
    mystery. As far as I know PreparedStatement and GregorianCalander
    are unique names within the packages you mention. Could you post
    some code that will not compile unless the specific import statements
    are there?

  • Any benefit to import java.util.Vector over import java.util.*?

    By benefit I mean does it reduce compile time or have some other beneficial side effect to import only those classes you're using in a class rather than importing the package they reside in.
    For example:
    // this?
    import java.util.Vector;
    // or this..
    import java.util.*;
    class Test
         Vector v;
    }Question is strictly academic...I'm just curious.

    I like Dr. clap's answer. Also, though you can
    consider code readability. Obviously importing a
    whole package doesn't give you an idea of what classes
    are being used. "I", personally, have only seen exact
    class imports done when learning something new. This
    is basically just for clarity, and not speed as Dr.
    Clap pointed out.That's probably a good thing to do for examples, but I can't see why you would want to know what individual classes are being used otherwise.
    From a programming standpoint if you're going to build a complex dialog you don't want 500 import statements. If you know you're going to be using lots of classes from an individual package might as well import the whole thing.

  • Cannot import java.util.concurrent.locks ... WHY?

    Why is Xcode unable to find the java.util.concurrent.locks package. The class browser knows it exists. For example the entry for the ReentrantLock class looks like this in the browser class window:
    ReentrantLock (java.util.concurrent.locks)
    Xcode knows about other java.util packages such as java.util.ResourceBundle which I have been accessed successfully in other parts of my projecgt.
    Here is a source file and the resulting compiler error:
    The source file:
    // Foo.java
    import java.util.ResourceBundle;
    import java.util.concurrent.locks;
    public class Foo { }
    The compiler error:
    compile:
    Compiling 2 source files to /Users/Terry/Desktop/JAVA/PROJECTS/Logic/bin
    /Users/Terry/Desktop/JAVA/PROJECTS/Logic/src/Foo.java:3: cannot find symbol
    symbol : class locks
    location: package java.util.concurrent
    import java.util.concurrent.locks;
    ^
    1 error
    BUILD FAILED
    Help or hints would be greatly appreciated!

    Well the reason to your problem is very simple... java.util.concurrent.locks is a package... Not a class.
    if you want to import a specific class, the class should be written at the end like you did for import java.util.ResourceBundle; but if you want to import a whole package you need to add the little star at the end :
    import java.util.concurrent.locks.*;
    Or else, you only import the class you need :
    import java.util.concurrent.locks.ReentrantLock;

  • A problem with importing java.util.concurrent

    I am rather new to Java with not that much experience. I apologize ahead though if this is the inappropriate forum to post this problem and/or this question has been answered somewhere else (I couldn't find a post on this subject).
    Some of my research has lead to using a semaphore if you wish to use the synchronized() method. I looked up that the import for that is under java.util.concurrent.Semaphore; however, thanks to netbeans for pointing this out before I compiled it, this doesn't seem to exist.
    I'm using Java version 1.6.0_03 which does seem to be the latest version. Was it simply removed or am I seriously missing something big here? Anyways, I'm at a total loss and hopefully someone can point me in the right direction.
    Thank you in advance for your help.

    jiju wrote:
    check whether import java.util.concurrent.*; is workingAwesome.
    As for netbeans, I went and double checked to see if it is reading from the most updated folder of Java and it is.
    So as I said, I am totally lost as to why it's not working. Should I just downgrade to a lower version of Java? Although it would seem kinda weird to do something like this.

  • Compile error import java.util.map$entry

    Hi,
    I am trying to compile code which imports the following package
    import java.util.Map$Entry.
    The error thrown up is : cant resolve symbol Map$Entry. Why is there a $ in the package import path and is there some configuration required to compile the file.
    I am not allowed to change the code. Does anyone have an idea on how this problem can be solved.
    Thanks and regards
    Kumar Vellal

    Btw java docs for the interface are available at:
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Map.Entry.html
    Changing the import should probably help compile the code, but without changing the import .. need to check. This is just from what i remember now. Lets see if anyone else comments on this.

  • Import java.util.*?

    Where can I place my imports? I seem to be placing them wrong :)
    <%@ page language="java" import="java.sql.*"%>
    <%!
    // define variables
    String publication;
    String classification;
    String startDate;
    String adText;
    String sqlflag;
    int adCount;
    import="java.util.*";
    import="java.text.*"
    // define database parameters
    String URL = "jdbc:oracle:thin:@server.site.com:1521:ftcs";
    String user = "user";
    String pass = "pass";
    Connection conn;
    %>

    You're doing it right first but getting it wrong later :)
    They need to be in the page directive. Use commas to separate them
    <%@ page language="java" import="java.sql.*, java.util.*, com.whatever.util.*" %>

  • Import java.util Error

    How come program wont accept import java.util ?
    I get cannot resole symbol ?? i looked in up in my java book and its spelled right . what gives ?

    there is no class named java.util .
    import java.util.ArrayList;
    import java.util.EventObject;
    or
    import java.util.*;

  • Import java.util.Enumeration;

    Hi, I test a programmer under eclipe
    I can import java.util.Enumeration;(error on Enumeration)
    and Vector connections = null;
    Enumeration enum = connections.elements();
    while (enum.hasMoreElements())
    do something
    I got error Enumeration can't not be resolve/
    why?
    and how to modify to change it?

    Hi, I test a programmer under eclipe Maybe should test the program, not the programmer ;-)

  • How to display IndexedFaceSet from .wrl file to Java 3D using cv97 package.

    Dear everyone,
    I'm trying to load a VRML file containing some IndexedFaceNode to Java3D using cv97 package written by Shatoshi Konno (http://www.cybergarage.org/vrml/cv97/cv97java/index.html).
    I use the code as below.
    However, there is nothing displaying in the window when I run this code.
    Does anyone have experience on this. Could you give me some suggestion?
    Thanks a lot!
    ======================================================
    import cv97.Constants;
    import cv97.SceneGraph;
    import cv97.j3d.SceneGraphJ3dObject;
    import cv97.node.Node;
    import cv97.node.PointLightNode;
    import java.awt.BorderLayout;
    import java.awt.Frame;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.media.j3d.AmbientLight;
    import javax.media.j3d.Canvas3D;
    public class ViewerJ3D extends Frame implements Constants {
       private SceneGraph   mSceneGraph;
       private SceneGraphJ3dObject mSceneGraphObject;
       public ViewerJ3D(){
          super("VRML Simple Viewer");
          mSceneGraph = new SceneGraph(SceneGraph.NORMAL_GENERATION);
          mSceneGraph.load("model\\model.wrl");
          setLayout(new BorderLayout());
          Canvas3D c = new Canvas3D(null);
          add("Center", c);
          mSceneGraphObject = new SceneGraphJ3dObject(c, mSceneGraph);
          mSceneGraph.setObject(mSceneGraphObject);
          setSize(400,400);
          show();
          addWindowListener(new killAdapter());
          setVisible(true);
       static class killAdapter extends WindowAdapter {
           public void windowClosing(WindowEvent event) {
              System.exit(0);
      public static void main(String args[])
          ViewerJ3D view = new ViewerJ3D();
    }=======================================================

    Dear everyone,
    I'm trying to load a VRML file containing some IndexedFaceNode to Java3D using cv97 package written by Shatoshi Konno (http://www.cybergarage.org/vrml/cv97/cv97java/index.html).
    I use the code as below.
    However, there is nothing displaying in the window when I run this code.
    Does anyone have experience on this. Could you give me some suggestion?
    Thanks a lot!
    ======================================================
    import cv97.Constants;
    import cv97.SceneGraph;
    import cv97.j3d.SceneGraphJ3dObject;
    import cv97.node.Node;
    import cv97.node.PointLightNode;
    import java.awt.BorderLayout;
    import java.awt.Frame;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.media.j3d.AmbientLight;
    import javax.media.j3d.Canvas3D;
    public class ViewerJ3D extends Frame implements Constants {
       private SceneGraph   mSceneGraph;
       private SceneGraphJ3dObject mSceneGraphObject;
       public ViewerJ3D(){
          super("VRML Simple Viewer");
          mSceneGraph = new SceneGraph(SceneGraph.NORMAL_GENERATION);
          mSceneGraph.load("model\\model.wrl");
          setLayout(new BorderLayout());
          Canvas3D c = new Canvas3D(null);
          add("Center", c);
          mSceneGraphObject = new SceneGraphJ3dObject(c, mSceneGraph);
          mSceneGraph.setObject(mSceneGraphObject);
          setSize(400,400);
          show();
          addWindowListener(new killAdapter());
          setVisible(true);
       static class killAdapter extends WindowAdapter {
           public void windowClosing(WindowEvent event) {
              System.exit(0);
      public static void main(String args[])
          ViewerJ3D view = new ViewerJ3D();
    }=======================================================

  • Where to find .jar files so I can implement import java.util.logging

    I'm trying to figure out how to take an application built for Websphere and port it to WebLogic. I've come across this blog entry http://blogs.sun.com/fkieviet/entry/using_java.util.logging_in_bea_weblogic and would like to try creating and using the startup class.
    I have not been able to find the correct jar files.
    import weblogic.common.T3ServicesDef;
    import weblogic.common.T3StartupDef;
    import weblogic.logging.LoggingHelper;
    In reading the documentation on using the NonCatalogLogger APIs at http://download.oracle.com/docs/cd/E12840_01/wls/docs103/i18n/writing.html I also see some code calling for the following imports
    import weblogic.jndi.Environment;
    import weblogic.logging.NonCatalogLogger;
    1. Does anyone know where I can grab these?
    2. There must be a strategy for finding these .jars that people use. If so, what is it?

    I thought I understood you, but the more I look at what you've set here, I'll just be honest and admit that the I don't know what you are saying here:
    'You should be able to add the "weblogic.jar" in the WebLogic distribution to your classpath.' - What doe this mean?
    1. Go to my xxxWeb app Dynamic Web Project and right-click and select Build Path / Configure Build Bath / Libraries - Select Add external JARS and navigate to the weblogic.jar
    2. Go to my xxxWeb app Dynamic Web Project and right-click and select Build Path / Configure Build Bath / Libraries - Select Add Library and try to go from there?
    3. Go to my xxxWeb app Dynamic Web Project and right-click and select Build Path / Configure Build Bath / Libraries - Select Add Variable and try to go from there?
    4. Go to my xxxWeb app Dynamic Web Project and right-click and select Build Path / Configure Build Bath and do something else?
    5. Something else?
    Also, I don't know what you mean here:
    'You don't need to (and you shouldn't) copy that jar file, just have it in your compilation classpath. It will be present automatically at runtime.'
    Sorry for being so simple here but I've been trouble shooting why I can't follow what look like pretty simple steps to implement over-riding the ApplicationLifecycleListener Class to use existing java.util.logging.Logger code by adding the following to the the weblogic-application.xml:
    <wls:listener>
         <wls:listener-class>com.qualcomm.weblogic.log.listener.UtilLogWrapper</wls:listener-class>
    </wls:listener>
    And including as a referenced jar file, a simple POJO class instance of com.qualcomm.weblogic.log.listener.UtilLogWrapper.
    My resrouces for this are:
    1. http://blogs.sun.com/fkieviet/entry/using_java.util.logging_in_bea_weblogic.
    2. http://www.oracle.com/technology/pub/articles/drolet-ant.html.
    Maybe my weblogic.jar is at the root of the problem.
    I hope you can 'dumb this down' for me with a simple explanation of steps to do what you outlined above.

  • Implementing export/import java utility

    Hi all,
    I am not sure I hit the correct forum but I'll give it a try.
    I need to write java utility that access table in one db, select some rows and copy them to a similar table in secon db - as either new rows or update to existing rows (if such rows exist).
    I thought I might use the OracleCachedRowSet to get data from one DB and to write data from another.
    Basically the code looks like....:
    Connection connSrc = null;
    ResultSet rsSrc;
    OracleCachedRowSet crs;
    try
    Class.forName("jdbc:oracle:thin:@myHOST:1521:DBNAME");
    connSrc = DriverManager.getConnection(srcDriver, USER, PWD);
    stmtSrc = connSrc.createStatement();
    rsSrc = stmtSrc.executeQuery("SELECT * FROM MYTBL");
    crs = new OracleCachedRowSet();
    crs.populate(rsSrc);
    crs.setUrl("jdbc:oracle:thin:@myHOST2:1523:DBNAME2");
    crs.setUsername("USER2");
    crs.setPassword("PWD2");
    crs.setCommand("SELECT * FROM " + RULETBL);
    crs.acceptChanges();
    The second table was empty but it did not get populated with the rows from first DB,
    I thought this might have to do with the SyncProvider issue that needs to implement the GRADE_NONE but I don't know if this is indeed the problem and where to get such sync provider implementation.
    I'll be glad to get any assistance.
    Regards,
    Avi

    Hi ,
    Many thanks for helping here.
    I thought I'd get suggestions like that...:-) It is dectated that I'll do this task using Java code. I can't even use system call to EXP/IMP utilities as anyhow I need to analyze all rows that matches the result of the SELECT command in order to access some specific information on specific column. Although I do know some column names (for that specific need) - I don't want to keep the knowledge of the row columns - as the table shema might be altered localy by our customers (usually additional columns) or from version to version of the software that usually deals with it.
    As conclusion of the above I need to use JDBC or something similar (Hibernate, JDO etc.).
    Regards,
    Avi

Maybe you are looking for

  • Error in transaction KPF6

    Hi All, I am facing an issue with transaction KPF6. In a particular scenario (with correct data) it is showing problem of "Too many elements in the overview screen". Though this particular scenrio works correctly if I try in some other system say tes

  • Data Services for CairgnormStore sample

    I am trying to run CairngormStore for Flex 2 end-to-end. It looks like the only deployment/configuration problem left is the configuration of Data Services. What is already done: - Flex 2 SDK is installed - Flex 2 builder is up and running - Flex 2 D

  • Why i cant use my app store account,tell me my visa error?

    Im facing problem when trying to buy app from my app store the system tell me that my visa are used in another account but i checked my bank nothing wrong!!!

  • Mail disappears/re-appears with exchange imap?

    first off the specs and versions: mbp running os 10.6.7 mail version 4.5 (1084) i have been using mail.app for my email for over a year now, and have had this issue all along.  i have my fetch timer set to one minute, and what happens is that i will

  • Excel to XML for spry

    O.k. i am a designer and i can see the benefit of spry big time in my work flow. BIG TIME. But i have a client site i am working on that has a bunch of data but its all in excel files. Right now to make useful web pages out of it i am using web merge