PDA

View Full Version : Java - Useful or not


linuxguymarshall
July 11th, 2009, 03:30 PM
I personally find Java to be a slow and complex language when compared to other languages like C++. I find a lot of people that disagree with me but find an equal amount that do agree. So, what are your thoughts on Java?

Joeb454
July 11th, 2009, 03:32 PM
I agree that it can be slow - depends on the application I guess.

Though I wouldn't say it's that complex

Simian Man
July 11th, 2009, 03:38 PM
Most of the reason Java seems slow is the ugly and slow Swing gui library that many applications use.

If you think Java is more complex than C++, you must not know C++ very well!

RiceMonster
July 11th, 2009, 03:44 PM
If you think Java is more complex than C++, you must not know C++ very well!

That's what I was thinking.

linuxguymarshall
July 11th, 2009, 03:48 PM
If you think Java is more complex than C++, you must not know C++ very well!


It's not that I know C++ too well but I guess it just makes sense in my head whereas Java does not.

Redache
July 11th, 2009, 04:16 PM
It's So-So. Java is meant to be an Improvement on the concepts of C++ and it does in certain areas. I guess it depends on what you want to do. Java is usefull for Portable Applications wheras C++ is useful for nearly every application barring simple programs (Something less Intense would probably be better for that).

ddrichardson
July 11th, 2009, 04:31 PM
C++ which is really a bit of a fudge of OOP principles shoehorned into C. A lot of people detest C++ (Linus Torvalds in particular - he was quite vocal here (http://lwn.net/Articles/249460/)). It depends what you want to do - I studied it fervently at university but haven't really used it since.

I don't think any of us really believes that anything and everything should be done in one language. I model a lot of stuff in Java but then I'm an engineer and it offers good encapsulation and data hiding plus as far as code reuse goes it makes more sense to me, interfaces are also very useful when looking at systems rather than creating applications.

By the same token if I want to do something for the desktop I like Python and I do prefer PHP for web stuff.

Pegs and holes.

linuxguymarshall
July 11th, 2009, 04:46 PM
C++ which is really a bit of a fudge of OOP principles shoehorned into C. A lot of people detest C++ (Linus Torvalds in particular - he was quite vocal here (http://lwn.net/Articles/249460/)). It depends what you want to do - I studied it fervently at university but haven't really used it since.

I don't think any of us really believes that anything and everything should be done in one language. I model a lot of stuff in Java but then I'm an engineer and it offers good encapsulation and data hiding plus as far as code reuse goes it makes more sense to me, interfaces are also very useful when looking at systems rather than creating applications.

By the same token if I want to do something for the desktop I like Python and I do prefer PHP for web stuff.

Pegs and holes.
Well said, thanks for that input

Gucko
July 11th, 2009, 04:49 PM
C++ which is really a bit of a fudge of OOP principles shoehorned into C. A lot of people detest C++ (Linus Torvalds in particular - he was quite vocal here (http://lwn.net/Articles/249460/)). It depends what you want to do - I studied it fervently at university but haven't really used it since.

I don't think any of us really believes that anything and everything should be done in one language. I model a lot of stuff in Java but then I'm an engineer and it offers good encapsulation and data hiding plus as far as code reuse goes it makes more sense to me, interfaces are also very useful when looking at systems rather than creating applications.

By the same token if I want to do something for the desktop I like Python and I do prefer PHP for web stuff.

Pegs and holes.

Yeah this is exactly what I wanted to say. Java is great for OOP. I don't think any good computer engineer would limit him self to a language. You use what suits your project. That's it.

Don't listen to people who just criticize other languages. These kind of people just want to convince themselves from time to time that they chose the right language.

Really if you can program in one language, you can learn others easily. I'm a computer engineering student and I faced many people that have this problem.

I would suggest to start learning C then learn Java or Python.

Blacklightbulb
July 11th, 2009, 04:50 PM
Depends on what your gonna use it onto. Besides it's improving and it's easy to program with than C++ (unless you already spent 10 years programming in C++).

Please don't start this stupid debate another time.

ddrichardson
July 11th, 2009, 05:03 PM
Well said, thanks for that input
I'm not sure if your being sarcastic or not here but another part of the issue is that generally speaking I don't find myself writing code from scratch very often now, especially since the advent of OSS.

More often than not, I tend to be addressing a bug, adapting something or adding to an existing codebase, in which case my language preference isn't really relevant, which increases the essentialness of developing a sound understanding of programming theory and a familiarity of common languages.

In fact, its not just languages you need - its documentation systems, UML modelling systems and version control systems. I love bazaar now but this time last year I hated it, purely because I was more used to git and subversion.

ghindo
July 11th, 2009, 06:46 PM
A lot of people detest C++ (Linus Torvalds in particular - he was quite vocal here (http://lwn.net/Articles/249460/)).To be fair, Linus isn't exactly a shrinking violet.

lisati
July 11th, 2009, 06:58 PM
Why not use the tools you know?

I'm not well versed in C but could probably cobble together a small project if I had ready access to some kind of book and/or online tutorial and if I had to do so.

I've got even less experience with programming in C++ and Java (close enough to zero experience that it makes no real difference), so I'm probably not qualified to comment on either language, beyond saying that they're currently out of my comfort zone for creating a project. From what I've seen of both, C++ in particular, a polite reaction would be "No thanks!"

The most recent programming project I've done for someone else (a few years back now) was done using a mixture of compiled Basic and assembler, for an MS-DOS system. Not the flashest of efforts, but once I had taken care of a potentially major stuff-up (due to an unwarranted assumption about the other person's hardware) it worked.

ddrichardson
July 11th, 2009, 07:44 PM
The most recent programming project I've done for someone else (a few years back now) was done using a mixture of compiled Basic and assembler, for an MS-DOS system. Not the flashest of efforts, but once I had taken care of a potentially major stuff-up (due to an unwarranted assumption about the other person's hardware) it worked.
I feel your pain, I had to use power basic a while back with assembler to measure a transistor's characteristics. It was unpleasant, you forget about low level stuff like timing, especially where there's latency in some components.

Sublime Porte
July 11th, 2009, 11:15 PM
ddrichardson,

interfaces are also very useful when looking at systems rather than creating applications.

It's interesting you say this. I've just been studying interfaces in my course, and I couldn't really understand what interfaces are useful for. Our lecturer was only able to tell us that if Java had multiple inheritance, then interfaces wouldn't be required. So from what I understood they're a replacement for a feature that Java doesn't have. Since you can implement many interfaces, but only extend one class.

Can you give me any other angle to look at interfaces from? As I'm seriously struggling to understand what useful purpose they serve (apart from making up for the single inheritance factor).

shadylookin
July 11th, 2009, 11:42 PM
Well you can program plenty of things in it. It has it's ups and downs like every other language. It's definitely not worthless.


ddrichardson,



It's interesting you say this. I've just been studying interfaces in my course, and I couldn't really understand what interfaces are useful for. Our lecturer was only able to tell us that if Java had multiple inheritance, then interfaces wouldn't be required. So from what I understood they're a replacement for a feature that Java doesn't have. Since you can implement many interfaces, but only extend one class.

Can you give me any other angle to look at interfaces from? As I'm seriously struggling to understand what useful purpose they serve (apart from making up for the single inheritance factor).

an interface is like a contract. When you say a class is going to implement an interface you're saying it will have that interface's methods. You need them because java is strongly typed


interface animal{
void noise();
}

class duck implements animal{
void noise(){
quack();
}
}

class bear implements animal{
void noise(){
growl();
}
}

class run{
public static void main(String args[]){
animal myanimal = new duck();
myanimal.noise();//quacks
myanimal = new bear();
myanimal.noise();//growls
}

in a dynamic language like python this is unnecessary you could just have


class duck:
self.noise():
quack()



class bear:
self.noise():
growl()


def makeNoise(animal):
animal.noise()

makeNoise(new bear())//growl
makeNoise(new duck())//quack

johnb820
July 11th, 2009, 11:53 PM
C++ is a hack language meant for hacks! It's meant to be useful to do anything and everything, nothing of which is ever very simple once you have built something even remotely complex all of which derived from a language that is not object oriented. Java is simple, elegant, logical, but hackish under the hood and slightly limiting.

Sublime Porte
July 12th, 2009, 12:56 AM
shadylookin,

Thanks for the example. Yes I know how it works, I just don't see the point to it.

An interface is basically just a limited form of an Abstract class (ie. only constants and abstract methods), but it's redeeming point is that you can implement many of them, instead of just one, like with Abstract classes.

So what I really want to know is, what is so great about an interface, other than the fact it's a limited replacement for multiple inheritance, which is about the only thing that seems to make it any different/better than an abstract class.

Btw,

makeNoise(new duck())//quack

There's no "new" keyword in python, think you're confusing with Java a little there :)

kixome
July 12th, 2009, 01:10 AM
i think java sucks, jmho

konqueror7
July 12th, 2009, 01:25 AM
shadylookin,

Thanks for the example. Yes I know how it works, I just don't see the point to it.

An interface is basically just a limited form of an Abstract class (ie. only constants and abstract methods), but it's redeeming point is that you can implement many of them, instead of just one, like with Abstract classes.

So what I really want to know is, what is so great about an interface, other than the fact it's a limited replacement for multiple inheritance, which is about the only thing that seems to make it any different/better than an abstract class.

Btw,



There's no "new" keyword in python, think you're confusing with Java a little there :)

well, the purpose of having an interface is just to have a common understanding of a class or entity. for example, in a big project or an open-sourced project, wherein you need to restrict eventual developers to use whatever methods that are defined in the interface, so if someone will use it, they will know what method to call.

also, as you said, interfaces are somewhat trimmed-down abstract classes, that is true. but what makes them different is the initial implementation in the abstract class that gives the developer the freedom to use the code or extend it. abstract classes is mostly used in classes that where certain methods, needs initial implementation, or gives an initial idea of what the implementation should look like...wherein in interfaces, you got all the freedom to write whatever implementation you like.

and i think java is a great language in certain areas, in comparison to other languages. in work or every project you do you have set of skills and tools that you choose to fit within the nature of the project. would you use assembly in GUI programming? duh?!?! ;)

one great advantage of java is its network inclined philosophy, from the very start of sun they wanted it for the web. the only thing that sucks in java is Swing, and lack of GUI components and configurability, as compared to C#.

lisati
July 12th, 2009, 01:37 AM
C++ is a hack language meant for hacks! It's meant to be useful to do anything and everything, nothing of which is ever very simple once you have built something even remotely complex all of which derived from a language that is not object oriented. Java is simple, elegant, logical, but hackish under the hood and slightly limiting.

That makes sense (sort of), especially when you consider that early versions of C++ were little more than a pre-processor for C.

@shadylookin: Thanks for the example.

Grant A.
July 12th, 2009, 01:38 AM
C++ which is really a bit of a fudge of OOP principles shoehorned into C. A lot of people detest C++ (Linus Torvalds in particular - he was quite vocal here (http://lwn.net/Articles/249460/)).

If Torvalds thinks C is such a great language, then I invite him to look through the source code of eAthena. :lol:

sdlynx
July 12th, 2009, 01:40 AM
I don't think its very useful when coming to building programs for other people to use, mostly because of the fact that you need the runtime environment and such. I mean applets are alright, but everything else isn't very simple to run.

JohnnySage50307
July 12th, 2009, 01:43 AM
Every language has its uses and setbacks:

Java was designed primarily for use over the internet (i.e. applets), and because of this, that's one of the reasons why it runs a little slowly. It was also designed in such a way to be OS independant, that is, if I compile a java .class file on a Win32 machine, I can run it on my Ubuntu machine without changing anything--same commands even.

C++ was designed to be the next great advancement of C. And as I remind everyone, C was designed to be a replacement for x86 assembly programming. Both of which are excellent when you require speed and hardware interaction. The drawbacks come from two places: skilled programmers can even create unseen security holes and that compiled programs are now both OS and archetecture dependant (e.g. a compiled .cpp program on an Ubuntu machine running an x86 processor will not run on an Ubuntu machine running an ARM processor without cross-compilation).

To be totally honest, C and C++ are both my weapons of choice: I am a Robotics Engineer. I do use Java, however, to prototype algorithms that I want to design because Java is a very stable language. I also enter TopCoder competitions and usually I write them in Java just because of the fact that I use it for designing algorithms I ordinairly have never done before.

In defense of Java, I have to admit that if you become skilled enough in applet programming, you can pull off some very sophisticated things; Astronomy.com has a very powerful interactive skymap that was done with applets. Something like that could not easily be done using C++, nor even be available on the website itself!

Nonetheless, I rely heavily on C/C++. Almost all computer games boil down to code in that language because of the languages that graphics libraries are supported. As well as many other hardware-dependant programs, such as networking, etc. Working with sensors as much as I do, you need a strong background in that to be able to write code that interacts with hardware as well. Plus, the underlying speed increase of compiling actual assembly instructions is important when it comes to polling data.

In closing, I stress, each language has its own unique uses and motivations. Neither is "better" nor "worse" unless if used for the unintended purposes. :-k

shadylookin
July 12th, 2009, 02:53 AM
shadylookin,

Thanks for the example. Yes I know how it works, I just don't see the point to it.

An interface is basically just a limited form of an Abstract class (ie. only constants and abstract methods), but it's redeeming point is that you can implement many of them, instead of just one, like with Abstract classes.

So what I really want to know is, what is so great about an interface, other than the fact it's a limited replacement for multiple inheritance, which is about the only thing that seems to make it any different/better than an abstract class.


because sometimes there's no meaningful default implementation. From my example almost no two animals are alike so writing a default implementation is a waste of time.

I guess in theory if that's the case then they could have just forced you to use abstract classes in which all the methods are abstract. Some things in life are just arbitrary I guess.


There's no "new" keyword in python, think you're confusing with Java a little there :)

I haven't used it in a long time so I'd be surprised if that's the only error.

ddrichardson
July 12th, 2009, 07:12 AM
Can you give me any other angle to look at interfaces from? As I'm seriously struggling to understand what useful purpose they serve (apart from making up for the single inheritance factor).
Lets say you create an interface called weather and you create some objects called, say lemon tree, orange tree, apple tree and coffee bush.

All those objects implement the weather interface, and have methods to react to it so when you're trying to model the interactions of different objects to the weather you need only use the interface.

Put simply all those objects know how to react to the weather.

Edit: @shadylookin's example is clear - I need to start reading threads instead of responding ;-)

Sublime Porte
July 12th, 2009, 10:23 AM
dd,

Thanks, but I'm quite well aware of what they're used for, I just don't see a real point to it.

Abstract classes could do the same, and if Java had multiple inheritance, then interfaces would be completely useless right, since that is their only advantage over an abstract class?

ddrichardson
July 12th, 2009, 11:19 AM
dd,

Thanks, but I'm quite well aware of what they're used for, I just don't see a real point to it.

Abstract classes could do the same, and if Java had multiple inheritance, then interfaces would be completely useless right, since that is their only advantage over an abstract class?
An interface _is_ an abstract class and it is a kind of multiple inheritance as a class can inherit multiple interfaces.

I suspect though, that given Java's strong typing, that this is a deliberate reasoning to avoid issues such as the diamond problem but being an engineer and not a computer scientist I'm not really knowledgeable to further argue the pros and cons.

Sublime Porte
July 12th, 2009, 11:00 PM
An interface _is_ an abstract class

Actually it's not. They are similar, and this is my point, that interfaces are perhaps redundant if not for the multiple extension factor.

and it is a kind of multiple inheritance as a class can inherit multiple interfaces.

Umm... and? That was my point.

ddrichardson
July 13th, 2009, 02:04 AM
@Sublime Porte - You asked for an example and I gave one but this seems to have upset you, I meant no insult and see no value in continuing this back and forth.

Sublime Porte
July 13th, 2009, 04:04 AM
dd,

I'm not upset in the least (apologies if I came across that way). It's a computer programming language, no sleep lost here.

I just didn't see anything new in your posts from what I'd already said. ie. that multiple interfaces can be extended by a class, but that compared to abstract classes they're just a more limited version (ie. you can only have constants and abstract methods in them).

So I was merely pointing out that you haven't brought anything new to the table, beyond what I initially stated. I am sorry, but I was asking about other redeeming features of interfaces (that I may not be aware of), not the ones I already listed.

Kazade
July 13th, 2009, 05:11 AM
You should always choose the best language for the job. Every single language out there has it's own flaws, you just need to weigh up the options.

I learned to program first in C, then C++ then Java. I used Java at College and University and over the past few months I've used it pretty much full time. I also used Python for a few years full time before as well. I have to say, IMO, Java is the most irritating language of the lot. Here's the list of annoyances that I've hit over the past few months (these are my opinions based on my experiences, I'm not flaming here):

1. Checked exceptions. When compared to Python and C++ exceptions, these are just crazy. You are FORCED to handle checked exceptions, which the majority of the time means adding a "throws" to the function definition all the way up the chain, or catching and re-throwing as an unchecked exception. Google checked exceptions for many many arguments for and against (I think the anti-checked arguments win me over)

2. No operator overloading. The reasoning is that providing the ability to overload operators would allow programmers to abuse them thus causing ambiguity. However, Sun themselves had to bend the operators to get concatenation to work with the String class. Not only that, but in creating wrapper classes for mathematical types (Integer, Float etc.) they actually created MORE ambiguity than if they had allowed operator overloading in the first place. For example, if you have two methods which return "Integer" instances, both wrapping an int with the same value, then you can't use the equality operator (==) this is such an easy mistake to make and I've made it time and time again. Also writing any long mathematical expression with a wrapper class just creates a mess of chained method calls. C++ operator overloading is overly complex but Python manages it fine, and I'm sure Java could have done to.

3. No private abstract methods in classes, or protected abstract methods in Interfaces. In C++, adding private/protected/public to a virtual method declares where the method can be called from, NOT where it can be implemented. It is ideal to be able to define a method as pure virtual (abstract) but private if you only intend the method to be called from the class it is declared. It is in fact commonly used in the Non Virtual Interface (NVI) idiom. Java doesn't allow this, which means if I want to declare an abstract method, I have to loosen the encapsulation to protected, meaning any derived class can call it, which is only slightly more encapsulated than public. Similar argument with Interfaces.

4. Interfaces don't allow method bodies. Now IIRC Java didn't implement multiple inheritance to avoid the deadly MI diamond situation. Especially to avoid the confusion accessing members which have been inherited via 2 branches of the hierarchy. However, I can think of no reason why an Interface couldn't just be a class which has no member variables. If this was the case, you can write more reusable code in the interfaces which perform logic using only other declared methods of the interface or its parent interfaces.

There are probably a few other things that have annoyed me, but eventually most issues I have boil down to one of the above. Java is a very clean, simple, neat language - but to use a toolbox analogy, if C++ represents a complete toolbox with power tools. Java is a toolbox with spanners, hammers, manual saws and screwdrivers only. That's not to say that C++ is some angel among languages, it's not, it's messy, sometimes overly verbose, and bloody hard to learn well. But when I write C++ the code just flows, when I write Java it doesn't flow so well. I don't have any major issues with Python either, I don't feel limited with Python, I do feel limited with Java.

Sublime Porte
July 13th, 2009, 05:46 AM
Thanks for that Kazade, I think you've nailed what I wanted to know about interfaces, basically that they have no clear advantage whatsoever, but that they're just a crippled replacement for multiple inheritance.

I too was thinking that without the ability to create proper methods (with bodies), interfaces are pretty useless, and mean that the 'extends' replacement of multiple inheritance that Java has is a pretty poor substitute.

SeanHodges
July 13th, 2009, 06:11 AM
Thanks for that Kazade, I think you've nailed what I wanted to know about interfaces, basically that they have no clear advantage whatsoever, but that they're just a crippled replacement for multiple inheritance.

I too was thinking that without the ability to create proper methods (with bodies), interfaces are pretty useless, and mean that the 'extends' replacement of multiple inheritance that Java has is a pretty poor substitute.

I wouldn't stretch to say interfaces are useless. They are key to a lot of Java's functionality, and are often required in design pattern implementations. Have a bit of a read up on the purpose of Java interfaces: http://en.wikipedia.org/wiki/Interface_%28Java%29. Think of them fundamentally as a contract between a class and the outside world, such as "Comparable", which when implemented promises that a class will provide functionality for comparing 2 instances of itself.

Remember that Java has NO substitute for multiple inheritance. It simply does not have it. Interfaces are not intended to be a crippled alternative, and extends doesn't support multiple inheritance at all.