who taught you

To expand on Kev’s post,

public class Demo
{
    public void printInt(int i)
    {
        System.out.println("" + i);
    }
}

produces bytecode (as disassembled by javap -c)

public class Demo extends java.lang.Object{
public Demo();
  Code:
   0:   aload_0
   1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
   4:   return

public void printInt(int);
  Code:
   0:   getstatic       #2; //Field java/lang/System.out:Ljava/io/PrintStream;
   3:   new     #3; //class java/lang/StringBuilder
   6:   dup
   7:   invokespecial   #4; //Method java/lang/StringBuilder."<init>":()V
   10:  ldc     #5; //String
   12:  invokevirtual   #6; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
   15:  iload_1
   16:  invokevirtual   #7; //Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
   19:  invokevirtual   #8; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
   22:  invokevirtual   #9; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
   25:  return

}

Or, to rephrase that as Java for those who don’t read bytecode, it is translated to

public class Demo
{
    public void printInt(int i)
    {
        StringBuilder sb = new StringBuilder();
        sb.append("");
        sb.append(i);
        System.out.println(sb.toString());
    }
}

That was compiled with 1.6: pre-1.5 it would indeed use StringBuffer rather than StringBuilder, which was even slower.

kingaschi, in Sun’s implementation the String.valueOf(primitive) methods call the Primitive.toString(primitive) methods. (Well, to be precise, String.valueOf(int) calls Integer.toString(int, int)). It’s possible that third party implementations have it the other way round. In nearly every circumstance which you choose is a matter of taste.

Why should everyone learn C++? I didn’t learn it at university, and I don’t think I missed out. I have done a small amount of C programming (a summer internship in which I learnt enough C and Win32 to write a diagnostic tool for a networking company), but at university I learnt a functional language (SML), an OO language (Java), an assembly language (ARM), and a hardware description language (Verilog). I also studied various mini languages to cover key concepts in type theory, wrote a few Turing machines and lambda calculus expressions, and was whizzed through 12 languages in one lecture each (actually C++ may have been covered there. C wasn’t, but BCPL was).

I don’t think saying “everybody should know language X” is useful (or even sane). As long as you’ve got some knowledge in the various different areas like pjt33 mentions it’s all good. Personally I don’t think C++ is particularly good from a learning point of view - it’s a low level language pretending to be a high level language which makes for a very inconsistant and difficult learning environment. You’d be much better starting out with C to focus on the low level and something like Java for the high level, where you can just deal with one lot of concepts at a time (IMHO, YMMV, TTFN).

And by the way - C is still frequently used today. All of the Halo games were written in pure C, for example, and every iPhone/Apple program is built on C, even though it’s their own wacky Objective C you actually use, it’s basically just C with a few extra bells and whistles.

I knew the C++ comment would draw some fire. :slight_smile:

I don’t know, I think we may have to agree to disagree. The way I see it, C/C++ is far too ubiquitous in the world of programming - particularly game programming - to justify not picking up at least a basic knowledge of it if you’re serious about the trade (which is all I’m suggesting, that a programmer be able to do simple things and not just give up the moment they see a -> or &).

I’d say the same thing about Java, that regardless of its relative merits, it’s just too common a language to not have at least a superficial proficiency in it.

BTW, though, we may be arguing across each other: I think the level of exposure that pjt33 has had is fine, better than that, even - most people have almost zero exposure to non-OO or imperative languages; I’m not saying everyone should be a C expert, just that they should have had to create some non-trivial programs at one point or another so they know what it’s all about.

[quote]Personally I don’t think C++ is particularly good from a learning point of view - it’s a low level language pretending to be a high level language which makes for a very inconsistant and difficult learning environment.
[/quote]
Absolutely agreed. It’s nasty stuff sometimes, and it’s possibly the worst first language to learn thanks to the complexity and the quirks (err…scratch that: I just remembered that Haskell exists). But its utility is not pedagogical, it’s practical.

Fair enough. I’d say basic C++ is still eventually worthwhile, though, because eventually you’re likely to run into a situation where you need to write some code and you can’t do it in Java (for instance, if a client refuses to accept Java, which describes a project I’m working on right now), and C++ is going to feel a lot closer to home from a big picture design perspective than C will!

Maybe I’m a little biased, though, because I work random contracts from random clients, so knowing the languages that clients usually require (VBA, C++, and Java, in roughly that order - YMMV if you’re not doing financial stuff) greatly increases my chances of finding work…

That’s actually more true than I thought - http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html ranks C above C++. But I don’t think it makes much sense to learn pure C to the exclusion of C++, since IMO the “++” adds quite a bit of useful stuff that’s quite commonly encountered in in the wild. Anyone that knows C++ can understand C perfectly, but the converse does not hold. Besides, even when writing straight up imperative code, the things C++ adds to C make things a lot more pleasant.

BTW, you can use C++ on the iPhone - I use as much C++ and as little Objective C as possible - you just name things .mm instead of .m. It’s not perfectly interoperable with Objective C, though, and the quirks are pretty arbitrary, so unless you want to drive yourself nuts you’ll want to draw pretty strict boundaries between the Objective C sections and the C++ ones.

Hm, I didn’t think C++ worked on the iPhone, I thought it just worked on Cocoa.

Good to know, at any rate.

wow that was like an essay. :slight_smile:

Welcome to java-gaming.org.

Some fun things I’ve seen at work.

new Float(myModel.getMyFloatValue()).intValue()
String myString = "test";
String mySecondString = myString.toString();
if (status == null) {
    throw new IllegalArgumentException("Invalid status: " + status);
}

// Json

Which is why, the only formal programming classes I had, were in PASCAL (yes yes, I’m old). What I found nicest about the language is the way it helped students ease their way into understanding global variables, nested loops and procedural code. Most of that went out the window when we hit C++ and Java, but, back in the day, I found it to be pleasant and easy to understand.

Now, try doing Paradox scripting if you want to lose your marbles.

I did that completely backwards ;D

language is just a tools, there are severals languages but few programming methods.

there is absolutly no interrest on learning all object/method/function of a language.

taking only the “core” (not the external libraries) of a language you can convert most of it to another language just by doing a search and replace when the “programming method” is the same : OO to OO, procedural to procedural, declarative to declarative, etc…

ex:
C++ => JavaScript
C++ => Java
Pascal => C
HTML => XML
etc…

the only thing to learn is “programming method”, and for the language itself just need to get a good reference book or nowaday simply internet…

I learned the programming method and all.

I just figured it out after I learned how to program in java.

before I was scrapping programs and making others.

I certainly agree with the point you’re making, but JavaScript is vastly different from C++ and the two have nothing in common except a similar syntax

Heh heh heh, that’s great.

now that I read those, that is funny ;D

[quote]Some fun things I’ve seen at work.
[/quote]


if(!!true)
{
   ...
}

::slight_smile:

I wish all new students in Java college classes wouldn’t have to deal with public static void main(String[] args) until the 2nd trimester.

I honestly think the best way to learn Java is to have 2 lessons of Javascript first. :persecutioncomplex:

[quote]except a similar syntax
[/quote]
that’s the point

in this case you can say that Java doesn’t have anything related to JavaScript too except a similar syntax, for exemple in case of OO, if you are able to grab all existing classes and their methods in a “non-specific datastructure” you can then export them to another language like :

C++


Test::Test()
{
 value=0;
}

void Test::setValue(double val)
{
	value=val;
}

non-specific :

class : Test
method : setValue
attrib : value

JavaScript

function Test()
{
 this.value=0;
 this.setValue=setValue;
 function setValue(val)
 {
  this.value=val;
 }
}

this is the same thing but ordered/aranged differently

I thought your point was that syntax doesn’t matter at all, but programming paradigms do matter. Well, that’s the point I wanted to agree with at least :slight_smile:
JavaScript works radically different from C++, with closures, prototypal inheritance, no classes, and a different concept of the keyword ‘this’.

yes, I just mean that the logic is the same between same kind of languages. inded they are differents in some ways… javascript have also some kind of meta capabilties with eval(something) but in “the big lines” (very big if you wich) they work using the same logic. but ok I agree Javascript <=> C++ is an extrem sample :slight_smile: