Why do we import a class

Why do we import the class TestFile and not call the class instead like in the code given below
package test;
import testing.TestFile;
import java.util.StringTokenizer;

"import" basically just defines aliases for class names. It lets you specify just the class name, without the full path. It makes the code easier to read.
You don't really call classes at all in Java. You call methods. You can do that later in the code.

Similar Messages

  • Import a class cannot take effect until the restart of wls6.1,why?

    Hi all,
              I am using Weblogic6.1,I knew that JSP,Servlet,EJB can be auto depolyed
              without restart weblogic,but when I
              import a class written by myself in JSP or Servlet£¬the modification of this
              class cannot take effect until
              the restart of weblogic server¡£Why? How can I solve it£¿
              thanks in advance!
              

    Check that your classpath is not set up to this class when you start the
              server and check the ProductionDeploymentMode to false in the starting
              parameters!
              Hope it helps.
              Pat
              "jxc" <[email protected]> wrote in message
              news:3bef34c3$[email protected]..
              > Hi all,
              > I am using Weblogic6.1,I knew that JSP,Servlet,EJB can be auto
              depolyed
              > without restart weblogic,but when I
              > import a class written by myself in JSP or Servlet£¬the modification of
              this
              > class cannot take effect until
              > the restart of weblogic server¡£Why? How can I solve it£¿
              >
              > thanks in advance!
              >
              >
              >
              >
              >
              

  • Problems importing a class with inner class

    Why can't I import a class so that I can use an (inner) static member class without naming the enclosing class. Put simply, I have:
    file C:\MyJava\Test\A:
    public class A {
      public static class B { }
    }file C:\MyJava\Test\C
    import A.*;
    public class C { }When I try to compile C (javac -classpath C:\MyJava\Test;. C.java) it fails with C.java:1: package A does not exist

    Class A must be in a package if you wish to import it. If you want to use the inner class, just import somepackage.A. You could then refer to A.B...
    HTH :o)

  • Classpath problems when importing my classes

    I'm using a tutorial with sample programs dealing with bank accounts.
    I get this error:
    InterestBearingAccount.java [9:1] '.' expected
    import Account;
    ^
    1 error
    Errors compiling InterestBearingAccount.
    The Account class already exists in the current directory. I've tried everything as far as setting the classpath variable (nothing, just a period, period & slash, the actual complete path for the current directory, nothing works!!!!!). I also tried using -classpath (.) and the end of my javac command and that seemed to not work at all.
    The Java Coffee Break tutorial have some already compiled (*.class) files and they run fine. My *.java files are identical. In fact, I cut and pasted them so I know it's not a typo.
    My path is set to include the jdk1.4.0\bin directory and I've only begun to have problems now that I need to import existing classes into the programs.
    I should mention that I get the same error using Forte environment or doing it at the command prompt window. Please help.

    Thanks ATMGUY. I commented out the import statements in both InterestBearingAccount and AccountDemo and it worked fine. I guess the author of that tutorial was obviously not working with jdk 1.4.
    As far as using packages, com.kusek.bank would make a good package name then??
    The statement:
    package com.kusek.bank; OR a shorter version package kusek.bank;
    should be added to all three classes and no import statements would then be necessary, right??
    I just remember reading that it should be something unique as a good habit to get into.
    I'm trying to learn enough to make a useful GUI program for a special project so I probably should be using packages anyway when I get to that point.
    My programming backround is limited to procredural languages Basic, QBasic, Pascal, and Fortran and I find myself still wanting to think in those terms. I have read several web sites and worked through some basic examples but I still have much to learn. I once I can grasp how to write OOP style it would be nice to look at code for a somewhat detailed application (like a store checkout app) and have every line explained as to why it's there. I can see where it makes sense to have your GUI classes predefined (Swing), File I/O, serial port communications, and even things like this InterestBearingAccount example that extends from the Account class utilizing its basic attributes but overriding the constructors for the additional parameters (interest calculation) that are passed. How to take a common problem and go about creating a solution is what I need to see being done to help me.
    My telemetry project uses VHF radios with packet radio modems to monitor two diesel engines and turn one off if the other turns off. The modems have built in A/D data gathering and can also output control signals, they just need to be told what to do. I can manually use a Windows Hyperterminal session and type in "connect Engine1" and use commands to determine the A/D inputs "analog". The modems have built in end-to-end acknowledgement so the only think I need is an application than can be setup to run in the Startup folder to handle this. It would use a timer class to "poll" engine1 every 5-10 minutes and if it has stopped (based on the response of the "analog" command) I would "disconnect" from engine1 and "connect" to engine2 and send a "ctrl B off" or something similar. The standard responses from the modem should allow me just to send and recieve STRING data to and from the serial port and parse them as needed. I need at least this much but it shouldn't be too much harder to develop a way to reset the system(reverse of this) when that is required. I could also read a water pressure value at one of the locations and display that on the screen along with the current status of the engines (using values obtained from the "analog" command on the modems).
    The hardest part of OOP programming seems to be knowing what classes are already out there and knowing how to find them or apply them. I hope Swing has classes that provide for displaying values on the Windows taskbar (my motherboard monitor freeware displays temperature readings down on the taskbar). I appreciate all the help given here. It's almost like having a private tutor.
    randy

  • What is actually happenning when we are importing a class of some other pac

    Sirs,
    I have a doubt which is very basic to java,
    I want to import a class say "HashMap" to my class.
    If i put import "java.util.HashMap" or "import java.util.*;"
    Which will be better ?
    If i put "import java.util.*; " will it affect the performance?
    What is actually happenning when we are importing a class of some other package to our class
    Your help solicited,
    Sudheesh K S

    Many of your questions of this nature can be quickly answered by a search of prior posts to the forums, like this:
    http://forum.java.sun.com/thread.jspa?forumID=54&threadID=631979
    And why do you tend to post boldened text? It's harder to read.

  • Importing unpackaged classes

    Hi,
    Here is a simplified example of what I'm trying to do. From a packaged class, I want to instantiate an object which is of type of an unpackaged class.
    package foo.bar
    public class ClassA {
    public ClassA() {
    public static void main()
    ClassB b = new ClassB();
    public class ClassB {
    public ClassB() {
    When trying to compile .. (where ClassB.java is in the directory C:\ClassB)
    C:\foo\bar> javac -classpath C:\ClassB ClassA.java
    I get the following compilation error:
    ClassA.java:5: cannot resolve symbol
    symbol : class ClassB
    location: class ClassA
    ClassB b = new ClassB();
    ^
    ClassA.java:5: cannot resolve symbol
    symbol : class ClassB
    location: class ClassA
    ClassB b = new ClassB();
    ^
    2 errors
    I see no reason why the above example should fail, or am I doing something incredibly stupid? Anyone have an ideas?
    Cheers
    Andy

    If you are using J2SDK1.4, you can not use a class from an unnamed package in a class in a named package. In 1.3, you can import the class and it will work (assuming it is in the Classpath). Your only choice is to package the class or use 1.3 - I'm not sure what earlier versions support.

  • Importing Java Classes for Bussiness Logic in Forms6i

    I have created a Java Class with some bussiness logic in it and i m able to impotr it in Forms 6i BUT when it converts my java method into program unit it automatically changes the name of the method with some code ..like method name is "increment" it will make it as "increment_3137" and also one parameter of Ora_java.object type will be added ....WHY is THAT ???and how to work for hat ...even when i m executing the method with the parameter it gives some Exception that Non-Oracle Exception ...and my class individually runs perfectly fine ...CAN U HELP ME ASAP ...Please as its urgent
    Thanx..

    Once you have imported java class files on forms throgh java import class option..
    it creates a pl/sql for the java class that you have imported.
    names for the procedures are assigned by machine code, so dont worry about it..
    for eg. if the name of a method in java class is Increment and after loading java class file the name of ur pl/sql is increment_1254.
    when u call increment_1254 and pass parameter to the procedure ur class incerement will be called and desired operation will be performed.
    ora_java.object is the objec that will be used to access the the class file.
    as java is object oriented it requires a object to execute method of class.
    so u have to initialize the object..
    e.g. increment_1234 (ora_java.object,a,b) is ur procedure
    to call this procedure do the following
    declare
    PASS ORA_JAVA.JOBJECT;
    a,b integer;
    begin
    pass := <classname>.new;     --new will be created if ur class is public or u got public constructor in ur class.
    increment_1234 (pass,a,b) ; -- increment_1234 (ora_java.object,a,b) ;
    end;

  • Import java class from model package

    I have a java class in model package.I create a managed bean in the view package and I want to import the first java class with "import model.class1" but this error "import model.class1 not found" is shown.What should I do?

    Hi,
    Why are you importing the Model classes to your backing bean? You should not be doing that. Instead, expose the method in model as client interface (whichever you want to call in the backing bean), create the method binding in your pagedef. Then, from the backing bean, you can execute the method programatically.
    -Arun

  • Import a class directly in classpath,without package.

    In jdk1.3, I can
    --------------------------- import MyClass;
    MyClass is in my classpath.
    But in jdk1.4,
    --------------------------- import MyClass;
    cannot been compiled success.
    exception: "." expected.
    Why?

    That's right. Importing a class that wasn't in a
    package was always pointless, and in 1.4 it's actually
    illegal.I am not as certain that I believe in the 'pointless' part.
    As it stands now, a class that does not have a package can not be used in a class that has a package. Not that that is a great loss, but the result certainly surprised me.

  • Import a class cannot take effect until the restart of wls6.1

    Hi all,
    I am using Weblogic6.1,I knew that JSP,Servlet,EJB can be auto depolyed
    without restart weblogic,but when I
    import a class written by myself in JSP or Servlet£¬the modification of this
    class cannot take effect until
    the restart of weblogic server¡£Why? How can I solve it£¿
    thanks in advance!

    Check that your classpath is not set up to this class when you start the
              server and check the ProductionDeploymentMode to false in the starting
              parameters!
              Hope it helps.
              Pat
              "jxc" <[email protected]> wrote in message
              news:3bef34c3$[email protected]..
              > Hi all,
              > I am using Weblogic6.1,I knew that JSP,Servlet,EJB can be auto
              depolyed
              > without restart weblogic,but when I
              > import a class written by myself in JSP or Servlet£¬the modification of
              this
              > class cannot take effect until
              > the restart of weblogic server¡£Why? How can I solve it£¿
              >
              > thanks in advance!
              >
              >
              >
              >
              >
              

  • Why cannot I import the package of j2ee?

    Hello,
    I am a beginning learner of J2EE but I am an immediate learner of J2SE.
    I have 3 questions. First of 2 is that why cannot I import the package of the J2EE, such as import javax.mail.*; ?
    Second question is that can anyone of you suggest me to write what J2EE program in order to let me learn the J2EE? What J2EE program example can you suggest me to write?
    Third question is in order for running J2EE application, what tool or tools should I have? Is the tool j2sdk1.4 java tool enough?Hardly enough?
    Learner,
    JohnWen604
    5-July-2005

    First of 2 is
    /u] of 2 is that why cannot I import the package of
    the J2EE, such as import javax.mail.*; ?Because it isn't on your classpath.
    Third question is in order for
    n order for running J2EE application, what tool or
    tools should I have? Is the tool j2sdk1.4 java tool
    enough?Hardly enough?Since that doesn't even have any J2EE classes in it, not enough at all. Look for the J2EE download link.
    JohnWen604
    5-July-2005FYI, this information is already listed on your post by the forum software.

  • Im using BlueJ, I want  to import a class from a path I set.

    Hi, I'm using BlueJ and I want to import a class from a path I set.
    Like this
    import "C:\myfolder\*";
    Instead of like this
    import java.thing.*;
    Any ideas why the above line is not working for me?

    The import statement takes a class name or package name + .*, not a file name. It has nothing to do with files.
    import package.name.ClassName; // to import a class
    import package.name.*; // to import all classes in the package named "package.name"
    You need to properly specify your classpath at compile-time as well as run-time.

  • How to import a class not in the package from a package

    how to import a class not in the package from a package?

    http://java.sun.com/docs/books/tutorial/java/interpack/usepkgs.html

  • A  classpath error while  importing a class with @page import property

    Hi ,
    I am using Tomcat contaniner for jsp applications. I have developed a page that i have import a class. when i use
    <%@ page import="myclass" &>
    i got an error that myclass not found. I have placed into tomcat\webapps\myproject\web-inf\classes directory. So How will I set the classpath for myclass to work?
    thanks.

    I was able to simulate your problem when I created a mismatch in the case of the name of the class.
    for example if my program is called MyClass.java
    and in the import I do <@page import="myclass" %>
    Are you sure about the case of class name that you are using? Please check that the file is called myclass.java the class defined inside it is called myclass and the class file that is copied into the WEB-INF/classes directory is also myclass.class. There should be no difference in the case of the names. like MyClass.java or MyclaSS.class
    Other things to check are
    1. If myclass is defined in a package then you have to import with the package.
    2. Make sure that your jsp is located in the myprojects directory and the class file is copied under myprojects/WEB-INF/classes.
    Let me know if things still don't work
    regards,
    Abhishek.

  • Error while importing java class into oracle forms 10g

    Hi
    I have generated a web service client using jdeveloper 10g. It consists of complex type methods. I am trying to import the class files using java importer in oracle form 10g. I am able import all of them successfully except one. That one is the main method. Please see the error and suggest me how to overcome this error.
    Exception occurred: java.lang.NoClassDefFoundError: oracle/jdeveloper/webservices/runtime/WrappedDocLiteralStub
    Thanks in advance

    Do you see oracle/jdeveloper listed in "Import Java Classes" when you try to import?
    If not, make sure you add C:\DevSuiteHome_1\jdev\lib\jdev.jar to FORMS_BUILDER_CLASSPATH in registry
    Also excetion indicates: oracle/jdeveloper/webservices/runtime/WrappedDocLiteralStub
    If you typing it - type: oracle.jdeveloper.webservices.runtime.WrappedDocLiteralStub

Maybe you are looking for

  • How to create Search help exit, and then assign it to a collective search

    hi gurus, i have an intersting question for you, well my scenario is like i have to create a search help exit using some function module cause i didt found table for my search help but i can find the value through FM, i know we can create a search he

  • FI document Line item Long text store in which table .

    Respected Members, During posting of the FI document through Tcode F-02 i m giving the some text in the long text not in the text field. Please anybody can be help me out where exactly this long text is going to be stored or in which table. Through F

  • Problem with ALV o/p

    Hi frnds i developed a ALV report with GRID display with 12 columns .Iam getting the proper o/p for the same. Now wen i try to take the print or see the print preview of it it gives me only 6 columns . can any1 tell me wht can be the problem.

  • Backing Up Your Files

    Could anybody recommend an application that I can use on my MacBook Pro to manage the regular back up of my files (photos, music, documents etc). I have an external harddrive that I connect and have manually copied the files to be backed up over, but

  • Thousands of "rolls" - how can I change this?

    iPhoto 6.0.6: I just checked my iPhoto 6 library and noticed that there are literally thousands of "rolls", most of which have just one photo in them. My "2007" folder has 1356 folders in it... Is there a way to change the import prefs so that this i