Talk:Java Programming/Integer variables

Merge with Learning JAVA

edit

The two pages are fairly similar. They both cover basic variables, how to declare them, and so on. I'm not against the multi-department layout for the Java topic, but the current implementation seems overly redundant.

The two courses are similar in that they cover essentially the same material, but they are designed for different audiences. Introduction to Programming in Java is the companion to Introduction to Programming and both are being written for student with no programming experience of any kind. We are trying very hard not to make any assumptions anywhere in this course, to clearly define every term as we use it and to build up the students understanding of programming in a logical, natural and engaging manner. When I started working on Introduction to Programming and decided that it needed a companion course with real, runnable, examples, I looked at Learning JAVA and though it is a fine course, it isn't appropriate for a raw beginner. It makes too many assumptions and moves too quickly. Dmclean 22:25, 7 February 2007 (UTC)Reply
I see the difference. I'll remove the tags. MetaBohemian 21:06, 13 February 2007 (UTC)Reply

Casting error?

edit
public class Integer1
{
    public static void main(String[] arguments)
    {
        byte i = 127;
        System.out.println("i is " + i);
        i = i + 1;
 
        System.out.println("i + 1 is " + i);        
    }
}

What do you expect the value of i + 1 to be? Compile and run it.

I expected the value to be -128. Instead, I got:

possible loss of precision
found   : int
required: byte
      i = i + 1;
            ^
1 error

(I note it lines the caret under the addition operator...) After some experimentation, it appears the correction is:

i = (byte) (i + 1);

--KevinCole 19:59, 6 May 2010 (UTC)Reply

Abbreviated assignment syntax introduction

edit

In the Character section, the more abbreviated form of assignment with addition (i += 1;) is introduced in the code w/o explanation or comment following. Common to many languages, but it assumes the reader has experience with other languages. (I see it gets introduced later on the page.) --KevinCole 21:35, 6 May 2010 (UTC)Reply

Return to "Java Programming/Integer variables" page.