This excerpt from “Thinking In Java” shows you how to use operators and execution control statements. It covers precedence, assignment, regular expressions, relational and logical operators, and short circuiting. You’ll learn to use Java’s execution control statements, including loops and switches. More programming articles, more operating system articles at InformIT.
Controlling Program Flow in Java
About The Author
Eugenia Loli
Ex-programmer, ex-editor in chief at OSNews.com, now a visual artist/filmmaker.
Follow me on Twitter @EugeniaLoli
39 Comments
I will attack any platform owned by one company that lies about it’s qualities.
I like these comments from a pretty good programmer.
http://www.research.att.com/~bs/bs_faq.html#Java
why java sucks.
http://www.jwz.org/doc/java.html
enjoy.
“This is why the fellow earlier was attacking your knowledge. Not because you criticised Java, but because you clearly have a “one size fits all” attitude, and think your chosen language is best in domains it is entirely unsuited for, and are willing to (hilariously) attack and denigrate a platform for laughable reasons, as in your first post.”
Quite. Personally I wouldn’t say that Java is the be-all, end-all of languages or that I even consider it to be a good language. It has its flaws, it has its ups, and it most certainly can be put to good use. Can’t say that that would be a good definition of something that “sucks”.
“Mr. Sappens . Is java used outside of E-commerce ???? Not really. I can’t think of any good client side programs. Java applets suck period. Slow.”
Putting “Java applets” == “Java client side programs” just shows Mr.Martin’s laughable lack of knowledge of Java. So far I haven’t seen a single coherent and thought through argument coming from him. The “XYZ sucks” argument is rather a typical denotation that we’re dealing with someone best left ignored.
The article posted was about programming constructs in the Java language. Why is it that everytime a post concerning Java appears on OSNews, the anti-Java zealots come out and bash the language? No one is claiming Java is the be all end all. It just works for the majority of programmers out there.
If you don’t like it, don’t use it. Not everyone is a lemming, using Java just because everyone else does, or because Sun tells them to.
Java is not the language for you if you love :
– template meta programming.
– spending hours trying to write exception safe code.
– tracking down memory leaks (yes, this is an issue for the majority of C++ programmers).
– moaning about how slow Java is. [url]http://www.aceshardware.com/read.jsp?id=153%5B/url], [url]http://www.javalobby.org/members/jpr/index.jsp%5B/url] provide benchmarks that show how fast/slow Java is. Evaluate it yourself and see if Java’s speed meets your standards. For most people, it is fast enough. Limewire runs fine on a PII 300 Mhz with 64 MB ram.
I’m sure you can come up with more reasons.
LOL
C++ is your response to this? Python? Give me a break! If written *correctly* (as in maintainable, extensible, etc…) then C++is just as verbose as Java. C++ (or some form of C, Objective C) is still the best platform for GUI development (or in some cases VB front ending C++).
But on the server Java wins hands down in terms of features.
And as for your link as to why java sucks – it’s mostly old news (copyright 2000? give me a break). Write once run anywhere IS true for server code now.
Alot of the rest of the stuff in there either
1) has been addressed
2) is being addressed in the next release (autoboxing primitives for instance)
OR
3) is just whining that he can’t write code the exact same way in a different language
Most of his complaints are just amateur hour stuff. Frankly I question the sanity of anyone who prefers multiple inheritance over interfaces.
Much of the relative simplicity of Java is – like for most new languages – partly an illusion and partly a function of its incompleteness. As time passes, Java will grow significantly in size and complexity. It will double or triple in size and grow implementation-dependent extensions or libraries. That is the way every commercially successful language has developed. Just look at any language you consider successful on a large scale. I know of no exceptions, and there are good reasons for this phenomenon.
Certainly individual projects can become dependant upon libraries. But the nice thing about Java is that there are generally open source alternatives for the core features. So even if you get stuck with a vendor on one project – when starting a new project you will have plenty of alternatives (some even free).
But as to how “Java” the language will become dependant upon third party libraries (ie. not Sun) I just don’t see what he is getting at.
Java isn’t platform independent; it is a platform. Like Windows, it is a proprietary commercial platform. That is, you can write programs for Windows/Intel or Java/JVM, and in each case you are writing code for a platform owned by a single corporation and tweaked for the commercial benefit of that corporation.
Sun has no clue how to make money on Java. They gave up control of the language to the JCP.
For the record, C++ is a good example on how not to design a language. So maybe comments from a C++ advocate about language design should be taken with a few grains of salt.
All these languages overlap as far as where they can be used, but each is best at something different. C might be the language of choice for kernel mode programming, C++ for user mode system programming and high-performance client side programming, Java for enterprise apps. So these “sux/rulez” type arguments don’t make much sense to me.
Some of us think C++ is a damn impressive language.
I hate it when people include a 40-50 line code sample to prove a point when a 5-10 line code sample would suffice.
I agree too. I hate it when an author (generally speaking) feels it necessary to use 30-40 page code example just to illustrate the use one damn function.
My feeling is that if it can be done in 5 lines of code, then do it. I don’t need you to show me a fully loaded program with this function in it – if you show me the syntax and a couple of SHORT code examples, I can figure out what to do with it from there.
Hi all!
I need of some sources of a intranet app in Java. Someone can help me?
Michael VinÃcius de Oliveira
~ BlueEyedOS.com Webmaster ~
Scheme, Ruby (and C) are my preferred programming languages. I have heard good things about Objective C. I find Java and C++ way too dense and obfuscated.
download the book here for free
http://www.mindview.net/Books/TIJ/
I will check scheme out. I know of ruby .
I am interested in haskell too, maybe clean.
If you like scheme, here’s a bunch of video lectures some people seem to like:
http://www.swiss.ai.mit.edu/classes/6.001/abelson-sussman-lectures/
BTW, there are a number of schemes (more than 3) that compile to the JVM.
Fairly good book on Java. I was able to pick it up pretty easily. Many of his examples do go on the long side for simple ideas. Luckily our instructor removed some of Bruce’s cruft and did his own presentation based on it. I always pictured Java to be mostly a GUI language but this book gives you all the basics leading up to the GUI stuff. Not till the last 1/3 of the book do you get into the GUI stuff. Helps if you’ve already been intruced to data structures before jumping into this.
I once downloaded this book of the author’s website to learn Java after I left C++. It’s a very good book. I was about to buy it when I suddenly turned my back to programming. I haven’t done any sort of programming for the last few years and I was very good at it.
should we just start programming in assembly now?
See that’s the problem with java. we have to go back optimizing crap on a freaking jvm
What the hell are you talking about? It is an article about operators and control statements in java, nothing to do with optimising anything.
i learn a great deal of java from this book. quite nice and covers almost all the bases. anyway, you can download the ebook version of this somewhere…:)
Thinking in Java is a great book.
I used the 2nd edition when I migrated from Delphi to Java, and it was a great help in understanding the differences (and similarities) in the languages.
I highly recommend Thinking in Java to anyone wanting to learn Java or brush up on their Java skills.
I hadn’t done any “professional” Java in a couple of years when I got a contract working on some in-house Java applets for a local company. I ran out and bought the second edition of “Thinking in Java” and read it cover-to-cover (some before the contract started, the rest during the contract). Needless to say, my Java skills quickly came back to me, and I learned a whole lot more.
My advice to any developers interested in writing Java professionally, buy this book. You won’t regret it (and if you own your own company, you can write the cost off of your taxes 🙂
Bruce Eckel’s Java book is great who wants to learn Java. I have c, c++ bakground and jumping into Java was not much of an issue. Just going thru the book helped me a lot.
80% of the development in enterprise is done in Java Platform. Java is great platform to develop highly scalable apps. I think Java is the replacement for cobol in the enterpise world.
There are great open source IDE’s like netbeans, jedit and eclipse out there to do coding with in Java.
Some open Appservers are TomCat, JBoss, JoAns,
I thought the whole book is available at Bruce Eckels’ personal site, as with his other books, too.
Yep, it’s there. go to:
http://www.bruceeckel.com
Then select the “Books” link and follow the links.
I think Java is the replacement for cobol in the enterpise world.
This is exactly right. It’s exactly the approach many companies (including my employer) are taking to the point of taking their COBOL jocks and retraining them to varying degrees of success. Those of us at my company who are doing desktop development where performance is paramount (currently in Windows) are using C++, Delphi or even VB 6. While I’m impressed with the .Net IDE and some of its integration features, the idea of intermediate code JIT’ed to machine code being as fast as native EXEs (or faster as I have read some claim) seems bogus to me for either .Net or Java.
What we’ve discovered is that it takes a powerhouse machine (2Ghz+ with 1GB RAM) to run our Java dev platform (WebSphere) and better workstations in the company (1GHz+ with 512MB RAM) to run any app deployed directly on the desktop. For a company with 19000+ PCs deployed worldwide, this means a major hardware investment for new application rollout.
YMMV.
I hate it when people include a 40-50 line code sample to prove a point when a 5-10 line code sample would suffice. Sure, sometimes it is nice to tie a series of examples together and that requires extra code. But, come on! I don’t want to dig through a bunch of fluff to see what you’re getting at. Bitter Java (reading it now) is a good book but is terrible in this regard. I have mostly given up reading the code examples.
Lots of good points.
As for IDEs, I’ve used JCreator Pro and now use GEL (freeware written in Delphi) as my Java IDE on Windows.
All of our coding is server side, and it is great. Runs on “old” hardware (PIII 733)
Java has little use on my puter since its a pII 266 with 32 megs.
I will say this about Java , it’s competing with MONOPOLYSOFT . So that’s a good thing.
As for the language, its way to verbose. Too complex.
Virtual machine is ofcourse crap. But what did you expect from a company that makes supercomputers with no worries about desktops.
The SUN story of how they got a strangle hold on the enterprise market and had the stupid java VM’s got put on everyones computer through software package is the real mystery.
I theorize it can be only one thing. BIG LIES by SUN and it succeeded. Good job guys.
Sun by the way is trying to get out of the computer company and get in on the hype and commerce of java.
It’s sad to see we use this language because ONE computer company demanded we use this revolutionary language.
If you want to see speed , check out http://www.rapideuphoria.com . They got a fast language there. not complex at all.
An aol user bashing Java for being slow and verbose. Now there’s something funny.
Uhm…since VMs are “crap”, SUN got a “strangle hold on the enterprise market”, and Java is pushed by ” ONE computer company” I got only two questions for you.
1. What drugs are you on?
2. Would you mind hsaring some to the rest of living in the real world?
I’ll add two requests too.
1. You desperatly need education when it comes to CS as you’re extremely uninformed judging by your comment.
2. If you got a problem with XYZ, either put forth some constructive criticism or make something better yourself.
The SUN story of how they got a strangle hold on the enterprise market and had the stupid java VM’s got put on everyones computer through software package is the real mystery.
It is not remotely a mystery. It is perhaps a mystery to teenagers in their bedrooms who want to write 133t c03ds0r, man, but there are in fact many solid reason why Java has become #1 choice for the serverside.
1 – real transactional behavior — Does your language of choice support cross DB transactions (meaning, I need a transaction that spans the legacy mainframe RDBMS and the new Oracle DB just installed for new project X), transparently, and without the need to code begins, commits, and rollbacks?
2 – clustering — Can your language of choice seemlessly execute across 5 different servers, with objects floating between according the app server’s balancing scheme, the whole thing remaining fully functional even if you kick the power out of 4 of those machines?
3 – security abstraction – can you define security/authorization roles at deploy time, without relying on a programmer who “thinks” he understands security to develop some secure code for you?
4 – resource pooling — does your language of choice automatically figure out how to efficiently allocate resources such as DB connections without your programmers needing to write some half-witted pooling code themselves?
Granted, you could build all of these features into an app server around ANY language. BUT IT HASN’T BEEN DONE YET, except for EJBs and Microsoft’s offering. Sorry. Your languages just don’t offer these features yet. As such, they ARE NOT FIT FOR THE ENTERPRISE. Do you think a 45 Billion in asset bank is going to trust a team of 4 programmers to write code that handles million dollar financial transactions without these features?
And sure, “good programmers can write all this stuff themselves.” They can code transactions. They can code security. Yes. So? All that stuff adds to development time, is less trusted by management, and therefore costs exponentially more.
Anti-Java zealots can dismiss this as “hype” as much as they like, it doesn’t change the fact that when it comes to the enterprise, you have two choices: Java and .NET. No other languages or platforms exist for this arena with anything like these features. Java is better than .NET for the serverside, and .NET is better than Java for the client side, in most situations for most companies. Your c++, perl, python, assembler, and “Euphoria” are utterly useless for this field, for the majority of business, real world programming.
i wonder how anything was accomplished before java.
Thank god we have this language that can do everything for us. We don’t need to program anymore.
Your right C++ and python could never do what java does. What was anyone thinking.
Score another one for Sun/al-queda brainwashing !
Sure. I remember when it took 10x longer to write enterprise applications, cost 10x more, and was full of root holes and bugs once done. This strong memory is why companies are moving to Java, and now .NET.
You didn’t answer my questions, because you have no answers, and no alternative.
comments that portray anyone that doesn’t care for java as uneducated and stupid is in itself stupid.
Java is a slow and cruddy language.
Glad you like it. I prefer C++ and python over java.
Tell me where all the java applications are for client side mr friggens ? Guess its not the be all is it ?
Your c++, perl, python, assembler, and “Euphoria” are utterly useless for this field, for the majority of business, real world programming.
Um no, Python compiles to the JVM. Jython’s sold as a “RAD” tool in these projects.
Java is a slow and cruddy language.
Irrelevant. On the serverside, JITs compile it to optimized native code.
Tell me where all the java applications are for client side mr friggens? Guess its not the be all is it?
No one claims now that Java can break Microsoft’s desktop dominance. Only LimeWire and IDEA come to mind as highly-polished apps. But if you’re using languages to make up for your inadequacies as a programmer, you’re in trouble. Great clientside programs can be made in Java, it’s just harder than with .NET.
Here’s some
http://directory.google.com/Top/Computers/Programming/Languages/Gar…
I like eiffel ,ada, maybe one of the modulas over java.
Mr Sappens , do you think Sun added some of those specifications to the language just for serverside e-commerce . Yes they did. Because Sun knows it’s market and where java is really used.
Mr. Sappens . Is java used outside of E-commerce ???? Not really. I can’t think of any good client side programs. Java applets suck period. Slow.
Don’t you think thats the problem with java ? It’s one dimensional.
If Python for example were owned by a company targetting E-commerce don’t you think you would see some of those features in it? hmmmmm.
C++ and python can do alot of things faster and better than java and not just a few things for e-commerce, although they could.
personally, i am glad Sun succeeds with java in e-commerce and not monopolysoft.
I am not 100% negative on java. I am with a alot of people about the slowness and complexity,verbosity of the language.
But if it succeeds for e-commerce and is productive for you then i think thats good.
But i do always want ALTERNATIVES so one language is not forced down our throats by academia or workplace. We need competition.
Here’s some