nrg_alpha Posted December 28, 2009 Share Posted December 28, 2009 Oh my.. this is going to be an adjustment.. I can just tell You get so accustomed to one language's syntax, then when you start playing around in anothers, you're head is spinning around like in the Exorcist (minus the green spewing puke - maybe). I'm immediately thrown off by strings being objects as opposed to primitive types like int for example (yeah, I know you can use objects in place of those primitives too). I'm not sure why float types have to have the 'f' at the end of the value, like say float number = 4.67f for instance (you would think that simply 4.67 alone would suffice - at least I did)... Yep, it's going to be a bizarre ride initially for sure (buckles up). Should prove interesting to say the least! Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/ Share on other sites More sharing options...
premiso Posted December 28, 2009 Share Posted December 28, 2009 I've always enjoyed Java. Good luck with it! Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-984688 Share on other sites More sharing options...
Daniel0 Posted December 28, 2009 Share Posted December 28, 2009 Oh my.. this is going to be an adjustment.. I can just tell You get so accustomed to one language's syntax, then when you start playing around in anothers, you're head is spinning around like in the Exorcist (minus the green spewing puke - maybe). I'm immediately thrown off by strings being objects as opposed to primitive types like int for example (yeah, I know you can use objects in place of those primitives too). I'm not sure why float types have to have the 'f' at the end of the value, like say float number = 4.67f for instance (you would think that simply 4.67 alone would suffice - at least I did)... Yep, it's going to be a bizarre ride initially for sure (buckles up). Should prove interesting to say the least! It's because the standard data type for representing floating point numbers in Java is called double. If you want to use float, which has only got half the precision, you'll have to explicitly specify that. However, if you do something like this: float foo = 1.5; it will work as well. Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-984792 Share on other sites More sharing options...
.josh Posted December 28, 2009 Share Posted December 28, 2009 Oh my.. this is going to be an adjustment.. I can just tell You get so accustomed to one language's syntax, then when you start playing around in anothers, you're head is spinning around like in the Exorcist (minus the green spewing puke - maybe). I'm immediately thrown off by strings being objects as opposed to primitive types like int for example (yeah, I know you can use objects in place of those primitives too). I'm not sure why float types have to have the 'f' at the end of the value, like say float number = 4.67f for instance (you would think that simply 4.67 alone would suffice - at least I did)... Yep, it's going to be a bizarre ride initially for sure (buckles up). Should prove interesting to say the least! This has thrown me off, as well. I might make a small suggestion for you: learn javascript first. Or if you know javascript, think of javascript as the Rosetta stone between java and php. For me, learning javascript was a lot less painful because it is more directly web-oriented, but also has the Object-based programming (for example, that string-as-object thing you mentioned). IMO this makes javascript a great learning-bridge between someone going from php to something like java. Maybe that's just me, but dunno, maybe that might help. Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-984972 Share on other sites More sharing options...
nrg_alpha Posted December 28, 2009 Author Share Posted December 28, 2009 It's because the standard data type for representing floating point numbers in Java is called double. If you want to use float, which has only got half the precision, you'll have to explicitly specify that. However, if you do something like this: float foo = 1.5; it will work as well. Yeah, the Sun Java tutorial mentions not using floats for precision values (turns out apparently even double data types should not be used for precision [in this case, they keep referring to currency as an example] - there is a java.math.BigDecimal class for that purpose) For your example, I think you mean double foo = 1.5; (when delcaring a float type, it requires 'f' postfixing to the value). This has thrown me off, as well. I might make a small suggestion for you: learn javascript first. Or if you know javascript, think of javascript as the Rosetta stone between java and php. For me, learning javascript was a lot less painful because it is more directly web-oriented, but also has the Object-based programming (for example, that string-as-object thing you mentioned). IMO this makes javascript a great learning-bridge between someone going from php to something like java. Maybe that's just me, but dunno, maybe that might help. Yeah, I did dabble a bit in javascript a few years back, but I don't really know it enough to be able to say I'm comfortable / knowledgable with it. Perhaps as I learn java more, when I look at javascript, it will be more familiar? Speaking of familiarity, I am noticing that java isn't totally foreign.. for, do-while loops, ternary operators, switch statements and the like seem to be pretty much like PHP's. So at this stage in the game, it's more or less getting to know java's nuances. Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-984998 Share on other sites More sharing options...
.josh Posted December 28, 2009 Share Posted December 28, 2009 right. you can certainly use java as a bridge to javascript just the same. Was just throwing that out there that since you know php you could go from php to javascript to java. Dunno your situation but in general javascript may be more useful to you, since it's more directly involved in web development. because it is more directly involved in web development, you should pick up on the underlying structure (like the DOM) and point faster. As you learn the DOM, you learn the things like string-as-object and then those will carry over to learning java, which is a much broader "stage" than just web development. My theory is that you'd learn javascript faster than java because you already know php, so use that as a stepping stone to java. Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-985020 Share on other sites More sharing options...
Daniel0 Posted December 28, 2009 Share Posted December 28, 2009 It's because the standard data type for representing floating point numbers in Java is called double. If you want to use float, which has only got half the precision, you'll have to explicitly specify that. However, if you do something like this: float foo = 1.5; it will work as well. Yeah, the Sun Java tutorial mentions not using floats for precision values (turns out apparently even double data types should not be used for precision [in this case, they keep referring to currency as an example] - there is a java.math.BigDecimal class for that purpose) For your example, I think you mean double foo = 1.5; (when delcaring a float type, it requires 'f' postfixing to the value). Hmm... yeah, this will work: daniel@daniel-laptop:~/test$ cat Test.java public class Test { public static void main(String[] args) { float foo = (float) 1.5; System.out.println(foo); } } daniel@daniel-laptop:~/test$ javac Test.java daniel@daniel-laptop:~/test$ java Test 1.5 To be honest though, just use double instead of float. Floats and doubles are only approximative data types anyway. Here is a funny example illustrating this: - load "Math"; > val it = () : unit - val x = Math.log10 1000.0; > val x = 3.0 : real - floor 3.0; > val it = 3 : int - floor x; > val it = 2 : int - x = 3.0; > val it = false : bool That is in Standard ML, specifically the MoscowML implementation. The "bug" is that it computes log(1000) to 2.99999999...9 (lots of nines) and rounds it for display, but when I ask it to floor the number, it correctly rounds down to 2.0. Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-985063 Share on other sites More sharing options...
nrg_alpha Posted December 28, 2009 Author Share Posted December 28, 2009 Ah, I noticed the type casting in your example... when I tried that, it worked (so I stand corrected). To be honest though, just use double instead of float. Floats and doubles are only approximative data types anyway. Yeah, I read that the general tendancy is to use double for decimals (so I won't complicate matters and simple stick with that). Was just thrown off by the float types (which my understanding now is that even with float data types, assigned literals are treated as double types by default - f (or F) treats literals as floats). So much stuff to learn... [ot]Come to think of it, I can only guess that the f part in the value is some form of shorthand typecasting (as opposed to using (float) )?[/ot] Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-985097 Share on other sites More sharing options...
Mchl Posted December 28, 2009 Share Posted December 28, 2009 Hey nrg... coincidentally I've just started my own venture into Java two days ago I actually had some previous exposure to it, but this time I want it to be serious Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-985131 Share on other sites More sharing options...
.josh Posted December 28, 2009 Share Posted December 28, 2009 omg now I wanna learn it too let's start a study group??!?!?!?! Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-985132 Share on other sites More sharing options...
Mchl Posted December 28, 2009 Share Posted December 28, 2009 CV and Java... hmm... public class Zombie extends Undead implements Infectious { public static void main(String[] args) { while(true) { new Zombie(); } } } Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-985137 Share on other sites More sharing options...
Daniel0 Posted December 28, 2009 Share Posted December 28, 2009 The university decided that I wanted to learn Java, so well.... Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-985138 Share on other sites More sharing options...
nrg_alpha Posted December 28, 2009 Author Share Posted December 28, 2009 Hey nrg... coincidentally I've just started my own venture into Java two days ago I actually had some previous exposure to it, but this time I want it to be serious At least you had some exposure to it.. That must help out somewhat, I'd wager. As for me, I'm venturing in blind. It's like anything else though.. repitition is the mother of all skill.. so I just have to keep at it.. It's already starting to feel more 'natural' (which can't be a bad thing). omg now I wanna learn it too let's start a study group??!?!?!?! lol smartass. The university decided that I wanted to learn Java, so well.... Is it beneficial to your education to learn Java? (I suppose learning new languages never hurts, but I mean given the employment goals afterwards) Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-985141 Share on other sites More sharing options...
Mchl Posted December 28, 2009 Share Posted December 28, 2009 I decided on my own that I wanted to learn Java when on university. But the teacher was so underqualified for this, that I dropped out of this course. The guy actually wanted us to search the web for some ancient (like 1.1 ?) version of Java DK, because he considered it 'better' than newer versions. Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-985142 Share on other sites More sharing options...
Daniel0 Posted December 28, 2009 Share Posted December 28, 2009 The university decided that I wanted to learn Java, so well.... Is it beneficial to your education to learn Java? (I suppose learning new languages never hurts, but I mean given the employment goals afterwards) Well, I don't really think so. As it is right now, I have no aspirations of working in the industry unless I can get something that's more focused on theory. It's the language they chose to use for their "Object Oriented Programming and Design" course so I don't have a choice either way right now. Personally, I don't like Java. It seems way too over-engineered. Want to read lines from a file and write lines to a file? public ArrayList<String> getLines(String filename) throws FileNotFoundException, IOException{ ArrayList<String> lines = new ArrayList<String>(); BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(filename))); while(reader.ready()) { lines.add(reader.readLine()); } reader.close(); return lines; } public void saveLines(Collection<String>, String filename) throws IOException { File file = new File(filename); if (!file.exists()) { file.createNewFile(); } BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); for (String s : lines) { writer.write(s + "\n"); } writer.close(); } I suppose it's "good design" or whatever, but it doesn't make it less tedious having to write half a book each time you want to do something. Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-985149 Share on other sites More sharing options...
corbin Posted December 30, 2009 Share Posted December 30, 2009 The situation in which I most often find my self going for Java is when I need something to have multiple threads. Threads in C++ still scare me . I think the weirdest part of going from PHP to Java is that almost everything is an object in Java. Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-985826 Share on other sites More sharing options...
Mchl Posted December 30, 2009 Share Posted December 30, 2009 The situation in which I most often find my self going for Java is when I need something to have multiple threads. Threads in C++ still scare me . They make me want to puke. Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-985938 Share on other sites More sharing options...
cags Posted December 30, 2009 Share Posted December 30, 2009 All C++ has that effect on me! Quote Link to comment https://forums.phpfreaks.com/topic/186476-starting-to-dip-my-toes-into-java/#findComment-985939 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.