• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A Java service!?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone! This is my first post and thank you for helping this noob(greenhorn) out!

What does it mean that a Java program should run as a service? I dont mean webservice, but a plain ole' Java program compiled from the the command prompt.

Thanks all!

 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe you're talking about a windows service? this does not have to be a java program - it can be any kind of program.

Basically (as I understand it), it's a program that is always running, waiting to do something. I worked on a project that had a windows service that scanned a directory for a Word .doc file in a certain directory. When a file showed up, it would convert it into a .pdf file, delete the original .doc, and save the .pdf to a new directory.

a java program could conceivably be installed as a service like this.
 
Alexander Arenas
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Fred, thanks for responding.

Unfortunately im not talking about a windows service. But definitely a service as you explained.

Going further with a program being a service:

Lets say I have a main class that calls another class that gives me the weather in Fahrenheit.
How do I go about creating another class that gives me the weather in Celsius without recompiling the original project?

In this case I am offering the weather as a service, the programmer must expand the original application without recompiling it. I cant just add a new compiled class into the directory and expect the original application to function without compiling everything. So how does one go about resolving this situation? A configuration file?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alexander Arenas wrote:
Going further with a program being a service:

Lets say I have a main class that calls another class that gives me the weather in Fahrenheit.
How do I go about creating another class that gives me the weather in Celsius without recompiling the original project?

In this case I am offering the weather as a service, the programmer must expand the original application without recompiling it. I cant just add a new compiled class into the directory and expect the original application to function without compiling everything. So how does one go about resolving this situation? A configuration file?



The term "service" is such a generic term that it has tons of meanings -- webservices and windows services being two of them... Having said that, I have never heard it described the way you did here. What you are desciribing sounds more like a shared library, or a plug in....

Regardless... Sure you can use a configuration file -- which can specify a class which your program can instantiate and call. Another option is to just instantiate a particular class, letting the ordering specified in the classpath, choose the correct class. In both cases, no recompilation of the application should be necessary.

Henry
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awkward. You can have a FahrenheitToCelsius class with methods running happily whenever the use enters temperatures.
You can have a CelsiusToFahrenheit class and compile it and add it to the directory, even while the application is running, and the two won't interfere with each other. But you can't make the main method "aware" of the new class without adding code and re-compiling it.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alexander Arenas wrote:I cant just add a new compiled class into the directory and expect the original application to function without compiling everything.


I beg to differ. A classloader that knows about the directory where new class files might show up can load and run those easily. The new class would not have a "main" method, though, but instead implement a pre-agreed interface. But even that could be pretty generic, thanks to the power of reflection.

This is not beginner's stuff, though, so let's move it to the Intermediate forum.
 
Alexander Arenas
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf,

I think you have best explained what I am trying to get at.

So the new class implements an agreed interface, as would have the original class. How do you develop the main class/method to call either of the classes that implement the agreed interface or for that matter any future classes?

I am also not familiar with these "classloaders".

Thanks!
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may want to read this article, written by -ahem- yours truly. It explains how to use a custom classloader to load classes from a particular directory. While it doesn't address the question of how to discover new classes at runtime (it does it at startup), that's a minor detail that could be added easily.
 
Alexander Arenas
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf!!!

That article is great stuff! Im taking it with me to lunch, so that I can consume the knowledge within.

I think I will owe you a beer or a drink or something after I read this!


Thanks again!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic