Difference between javac and eclipse compiler

I have the following code:
public class Test {
     public static void main(String[] args) {          
          Integer i = 0;
          double d = 1.5d;
          i += d;
          System.out.println(i);
}javac gives me the following error:
Test.java:5: inconvertible types
found   : double
required: java.lang.Integer
                i += d;
                     ^
1 errorThe Eclipse compiler, however, gladly compiles and the JRE runs it, outputting "1".
The question is: which compiler is correct?
javac version 1.6.0_04
java version "1.6.0_04"
Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)
Eclipse JDT version 3.3.1.r332_v20080131

Integer is probably 32-bit while Double is 64-bit.
Your code is doing the following;
- widening the original Integer to Double,
- performing double-precision addition,
- assigning the double-precision result to the original Integer.
Without an explicit cast, your code is asking the compiler to implicitly narrow the double, potentially throwing away data.

Similar Messages

  • Whatz the difference between jdk and jre

    i would like to know the difference between jdk and jre.

    Yes JRE is Java Run Time Environment. The java programming language adds the portability by converting the source code to byte code version which can be interpreted by the JRE and gets converted to the platform specific executable ones. Thus for different platforms one has corresponding implementation of JRE. But JRE has to meet the specification JVM (Java Virtual Machine) Concept that serves as a link between the Java libraries and the platform specific implementation of JRE. Thus JVM helps in the abstraction of inner implementation from the programmers who make use of libraries for their programmes.
    The JDK(Java Developmental Tool kit) comes along with java libraries and JVM embedded in it. Apart from these it comes along with the utility tools for byte code compilation "javac", Executing the byte codes through java programmes through "java" and many more utilities found in the binary directory of java. Speaking practically JDK is essential for developers, which comes along with library packages to develop Software programmes. While JRE is minimal set of programmes which executes the java class files developed by the software developers.

  • What is the difference between netbeans and JDK ?

    What is the difference between netbeans and JDK ?
    This is because i got netbeans 5.5 ide and nothing else and still i ran some hello world programs successfully. . ..
    i am confused - - does jdk come combined with netbeans ?

    What is the difference between netbeans and JDK ?
    This is because i got netbeans 5.5 ide and nothing
    else and still i ran some hello world programs
    successfully. . ..
    i am confused - - does jdk come combined with
    netbeans ?JDK is Java Development Kit. It includes all the Java APIs and Java tools like compiler etc so that you can develop code in Java language.
    NetBeans is an IDE (Integrated Development Environment). It provides you tools for helping you write Java code, like it provides you a text editor where you can type your java code etc. You can use any other IDE like Eclipse JCreator etc for writing java code.
    NetBeans should come packaged with a JDK. NetBeans requires JDK to function but JDK does not require NetBeans to function.
    Personally, if you are so new to the language then I would recommend that you stay away from NetBeans or any other other heavy IDE for a while and code in something like WordPad or some of the other editors recommended in this thread. This will help you learn the language better. You can latter decide on an IDE when you are comfortable with the language.

  • Difference between void and null?

    wht is da difference between void and null w.r.t java?

    corlettk wrote:
    Why do you care, unless you're implementing a java compiler or JVM?Wow, you sure do suck at helping out in a forum. Why even make this post? You're not helping the OP any, and you made yourself look like a tool.
    To the op:
    Null is java's version of a null value. Java's version is more strict then many other languages, and will not work in a boolean expression or anywhere code expects a real and not null value. It's simply null.
    Void is java's way of declaring no return type on a method. Methods that are void take no 'return' statement and if one is provided will cause a fatal error. The exception to this is using 'return' without a value, which returns control to the caller of the method.
    Observe:
    //this method returns an int
    public int return_int(){
        int value = 5;
        return value;
    //this method does not return an int
    public void return_nothing(){
        int another_value = 123;
        System.out.println("Here's the value: " + return_int());
    //this method does not return anything
    public void nothing_returned(){
        return_nothing();
        return;
        System.out.println("This line never gets printed; the method returned control already!");
    }

  • Difference between mtl_system_items and mtl_system_items_b

    Hi All,
    Can anyone tell me the difference between mtl_system_items and mtl_system_items_b ?
    Regards,
    Shruti

    mtl_system_items is a synonym that points to mtl_system_items_b
    mtl_system_items used to be the actual items table in older versions.
    But in recent version the mtl_system_items_b is the items table. If any old code was using mtl_system_items, the synonym helps it compile and thus make this change backward compatible.
    Oracle follows the following convention to handle multi-language.
    The b stands for base table. And then there is a table called tl (e.g. mtlsystem_items_tl). In the _tl table, for each base record, you can find multiple records - one for each language that you use.
    Hope this answers your question,
    Sandeep Gandhi

  • What's the difference between boxing and unboxing?

    What's the difference between boxing and unboxing, I'm a bit confused?
    Is autoboxing the same as boxing?
    This is what I know so far:
    -This is boxing, i think:
    int  []arrayset = {1,2,3};but I don't understand what unboxing is, can someone explain it to me.

    I did little research, but please correct me ifI'm
    wrong:
    Is this similiar to unboxing:
    System.out.println(intArray[0] + intArray[1] +
    intArray[2]);
    Only if intArray is declared asInteger[]
    intArray ...Then the Integers at intArray[0] etc are unboxedinto
    int primitives before adding.Did you try that before you posted it? Autoboxing is
    applied only to an individual primitive/wrapper.
    Arrays and collections aren't subject to
    autoboxing/unboxing. Basically, the compiler will
    fill in constructs such as Integer.valueOf() for you,
    it doesn't go as far as generating loops and new
    arrays for you
    OP, as Peter said, the difference between boxing and
    unboxing is merely one of direction. Autoboxing wraps
    a primitive up for you, auto-unboxing extracts the
    primitive from a wrapperAm fully aware of that, the OP's example contained references to array elements but it was not clear whether that array was declared as Integer[] or int[], hence my answer.
    And just for the recordInteger[] intArray = new Integer[] {1, 2, 3}; // autoboxing
    System.out.println(intArray[1] + intArray[2]); // autounboxing
    // while ...
    int[] intArray = new int[] {1, 2, 3}; // no boxing
    System.out.println(intArray[1] + intArray[2]); // no unboxingis what i meant.

  • Differences between CAF and NWDS

    Hi all,
    I'm reading about CAF and I don't understand the differences between CAF and NWDS. In NWDS you can composite an aplication with services offered by other systems, so I don't understand what CAF offers.
    Regards,

    Hi,
    CAF is a Frame work for developing Composite Applications.
    CAF consists of two parts: design time and run time.
    NWDS provides design time development support.Simply, NWDS is the IDE based on Eclipse.
    CAF Server that is Composite Environment Server provides the run time for composite applications.
    You can go through the help doc for [Composite Environment |http://help.sap.com/saphelp_nwce10/helpdata/en/45/ff9fc1d8986c06e10000000a1553f6/frameset.htm]so that you can understand easily.
    Sampath

  • Differences between jdk and jre

    can anybody explain the differences between jdk and jvm. and relation between jdk, jre and jvm.
    thanks

    Hi,
    JDK- Java Development Kit contains compiler and other appliction development tools. with this tool you can compile as well as run your application
    JRE-Java runtime Environment where Java applications are exceuted .You can only run your application here but you cant develop and compile.
    JVM-Java Virtual Machine Its interpretor which interprets and then executes you coded after it is compile ( to byte code) by Java Compiler.

  • What are the differences between inactive and active ABAP objects?

    Can anybody tell me what are the differences between inactive and active ABAP objects?
    In my opinion,  an active object is compiled and system wide available, that means the system do not have to compile the program again before run or use the object. While An inactive object is not system wide available and every time you run an inactive object, firstly the abap runtime will have to  generate a tempory runtime object and this inactive object can not seen by others.
    Am I right? Can anybody kindly tell me other differences?

    Hi,
    "When it is inactive, it is like it would not exist at all:" no - it's like it only exists to you
    "If we just saved that one means it is stored in application server not in database": no - the inactive version is also stored in the database. You can log off and log on and it will still be there, in its inactive status.
    "Only active objects can be executed.": no - inactive objects can be executed by you
    When you create or modify a program, it is inactive until you activate it.
    With a change, there are two versions of the program stored in the database - the active version (as it was before you made your change), and the inactive version. If you attempt to run the program, you'll run the inactive version - the one with your changes. Everyone else on the system will run the active version.
    In this way, you can make changes without affecting anyone else.
    Once you activate your program, then the inactive version becomes the active version.
    With a create, there is no active version, until you hit the activate button. This means ONLY you can run the program.
    An additional benefit of this model, is that if you make a change, save it, and then change your mind without activating, you can recover the active version into the editor, using version management.
    A downside is that sometimes you have to activate your change before you can test it, if it interacts with other, active, programs.
    Regards,
    Kumar

  • Difference between Macros and subroutine

    Hi all,
    What is the difference between the macros subroutine and function module functinalitywise.;

    Hi,
    Macros can only be used in the program the are defined in and only after the definition.
    Macros can take max 9 parameters.
    Macros are expanded at compilation / generation.
    Subroutines (FORM) can be called from both the program the are defined in and other programs ('perform
    ' of 'perform in program ').
    Subroutines can take any amount of parameters.
    Subroutines are 'expanded' at runtime.
    Functions are just like FORMs, but are intended to be called external.
    Some differences between FUNCTIONs and FORMs:
    The name of a FORM must be unique within the program (two programs can have different FORMs with the same name). A FORM is intended to be called internal (from within the program, however by a 'trick' you can call them external).
    The name of a FUNCTION has to be unique throughout the system. A FUNCTION is intended to be called external (and is thus shared by 'many' programs).
    The latter is more important for programmers and maintenance. Since a FUNCTION is called external, it is important to keep the interface (parameters) the same. The interface of a FORM (which is intended to be called internal) is check when debugging a program (but it is only checked within the program that is debugged). So if the interface of a FORM is changed, but the call to the FORM (perform ) is not, the debugger will notice this and issue an error message.
    In general:
    A MACRO is more or less an abbreviation for some lines of code that are used more than once or twice.
    A FORM is a local subroutine (which can be called external).
    A FUNCTION is (more or less) a subroutine that is called external.
    Since debugging a MACRO is not really possible, prevent the use of them (I've never used them, but seen them in action). If the subroutine is used only local (called internal) use a FORM. If the subroutine is called external (used by more than one program) use a FUNCTION.
    --Excerpt from http://sap.ittoolbox.com/documents/popular-q-and-a/macro-vs-subroutine-1594#
    DATA p_c(10).
    FIELD-SYMBOLS: <fs> TYPE ANY.
    DATA p_old1 TYPE i VALUE 10.
    DATA p_old2 TYPE i VALUE 11.
    DATA p_old3 TYPE i VALUE 12.
    DATA p_old4 TYPE i VALUE 13.
    DATA p_old5 TYPE i VALUE 14.
    DATA p_old6 TYPE i VALUE 15.
    DATA p_old7 TYPE i VALUE 16.
    DATA p_old8 TYPE i VALUE 17.
    DATA p_old9 TYPE i VALUE 18.
    DATA p_old10 TYPE i VALUE 19.
    DATA p_old11 TYPE i VALUE 21.
    DATA p_old12 TYPE i VALUE 22.
    DATA p_old13 TYPE i VALUE 23.
    DATA p_old14 TYPE i VALUE 24.
    DEFINE ADD_MAPPING.
    p_c = &1.
    CONDENSE p_c.
    CONCATENATE 'p_old' p_c INTO p_c.
    ASSIGN (p_c) TO <fs>.
    WRITE <fs>.
    END-OF-DEFINITION.
    DO 14 TIMES.
    ADD_MAPPING sy-index.
    ENDDO.
    http://sap.ittoolbox.com/documents/popular-q-and-a/macro-vs-subroutine-1594
    http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db972835c111d1829f0000e829fbfe/frameset.htm
    Regards,
    Priyanka.

  • Difference between implements and extends

    Hi all,
    what is the difference between implements and extends. i am sorry to ask this silly question, but i am new to JAVA.
    Thanks
    Balaji

    when you extend a class, your class that you are coding inherits every method and field from the extending class. For example:
    public class CustomFrame extends JFrame {
    //Your class's methods will be in here, but so will all of JFrame's methods.
    }You can override (most) methods from extended classes if you want them to do different things than they normally do. The most commonly overriden methods when using swing are stuff like paint(Graphics g). It needs to be overriden to repaint all of the components.
    When you imlpement something, you have to specify an interface. Interfaces have methods in them with no code. If you implement an interface, all methods in in must be defined. If not, the code will not compile. Some interfaces like ActionListener extend other classes to perform stuff. The actionPerformed(ActionEvent e) method will perform an action when a button is pressed, etc.

  • Difference between Macros and subroutines

    Hi experts can any one tell difference between macros and subroutines.

    1) Macros can only be used in the program the are defined in and only after the definition are expanded at compilation / generation. Subroutines (FORM) can be called from both the program the are defined in and other programs . A MACRO is more or less an abbreviation for some lines of code that are used more than once or twice. A FORM is a local subroutine (which can be called external). A FUNCTION is (more or less) a subroutine that is called external. Since debugging a MACRO is not really possible, prevent the use of them (I’ve never used them, but seen them in action). If the subroutine is used only local (called internal) use a FORM. If the subroutine is called external (used by more than one program) use a FUNCTION
    2)  The macros, which we may use,
    (stored in table TRMAC)
    , we cannot debug that code.
    3) where as in subroutine,
    its a abap code, directly visile in
    the editor,
    and we can debug this code.
    4) MACROS =>
    Getting a feel of macros
    The basic syntax of macros is as follows:
    DEFINE macro_name. "Macro Definition
    ……………. Statements
    ……………. Statements
    END-OF-DEFINITION. "Macro Definition
    macro_name par1 par2 …par9. "Macro call -parameters separated by spaces
    Within the DEFINE... and END-OF-DEFINITION lies the body of the macro—the statements that you wish to be executed each time the macro is called. These statements may be any valid ABAP statements, such as WRITE, CLEAR, FORM calls, or database statements such as SELECT or UPDATE.
    To familiarize yourself with the working of macros, it's necessary to take a close look at exactly what happens when an ABAP program containing a macro call is generated. Consider Listing A.
    All ABAP programs must be generated before they can be executed. At the time of program generation, the system supplants each macro call, as shown in Listing A, with the statement(s) placed between the macro definition. Furthermore, the parameters passed at the time of macro calling are copied in place of the any placeholders (numbered &1, &2 …&9) found in the body of the macro definition. The system simply ignores the presence of the macros during the execution of the program—that is, all statements are executed as a single block of code:
    write : int1.
    write : int2.
    write : int3.
    Other than readability and meaningfulness, macros also offer performance advantages. For testing purposes, I wrote a macro that incremented the value of a variable by 1 and called the macro N times via a DO loop, as shown here:
    DEFINE INCREMENT.
    ADD 1 TO &1.
    END-OF-DEFINITION.
    DO N TIMES.
    INCREMENT VAR1.
    ENDDO.
    SUBROUTINES=>
    Subroutines
    You call subroutines from ABAP programs using the PERFORM statement.
    Subroutines are introduced with the FORM statement and concluded with the ENDFORM statement.
    You can define subroutines in any ABAP program. You can either call a subroutine that is part of the same program or an external subroutine, that is, one that belongs to a different program. If you call an internal subroutine, you can use global data to pass values between the main program and the subroutine. When you call an external subroutine, you must pass actual parameters from the main program to formal parameters in the subroutine.
    *U Shud start rewarding helpfull answers*
    amit

  • Difference between mailroutingsmarthost and daemon

    I would like to know the difference between mailroutingsmarthost and daemon usage. When to use mailroutingsmarthost and when to use daemon?
    Thanks in advance.

    MailRoutingSmarthost is placed in LDAP for a domain.
    Daemon keyword is for an entire channel, and is used in the imta.cnf
    LDAP entries require no restart.
    imta.cnf mods require both compile of new config and a restart of the dispatcher to take effect.

  • Difference between procedure and function

    hi
    please give solution to below discussion:
    Interviewer: What is the difference between Procedure and Function ?
    Myself: Procedure may or may not return a value and can return multiple values and Function must return a value.
    Interviewer : Can function return multiple values ?
    myself: Yes, It can return multiple values.
    Interviewer: Then, there is no need to use procedures any more, according to your previous answer (function can return multiple values) "we can do all the things by using procedures by using functions". Then why there is differentiation between procedure and function ?
    myself : no reply (simply frustated at this question)
    The above is conversation between me and interviewer.
    Please suggest me what would be my reply to above topic.
    In one book i find that using functions we can return multiple values but it is poor programming practice.
    why this is a programming practice ?
    please suggest me solution
    thanks in advance
    prasanth as.

    Another difference is function must return something. There is no such restriction on procedure.In fact, a procedure CANNOT contain an expression in its RETURN statement.
    SQL> create or replace procedure test_return is
      2  begin
      3    return(10) ;
      4  end ;
      5  /
    Warning: Procedure created with compilation errors.
    SQL> show errors
    Errors for PROCEDURE TEST_RETURN:
    LINE/COL ERROR
    3/3      PLS-00372: In a procedure, RETURN statement cannot contain an
             expression
    3/3      PL/SQL: Statement ignored
    SQL>And, a procedure cannot be called as part of a expression (it must be a function).
    SQL> create or replace procedure test_return is
      2  begin
      3    return ;
      4  end ;
      5  /
    Procedure created.
    SQL> variable x number ;
    SQL> exec :x := test_return ;
    BEGIN :x := test_return ; END;
    ERROR at line 1:
    ORA-06550: line 1, column 13:
    PLS-00222: no function with name 'TEST_RETURN' exists in this scope
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    SQL>

  • What is the difference between JDK and J2ee

    Could someone explain, in simple terms, what is the difference between JDK and J2ee. I am trying to understand the difference.
    THanks

    Could someone explain, in simple terms, what is the
    difference between JDK and J2ee. I am trying to
    understand the difference.You can practice on this one first. What's the difference between chalk and cheese? No just kidding.
    A JDK is a set of tools for Java development including compiler, runtime system and standard libraries. J2EE is the enterprise version of the Java technology platform (it's one of three). To use it you download the proper JDK's.

Maybe you are looking for

  • Web page does not display on my browser.

    hi, i am trying to go to a web pae with url http://xxx:8800 The page loads but when i enter login username & password , the processing stops there. the information displayed in Java Console is : Connenting to the servlet before urlConn.getOutputStrea

  • Why can't i copy and paste a calendar event?

    Why does Apple not implement copy/paste of events in the iPhone and iPod calendar. People have asked for this very simple feature for years now, and Apple is unresponsive. Furthermore, I have been told by several calendar app developers that Apple wi

  • Print wirelessly with HP Photosmart 7450

    I have an HP Photosmart 7450 printer and a Cisco wireless router.  I also have an HP LaserJet m1212nf that I am printer to wirelessly.  I have an HP desktop and a Samsung netbook.  How do I print to my 7450 from the netbook?

  • Abap/4 Driver

    Hi, What are ABAP/4 Drivers and why are they used? Regards, Nimisha

  • ICal 2.0.1 can't remove an event

    I was invited to an event and I accepted the invite and it imported into iCal, now I have a notification ! in iCal every time I open iCal and I can not get this event off my calender.