Java

Coders forum. Discuss techniques, swap code snippets, ask for help etc. relating to all forms of software development.
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: Java

Post by Dungeon-Dave »

t0ne wrote:I think most of the problems with Java are the number of bloated over-engineered frameworks that sprung up everywhere and half the world believing they needed full on J2EE for everything.
.. and the number of people that are used to procedural and don't grasp OO concepts in general, or those use to lack of standards and find Java restrictive because it imposes a certain framework, etc... Or we could generalise this with "the problem is definitely in the Java anguage, and not in the way we use it badly"....
Malf wrote:But of course my bosses are of the opinion that you can use the same old approach no matter the tool. I can hardly wait to start screwing in some nails...
"if the only tool you have is a hammer, then every problem begins to look like a nail" is an antipattern I quote regularly. Same as the number of people using Excel for everything because that's what they're most familiar with, bending a spreadsheet tool to perform functions required of databases, calendars, etc.

I suppose the flipside is reinventing the wheel each time and completely ignoring code re-use. But right tool for the job, right time and a place, and everything.
User avatar
princec
Baaaa!
Baaaa!
Posts: 590
Joined: Thu May 09, 2002 3:20 pm 0
Location: Basingstoke
Contact:

Re: Java

Post by princec »

Java works for me :) It's just a massive pisser there isn't a Playstation or XBox port.

Cas :)
User avatar
zip accident
Sheepie Whore
Sheepie Whore
Posts: 13928
Joined: Sun Feb 20, 2005 1:58 pm 0
Location: Bristol, UK

Re: Java

Post by zip accident »

Dungeon-Dave wrote:
Malf wrote:But of course my bosses are of the opinion that you can use the same old approach no matter the tool. I can hardly wait to start screwing in some nails...
"if the only tool you have is a hammer, then every problem begins to look like a nail" is an antipattern I quote regularly.
However, you actually can hammer in screws; oval nails with a screwdriver? not a chance (unless the screwdriver is heavy enough to be used as a very poor hammer).
"My way is the way of not fighting":- the book of Enter the Dragon.
User avatar
GoatFoam
Baaaaa!
Baaaaa!
Posts: 1255
Joined: Tue Dec 12, 2006 11:05 am 0
Location: Brizzle
Contact:

Re: Java

Post by GoatFoam »

I think this is the point where someone usually comes in, points out that all languages are theoretically equivalent and utterly misses the point.
User avatar
gilesgoat
Sheepie Whore
Sheepie Whore
Posts: 27258
Joined: Wed Sep 03, 2003 7:54 am 0
Location: Monfalcone, Italy
Contact:

Re: Java

Post by gilesgoat »

GoatFoam wrote:I think this is the point where someone usually comes in, points out that all languages are theoretically equivalent and utterly misses the point.
Yeah ..

Image
Giles the billy goat
"Baa"
User avatar
the2bears
Baaaaaa!
Baaaaaa!
Posts: 3686
Joined: Wed Oct 27, 2004 9:30 pm 0
Location: The City by the Bay
Contact:

Re: Java

Post by the2bears »

Right tool for the job, etc. I'd never be able to go back to a language without dynamic class loading.

Bill
the2bears - the indie shmup blog
User avatar
RamaBot
Baaa!
Baaa!
Posts: 349
Joined: Sat Feb 04, 2006 1:44 am 0
Location: Coventry, England
Contact:

Re: Java

Post by RamaBot »

Right tool for the job, etc. I'd never be able to go back to a language without dynamic class loading.
Why not?
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: Java

Post by Dungeon-Dave »

I'm curious about that too - what is meant by "dynamic class loading"..? What languages support it?

(I know about dynamic module loading - not having to recompile Apache for adding in modules, etc. That the same thing?)
User avatar
t0ne
Baaaaaa!
Baaaaaa!
Posts: 3134
Joined: Wed Sep 11, 2002 8:48 am 0
Location: Bristol

Re: Java

Post by t0ne »

Java allows you to load classes at runtime. For example JDBC uses this sort of thing with database drivers which allows you to specify the appropriate database driver class at runtime, perhaps from a config file without recompiling.
By default as long as the class is in the class path somewhere, Java can resolve a name to a class and load it for you. In fact you can write your own class loaders to pull in classes from anywhere you want (over a network connection, or from encrypted storage for example).
User avatar
sdetoni
Baaaaa!
Baaaaa!
Posts: 1368
Joined: Tue Jun 18, 2002 4:14 am 0
Location: New Sheepland

Re: Java

Post by sdetoni »

t0ne wrote:Java allows you to load classes at runtime. For example JDBC uses this sort of thing with database drivers which allows you to specify the appropriate database driver class at runtime, perhaps from a config file without recompiling.
By default as long as the class is in the class path somewhere, Java can resolve a name to a class and load it for you. In fact you can write your own class loaders to pull in classes from anywhere you want (over a network connection, or from encrypted storage for example).
Thats sound like a cool feature .... pity I've not found a use for it in Java. I'm of the opinion, if you try to be too clever when you don't have to be, then don't, you only end up confusing people, including yourself (give it 6 months). Actually, these dynamic classes sound a bit like function pointers in C, I've only every found one really good use for functions pointers, it had something to do with loading and calling dynamic functions/libraries I implemented in my play language that wrote called Moria.
User avatar
gilesgoat
Sheepie Whore
Sheepie Whore
Posts: 27258
Joined: Wed Sep 03, 2003 7:54 am 0
Location: Monfalcone, Italy
Contact:

Re: Java

Post by gilesgoat »

t0ne wrote:Java allows you to load classes at runtime. For example JDBC uses this sort of thing with database drivers which allows you to specify the appropriate database driver class at runtime, perhaps from a config file without recompiling.
By default as long as the class is in the class path somewhere, Java can resolve a name to a class and load it for you. In fact you can write your own class loaders to pull in classes from anywhere you want (over a network connection, or from encrypted storage for example).
That sounds a feature working only with interpreted languages ..

So you are kinda telling that "you can call function X / use class Y in your code withouth the need to link with lib Xyz and
the program 'automagically' will load and link the lib for you as you run it ?".

Well no, on a second tought you could implement it in various ways .. "a bit more evolved than a DLL" I'd say yet
fundamentally "same kind of idea" .. I can see pros and cons in this .. one 'pro' could be "I can update/change the class
under your arse without you needing to know about it".

I am not sure but I think you could do some kind of mechanism of that kind in C++ .. it would be nice if you could do
"all the loading / link you need" at startup all in once and then "once is all there, run full speed" otherwise I can see
potential for serious performance issues.
Giles the billy goat
"Baa"
User avatar
t0ne
Baaaaaa!
Baaaaaa!
Posts: 3134
Joined: Wed Sep 11, 2002 8:48 am 0
Location: Bristol

Re: Java

Post by t0ne »

Yes, the dynamic class loading is a lot like function pointers. In Java you'd define an interface and code to that. Apart from keeping the coupling loose, it also gives you the ability to dynamically change the implementation at runtime.

I should just clarify that you have to call a method passing the name of the class you want to load to do this in Java, it doesn't automagically do it if you try and use a particular class.
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: Java

Post by Dungeon-Dave »

gilesgoat wrote:That sounds a feature working only with interpreted languages ..
I don't see how.

If I apply a service pack that updates DLLs on a machine, applications dependent upon those libraries don't need to be recompiled.

(and the fact it works with Java suggests that it definitely works with compiled languages, rather than interpreted... although I predict the thread digressing into the definition of how the JVM deals with bytecode any min now....)
User avatar
Orava
Sheepie Whore
Sheepie Whore
Posts: 12698
Joined: Sat Mar 13, 2004 12:13 am 0
Location: The West Country

Re: Java

Post by Orava »

gilesgoat wrote:
t0ne wrote:Java allows you to load classes at runtime. For example JDBC uses this sort of thing with database drivers which allows you to specify the appropriate database driver class at runtime, perhaps from a config file without recompiling.
By default as long as the class is in the class path somewhere, Java can resolve a name to a class and load it for you. In fact you can write your own class loaders to pull in classes from anywhere you want (over a network connection, or from encrypted storage for example).
That sounds a feature working only with interpreted languages ..

So you are kinda telling that "you can call function X / use class Y in your code withouth the need to link with lib Xyz and
the program 'automagically' will load and link the lib for you as you run it ?".
Java jar-files work much like DLLs, except you don't have to do any linking or registering them.

For example, MySQL driver lives in a file my-sql-connector-java-5-6-1-bin.jar, you make sure that is on your application's classpath so its gets loaded when needed.

You can then dynamically access all the classes in that jar file, e.g.

Code: Select all

Class.forName("com.mysql.jdbc.Driver").newInstance();
or you can do this with any class as long as you know the name

e.g.

Code: Select all

Class megaLlamaClass = Class.forName("org.llamasoft.MegaLlama");
MegaLlama ml = (MegaLlama)megaLlamaClass.newInstance();
ml.spit();
ml.say("Bullseye!");
Holier than thou
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: Java

Post by Dungeon-Dave »

Is it possible under Java (although I'm thinking of ways to do it already) to parametrise this stuff in a separate file of constants then read that file in at run-time?

I'm not thinking of opening the file and reading it like a data source, more like the php_ini() function.

Also: what would be the format of that file - can it appear like an .ini file, or could I use XML to define finals which will be used later?
Post Reply