java/c++: question on functionality

Status
Not open for further replies.

shabadu

Ars Tribunus Militum
1,851
For my c++ class project, I have to make a program that outputs a calendar in HTML format. The calendar would read in appointments and stuff from a text file and put them in the html file, along with all the normal calendar stuff. He also said that we have to "enhance" the program in some way that we come up with. I'd like to make it possible to add/remove appointments through the HTML interface. Is there a way to do this with java? The major problems I forsee with that would be:

1) Is file IO possible in java?
2) Can java run an executable?

I think the answer to both of these is no, but I'm by no means an expert, so I ask you. If this isn't possible with java, is there any other language in which it is?

shabadu
 
Originally posted by shabadu:
1) Is file IO possible in java?
2) Can java run an executable?

Yes, and yes. Look at the FileWriter and FileOutputStream classes for the first, and for the second, look at the Runtime.exec() collection of functions.

There's documentation available for all of the core Java API at http://java.sun.com/j2se/1.3/docs/api/index.html. If you're using a version of Java other than 1.3, just change the version number; i.e. Java 1.2.2 is http://java.sun.com/j2se/1.2/docs/api/index.html.

floccinau
 

Mike Y

Ars Scholae Palatinae
825
I'm assuming the html file would be opened in a web browser like IE or netscape. If that's the case, writing a java applet for this would be an irritating experience, IMO, and there are many other better ways of doing it (servlets as listed above or maybe scripts). I am wondering, however, why you would use java to "enhance" a C++ program. I would think your professor would want you to do something with C++.

As for what SDK to use, Forte is an IDE, not an SDK. The Software Development Kit is the tools to compile and debug code. There are only two really, the Sun and IBM ones. I'd just stick with the Sun one unless you're writing some big app that needs speed. As for what IDE to use, I don't think Forte is very good (especially since it's written in Java). I prefer JCreator for small projects.
 

wb

Ars Legatus Legionis
25,208
Subscriptor
I don't think this program was "designed" to be run as an applet, even though it uses HTML. If you look at the professor's spec, he says it has to read in an input file to get appointments, etc., which is also (normally) out of the sandbox for applets.

To execute an external application, use Runtime.exec(), which returns a Process object which holds references to stdin, stdout, and stderr for the executing process.
 

shabadu

Ars Tribunus Militum
1,851
Mike Y: He said that adding the capability to add and remove appointments through the html would be a great enhancement, even if it's not really c++ related. I think he knows that only people who are confident in c++ are going to try something this hard. And I think I'll be using javascripts also, but can javascripts do the things in my first post?

wb: I would still be using the c++ program to do most of the work, I would just use java to edit the data files and re-run the program.
 

OneFootsTheSame

Smack-Fu Master, in training
70
In case you're still thinking Applets ... DONT! Doing this server side will be easier. (Do people still write Applets? ;) )

Managing the text files with Java won't be difficult for you once you find all the APIs. One way to read the file is to do something like this:

code:<HR>
Code:
BufferedReader in = null;
try
{
    in = new BufferedReader(new FileReader("YourFileName"));
    String tmpLine = null;
    while ((tmpLine = in.readLine()) != null) {}
}

After you've added or removed your entry from the data, you can then run your C++ prog and send the output back to the client.

Of course you will have to be able to indicate which items to delte and gather data for new items. Not that it's hard, but it can be time consuming (at least for me ... but, I get anal about my interfaces).
 

shabadu

Ars Tribunus Militum
1,851
Ok, thanks. I don't really know what that's doing, but I'm sure I'll figure it out after getting through more of the sun tutorial.

A question on applets vs. servlets: I recognize that doing everything server-side would be easier. I would like this to be a functional, web-based organizer, but chances are that in class the whole thing will run on one machine. He'll want me to compile the code on the spot, so the .exe would be local and the servlet would need to be local to acces it. Would a servlet work in that situation?
 

Tristram

Ars Scholae Palatinae
1,428
Subscriptor
Without seeing the actual problem description, it sounds like a simple application that can be configured with command line arguments would do the trick.

Java file IO sucks, though I prefer Java for most things. Simple streaming ascii to a file, I'd use C++. Actually, I'd use Perl, but then I'm lazy.

Servlets or CGI will allow you to use HTML forms to modify the Calandar display. Any server side programming presupposes a Web server that is configured, running and that you have permission to add pages and programs, however. In particular, setting up a Java Servlet container is not trivial. Not hard, but does require attention to detail.

As for enhancments, why not do something with the HTML that is emmitted? Say, put a switch that lets you choose the background color. Much easier, meets the letter, probably meets the intent.
 

OneFootsTheSame

Smack-Fu Master, in training
70
in class the whole thing will run on one machine

Will you be able to set up the machine before having to compile and run in on the spot? If not, this will be difficult. Getting the environment setup should mostly a matter of running installers. On my dev machine I install: Java, then JSDK (add jsdk.jar to CLASSPATH env var), then Apache, then JServ, and it all pretty much works. But I'm behind the times and really would rather be using Tomcat (can't just yet) which is what I recommend to you. Once installed, find the sample servlets and start working from there. The default configuration should be good enough for your purposes. Then, rip off the IsItWorking servlet to get a basic servlet framework.

Java file IO sucks, ... I'd use Perl

Perl for file/text processing is teh win! However, reading things like s/^\s*(.*?)\s*$/$1/ makes my head hurt. :)
 
Status
Not open for further replies.