Why do we need to import 'java.lang.annotation' ?

Hi All,
Since java.lang.* is the default package for all java file, Why do we need to import 'java.lang.annotation' separately?
Thanks in advance..
Regards
Karthikeya V

Karthikeya wrote:
Hi All,
Since java.lang.* is the default package for all java file, Why do we need to import 'java.lang.annotation' separately?
Thanks in advance..
Regards
Karthikeya VLet me explain that differently: packages on disc usually form a directory structure (but it is not a rule, elements of the same package structure can come from different jars). BUT, this does not automatically mean that packages to Java form some kind of hierarchy as well - they don't. java.lang and java.lang.annotation are simply two completely different, unrelated packages.

Similar Messages

  • Why use customized / particular exceptions instead java.lang.Exception

    Hi,
    Do any of you guys know where can I find a theorical statement / explanation about why use particular / customized exceptions instead java.lang.Exception? I am aware that it consumes more resources and becomes a heavier object, as well as the clearness when coding and all that stuff; however, my boss wants to see a tech document where all this is clearly stated. Any resource over there?
    Regards

    It is better to throw specific--or at least module- or
    package-specific--excpetions, rather than Exception,
    because then the caller knows what to expect. However,
    if you declare "throws Exception", the caller can
    still catch IOException, SQLException, etc.,
    separately. He'll just have to be a really good
    guesser as to which ones he should catch.True.
    Also, there's no point in declaring "throws
    NullPointerException." Any method can throw it without
    declaring it. If you generate your own NPE (or other
    unchecked exception) inside the method, then you
    should document it in the javadoc comments, but you
    don't need to put it in the throws clause. It doesn't
    do any harm, but it's redundant and cluttersome.It was an example and I wasn't feeling too creative....excuse me. ;-) But yeah, I've never thrown NPE ever.
    I'm assuming overhead caused by extending classes.At
    the worst, it would be miniscule, or so I wouldthink.
    What overhead is created by extending classes?Hmm, I was under the impression that a class the extended another class, inherited all of the other classes data (variables, etc.). Hence, you get something like this:
    SuperClass1 + SubClass1 + SubClassOfSubcCass1 = Memory usuage for SubClassOfSubClass1.
    Since adding postivie number will always end up increasing data, SubClassOfSubClass1 will use more dtat than SuperClass1.
    Am I wrong?

  • Why do we need downcasting in Java? What is the use of it?

    Why do we need downcasting in Java? What is the use of it?

    here's an example of a valid downcast.
    class Dog {}
    class Dogma extends Dog {}
    class Dogmatic extends Dog {}
    Dog dogwood = new Dogma(); // a Dogma object is upcast to a Dog
    Dogma bush = (Dogma) dogwood; // a Dogma object is downcast from a Dog
    You cannot upcast a Dogmatic to a Dog and then downcast it to a Dogma. You also cannot downcast a Dog to a Dogma. In the working example, above, the dogwood references a Dogma, so you can downcast the Dogma.
    and one more example
    If you have a class hierarchy where class B extends class A (B is a specialization of A) you can use B in the place of A since B supports all the operations that B does. This is called polymorphism.
    When you use an object of type B in place of A you actually do a up-cast, meaning you make the object of type B look like an object of type A (a less specific class type).
    What you are asking about is down-casting which is making an object be of a more specific type, i.e. transforming an object of type A to type B. Is is only allowed if the object was actually created as a type B.
    This is allowed (line 2 is a down-cast):
    A a = new B();
    B b = (B)a;

  • Import java.lang.?

    I just noticed that, without writing "import java.lang.***;" all the classes in the java.lang.*** namespace are reachable, such as:
    java.lang.Exception;
    java.lang.Thread;
    java.lang.StringBuilder;
    So, is it correct to say that " import java.lang.***; " has no tangible effect and I should never have it in my source code? thanks.

    Yes.

  • Why do I need a second java.exe when I alreayd have another in a JDK instal

    When I install JDK then there are two instances of java.exe
    (and other programs like javaws.exe). One instance in
    INSTALL_DIR\bin\
    and the other in
    INSTALL_DIR\jre\bin\
    So why do I need two exes instead of one?
    Peter

    Hello!
    So why do I need two exes instead of one?Don't know the reason myself, ask the developers..........
    One instance in INSTALL_DIR\bin\
    and the other in
    INSTALL_DIR\jre\bin\Yes, checked that, you are right.
    But , whats the problem, It hardly takes 2MB more space.
    Or, were you implying that ideally java.exe and javaws.exe should not be in "INSTALL_DIR\bin\" as they are involved in running the java programs.
    Thanks!

  • Why my cutomize role mapper throws java.lang.ClassCastException: $Proxy67

    Hello all,
    I customize the role mapper as follows is my MDF content
    <MBeanType
    Name = "TestRoleMapper"
    DisplayName = "TestRoleMapper"
    Package = "test.pkg.roles"
    Extends = "weblogic.management.security.authorization.RoleMapper"
    Implements = "weblogic.management.security.authorization.RoleReader"
    PersistPolicy = "OnUpdate"
    I implements the method "listRolesForResource", this method declared to return a string array.
    When I return the role name array then Weblogic throws java.lang.ClassCastException: $Proxy67
    Error snapshot
    http://antonov0318.googlepages.com/error.jpg
    Would I miss some interface ?
    Would somebody know how to solve it?
    Please let me know , Please....Thank you very much.
    Edited by: user6273860 on 2008/10/25 上午 12:00

    It looks like you're just taking random methods,
    calling them incorrectly, and expecting them to
    work.
    What do you think this will do?
         * Construct {@link java.lang.Object} array of keys from {@link java.util.Hashtable}
         * @param h {@link java.util.Hashtable}
         * @return array {@link java.lang.String}
         * @throws java.lang.IndexOutOfBoundsException Exception thrown if initial {@link java.lang.Object} array paramater cannot be indexed
        public static Object[] arrayKeys(Hashtable<Object, Object> h) throws IndexOutOfBoundsException {
            return h.keySet().toArray();
        }>
    ArrayFunctionality.arrayKeys(attrs)(new
    String[attrs.size()]);What's arrayKeys? And what do you think
    method(args) (some other stuff) ; will
    do?
    Somebody else showed you what to do earlier, but they
    had a typo. You need to pass an array of the
    appropriate type to toArray:
    String[] stringArr =
    (String[])theList.toArray(someStringArray);Read the docs for that method so you understand how
    it works. Just just blindly copy/paste.The API docs for toArray() for java.util.Set interface takes no parameters, I can't expect to know you can override it

  • Help needed with JNI -  java.lang.UnsatisfiedLinkError

    I need some help with JNI. I am running on Sun Solaris 7 using their CC compiler. I wrote a simple java program that calls a native method to get a pid. Everything work until I use cout or cerr. Can anyone help? Below is what I am working with.
    Note: The application works. The problem is when the C++ code tries to display text output.
    My error log is as follows:
    java Pid
    Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/dew/test/libPid.so: ld.so.1: /usr/j2se/bin/../bin/sparc/native_threads/java: fatal: relocation error: file /home/dew/test/libPid.so: symbol __1cDstdEcerr_: referenced symbol not found
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1382)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1306)
    at java.lang.Runtime.loadLibrary0(Runtime.java:749)
    at java.lang.System.loadLibrary(System.java:820)
    at Pid.<clinit>(Pid.java:5)
    Pid.java
    ========
    * Pid: Obtains the pid from the jvm.
    class Pid {
    static { System.loadLibrary("Pid"); }
    public native int getPid();
    public static void main(String args[])
    System.out.println("Before construction of Pid");
    Pid z = new Pid();
    System.out.println(z.getPid());
    z = null;
    Pid.cpp
    =========
    * Native method that obtains and returns the processid.
    #include "Pid.h"
    #include "unistd.h"
    #include <iostream.h>
    JNIEXPORT jint JNICALL Java_Pid_getPid(JNIEnv *env, jobject obj) {
    /* cout << "Getting pid\n"; */
    cerr << "Getting pid\n";
    /* printf("Getting pid\n"); */
    return getpid();

    I forgot to include my build information.
    JAVA_HOME = /usr/j2se/
    LD_LIBRARY_PATH = ./:/opt/readline/lib:/opt/termcap/lib:/usr/bxpro/xcessory/lib:/${JAVA_HOME}/lib:/usr/RogueWave/workspaces/SOLARIS7/SUNPRO50/0d/lib:/usr/RogueWave/workspaces/SOLARIS7/SUNPRO50/3d/lib:/usr/sybase/lib
    javac Pid.java
    javah Pid
    CC -G -I${JAVA_HOME}/include -I${JAVA_HOME}/include/solaris Pid.cpp -o libPid.so
    Thanks again,
    Don

  • Help needed (the notorious java.lang.UnsatisfiedLinkError)

    Hello all.
    I'm using Eclipse 3.4.0 on Windows and getting the following error when trying to call a function from a dll which is located in the java project(Test) folder:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: Test.hello()V
         at Test.hello(Native Method)
         at Test.main(Test.java:12)Any thoughts about why this problem is happening will be very appreciated.
    This is my simple code:
    Test.java
    public class Test {
         public native void hello();
         static {
              System.loadLibrary("hello");
         public static void main(String[] args) {
              new Test().hello();
    }test.cpp
    #include <iostream>
    #include "Test.h"
    JNIEXPORT void JNICALL Java_Test_hello
      (JNIEnv *env, jobject obj)
         std::cout<<"Hello World!"<<std::endl;
    }Test.h
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class Test */
    #ifndef _Included_Test
    #define _Included_Test
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class:     Test
    * Method:    hello
    * Signature: ()V
    JNIEXPORT void JNICALL  Java_Test_hello
      (JNIEnv *, jobject);
    #ifdef __cplusplus
    #endif
    #endif

    Anton1981 wrote:
    Hello all.
    I'm using Eclipse 3.4.0 on Windows and getting the following error when trying to call a function from a dll which is located in the java project(Test) folder:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: Test.hello()V
         at Test.hello(Native Method)
         at Test.main(Test.java:12)
    The exception tells you that java did not find the method that it was looking for.
    Your library was loaded otherwise another exception would have occurred.
    Per your posted code the above exception does not match (line 11 versus line 12). That could just be a cut and paste though.
    Presumably you do not have a package in Test because otherwise your C++ code does not match.
    Most problems of this sort are because the java method signature does not match the C method signature but your appears to be correct. But to be safe you might want to
    1. Delete the dll/h file
    2. Delete the class files
    3. Recompile java
    4. Rerun javah
    5. Confirm the signature still matches in your cpp file.
    6. Rebuild the dll.
    Also try running your code before step 6. If you get an exception besides one that says your library is missing then you still have a library somewhere (which is another source of possible problems.)

  • Why i can't use import java...;

    Hi,
    i'm trying to compile a small piece of java program but the compiler tells me that some of the objects defined are unknown.
    For example, i imported java.io.* and istanced TextFileReader fr = new TextFileReader();
    Is there anybody able helping me?
    Thanks man!

    Hm...you're a bit new at this right? =).
    Allright, this is what you gotta do:
    if your're running Windows 98...find the autoexec.bat file and select to edit it.
    there will be a variable called classpath. Here, you must add an entry (path) to where the rt.jar file is found.
    Let us assume that you installed jdk directly on to c:\. The jar file is usually found in jre\lib\rt.jar
    so, you would add the following line:
    .;C:\jdk\jre\lib\rt.jar
    you must have that set for any of your programs to work at all. I would recommend you simply write a program that prints hello...do this:
    import java.io.*;
    public class PathTester
    public static void main(String[] args){
    System.out.println("I'm working");
    If this doesn't work...you're in big trouble =). Once this works, you're ready to go. Give it a shot.
    Shrubz

  • Need help on java.lang.reflect

    Hi,
    I want to use the java.lang.reflect package's member classes for my program. Is there any place on web where I can get complete details of these packages including, classes, methods, functions and their arguements etc.
    Thanks.

    Hi jasper,
    It serves my purpose. But it is available as web page with links. Is there any downloadable version available?
    Can anybody help me, because I won't be online all the time.

  • Need help with java.lang.UnsatisfiedLink Error

    hello,
    i'm trying to access a channel using Java Channel Access(JCA) on HP UX
    [please ref for documentation: http://www.aps.anl.gov/xfd/SoftDist/swBCDA/jca/doc/index.html]. I set the java.library.path to the directory where my JCA libraries are. But I get the following error and finally core dump when I try to load the library, libjca.sl or even when I comment out the lines that load the library.
    Any help would be appreciated. Thanks, Srik.
    My Source code looks like this:
    try{
    System.out.println(System.getProperty("java.library.path"));
    try{
         //System.loadLibrary("libjca.a");
         System.loadLibrary("libjca.sl");
    }catch(UnsatisfiedLinkError ule){
         ule.printStackTrace();
    Ca chanAcc = new Ca();
    chanAcc.init();
    System.out.println("Hello: Connected to Channel");
    PV procvar = new PV("ioc:heartbeat");
    chanAcc.flushIO();
    String host = procvar.hostName();
    System.out.println("Host: "+host);
    procvar.clear();
    chanAcc.exit();
    }catch(Exception e){
    e.printStackTrace();
    Error:
    java.lang.UnsatisfiedLinkError: no libjca.sl in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1419)
    at java.lang.Runtime.loadLibrary0(Runtime.java:788)
    at java.lang.System.loadLibrary(System.java:832)
    at ChAccess.main(ChAccess.java:12)
    aCC runtime: Error 215 from shl_findsym(/cs/prohome/lib/libcsue.sl.v5,_shlInit)
    /usr/lib/dld.sl: Unresolved symbol: typeid__XTQ2_3std9exception_ (data) from /cs/prohome/lib/libcsue.sl.v5
    /usr/lib/dld.sl: Unresolved symbol: Cclassic_table__Q2_3std5ctypeXTc_ (data) from /cs/prohome/lib/libcsue.sl.v5
    /usr/lib/dld.sl: Unresolved symbol: __nullref__Q2_3std12basic_stringXTcTQ2_3std11char_traitsXTc_TQ2_3std9allocatorXTc__ (data) from /cs/prohome/lib/libcsue.sl.v5
    /usr/lib/dld.sl: Unresolved symbol: __ct__Q3_3std8ios_base4InitFv_1 (code) from /cs/prohome/lib/libcsue.sl.v5
    /usr/lib/dld.sl: Unresolved symbol: Cfire_event__Q2_3std8ios_baseFQ3_3std8ios_base5eventb (code) from /cs/prohome/lib/libcsue.sl.v5
    /usr/lib/dld.sl: Unresolved symbol: __dt__Q2_3std9exceptionFv (code) from /cs/prohome/lib/libcsue.sl.v5
    /usr/lib/dld.sl: Unresolved symbol: Cinitfacet__Q2_3std5ctypeXTc_FRCQ2_3std6locale (code) from /cs/prohome/lib/libcsue.sl.v5
    /usr/lib/dld.sl: Unresolved symbol: Cvformat__Q2_3std14__rw_exceptionFiPd (code) from /cs/prohome/lib/libcsue.sl.v5
    /usr/lib/dld.sl: Unresolved symbol: do_out__Q2_3std14codecvt_bynameXTwTcT9mbstate_t_CFR9mbstate_tPCwT2RPCwPcT5RPc (code) from /cs/prohome/lib/libcsue.sl.v5
    /usr/lib/dld.sl: Unresolved symbol: __dt__15_HPMutexWrapperFv (code) from /cs/prohome/lib/libcsue.sl.v5
    /usr/lib/dld.sl: Unresolved symbol: do_in__Q2_3std14codecvt_bynameXTwTcT9mbstate_t_CFR9mbstate_tPCcT2RPCcPwT5RPw (code) from /cs/prohome/lib/libcsue.sl.v5
    /usr/lib/dld.sl: Unresolved symbol: __dt__Q3_3std8ios_base4InitFv (code) from /cs/prohome/lib/libcsue.sl.v5
    ABORT instruction (core dumped)

    hi jonas..
    thanks for the reply. actually I set SHLIB_PATH on HP UX which is the equivalent of LD_LIBRARY_PATH and i'm trying to load the library using
    System.loadLibrary(..) and i type out the path using System.getProperty to make sure that the path to the library is included.
    but still i'm getting the error.
    i'd appreciate any suggestions.
    thanks in advance.

  • Why do we need to install java during sap installation

    why do we install Java during SAP installation?

    Hello Satish,
    Sapinst tool requires JRE for the running and as JRE cannot be integrated to sapinst due to licensing issues we need to install seprately java before sap installation.
    Hope this clarifies your query.
    Thansk and Regards,
    -Bijesh.

  • Why do I need to download Java SE 6 runtime to open Adobe Illustrator on my brand new mac book pro?

    Please help?

    Apple no longer handles or deals with JAVA anymore
    and has left that task up to the publishers of JAVA, Oracle.

  • Java Importer: import of java.lang.Boolean does not compile?

    I have created a webservicestub for the Reports webservice with JDeveloper.
    Now I want to use it in Forms. All methods work correctly, except the runJob method, which uses a boolean argument. I think I need to import java.lang.Boolean for it, but the created package body does not compile ("wrong number or type of arguments" in jni calls).
    Does anybody have suggestions how to get it compiling, or how to call the runJob method without the import of java.lang.Boolean?

    Downloading 1.4 sdk does not have the javac, it just has the JRENo, you apparently downloaded the JRE runtime. Do this to get the compiler, etc:
    Go here: http://java.sun.com/j2se/1.4/download.html
    and in the section titled:
    Download J2SETM v 1.4.0_01 JRE SDK
    look in this row:
    Windows (all languages, including English)
    and click download in the column headed SDK at the far right

  • Java.lang.Integer

    I am getting "cannot resolve symbol" error on compilation on the method 'getInteger' below.
    I am not able to figure out what can be the reason?need help
    import java.lang.*;
    public class inttest
    public static void main(String[] argc)
    String str = "test";
    Integer int1 = getInteger(str);

    I am getting "cannot resolve symbol" error on
    compilation on the method 'getInteger' below.
    I am not able to figure out what can be the
    reason?need help
    import java.lang.*;
    public class inttest
    public static void main(String[] argc)
    String str = "test";
    Integer int1 = getInteger(str);
    getInteger is a static method of the Integer class, so it needs be called like this:
    Integer.getInteger(str);

Maybe you are looking for

  • What Print Resolution for Epson R800?

    I wonder what the value for "Print Resolution" in the Printer module should be to print with an Epson R800 on glossy or luster paper at the highest quality settings (Photo RPM). I would rather not have LR do any re-sampling... but given it asks for a

  • Rename ok button from FYI notification in oracle workflow.

    Hi All, In Oracle workflow the Client want to rename the OK button in FYI Notification. Is it feasible? If yes then how to do this. Please help. Regards, Uday Edited by: 823973 on May 10, 2013 12:03 AM

  • BUG - too many images crashes apps.

    Hello, I would like to report a bug to RIM.  When using a sketchting app (Paint book or Sketch), if I attempt to load an image, the application hangs and the keyboard and parts of the touchpad get disabled even after I have killed the application, al

  • Cause for the sudden shutdown of Essbase?

    Hello Experts, One of my customer would like to know the cause for the sudden shutdown of Essbase. They started receiving the below error when tried to connect through EAS or through Spread sheet Add-in network error [145]: unable to connect to essol

  • Modules in SWC files

    We have a custom SWC, with its defaults.css. Customer uses our SWC in a module. When the module is loaded in a main application, the module loads, but css styles defined in our defaults.css do not. Only way to fix is to include our CSS in main applic