You are not logged in.

#1 2008-07-30 03:35:28

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Java; Where to start?

I know it's not strictly Arch related, but I need help...

Goal: I want to write a small program to assist with creating Fire Reports for the local Fire Brigade... Basically an electronic copy of the paper forms we have at the moment to help make sure we get all the details. Also want to expand in the future to include membership records, training history, equipment maintenace etc (ie, interface to a PostgreSQL database).

I think Java is going to be best - I run Linux at home, the Fire Station runs Windows.

I currently know PHP (w/ PostgreSQL), Bash and Visual Basic (igh) so I'm kind of limited in that sense. I definitely don't want to use VB (for obvious reasons), Bash is defiantly inappropriate, and a PHP Web App with a PostgreSQL backend isn't very suitable either.

First, am I right in thinking that Java will be technically best for developing this?
Second, if so, where's a good place to start learning? I reading through www.javabeginner.com at the moment, and I'm lost already!

For example, this just seem grossly disgusting, counter-intuitive and messy to me:

/** Comment 
 * Displays "Hello World!" to the standard output. 

 */
public class HelloWorld {
      String output = "";
      static HelloWorld helloObj;  //Line 1 

      public HelloWorld(){
            output = "Hello World";
      } 

      public String printMessage(){
            return output;
      } 

      public static void main (String args[]) {
            helloObj = new HelloWorld();  //Line 2
            System.out.println(helloObj.printMessage());  
  }
 
}

- Where does this "helloObj" thing come from?
- Why is "output" defined in the class instead of in the method (which at the moment seems to equate to what I know as a "procedure"?)
- If the aim is reuse, then when we look at printMessage, what happens if we reuse that against another method that doesn't expect to use "output"? We forever have to remember to name our output variable "output" for the rest of coding this program? That seems like more effort than just re-coding it, especially when it gets bigger and the benefits of reuse would be beneficial, then there's more "gotchas" we have to remember and debug?

Maybe my brain just can't handle Object Oriented Languages sad
Should I give up, stick to what I know and write it in PHP on top of a framework?

Offline

#2 2008-07-30 04:10:20

freakcode
Member
From: São Paulo - Brazil
Registered: 2007-11-03
Posts: 410
Website

Re: Java; Where to start?

Java isn't the only thing that can run both on Linux and Windows. PHP itself runs on Windows, as does Python, Ruby, and others.

Java is kinda overkill depending in what you have to do, and will take much more time to learn, specially if you don't have your head around OO already. You need to define what functionality you need from this application first. If it's something simple, I might tell you to stick with PHP itself as you already know it, or go to a language easier to learn like Python, and search the functionality you need in libraries.

Offline

#3 2008-07-30 04:21:16

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Java; Where to start?

Python is cross-platform? I wasn't aware - I thought you needed Cygwin to run Python under Windows...

I need to expand my programming languages anyway (looking for a new job!) so maybe I should try Python instead?

The report-filling-in part of the app will basically be a whole series of text boxes, check boxes, radio buttons etc which will then get printed. How does Python handle printing? From my experience with VB, I know the printing part is going to be the hardest, regardless of what language I choose.

Offline

#4 2008-07-30 04:50:05

ProtoXyne
Guest

Re: Java; Where to start?

Python runs on Windows with ActivePython: http://www.activestate.com/Products/act … ndex.mhtml as well as Cygwin (it's what I use on WinXP, never bothered with Cygwin).
It's often considered easy to learn too. If you want to get into object-oriented programming, I think Python would be a good way to go. Imo, it lets you look a bit beyond the syntax and deal with the concepts more clearly.

RE: Java
You're not alone in thinking that a lot of ways of doing things in Java are convoluted. To answer your question, "output" is first declared in the class itself, then it's defined in the object constructor which is run when you create the object. That just sets it's default to "Hello World!". Think of it as a note that each object is given when it's born that it can refer to when asked what it's supposed to say. You can change the note later if you want, so it is extensible. Also, you probably wouldn't access "output" directly, you would write a method to set it for you, so you could do something like this later:

emoObj = new HelloWorld();
emoObj.setMessage("Goodbye World!");
System.out.println(emoObj.printMessage());

Btw, if that's the example code that you found on that site, I'd say to keep looking for a better tutorial (no suggestions, sorry).

Last edited by ProtoXyne (2008-07-30 04:51:33)

#5 2008-07-30 07:03:30

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Java; Where to start?

Thanks Xeno...

That was the second example on the site (after the standard 6 line Hello World)

I can understand that one just, but I surely wouldn't be able to write it because it just doesn't gel in my head.

I think I'll give Python a go. Getting late tonight, so I'll have a gander tomorrow.

Thanks guys smile

Offline

#6 2008-07-30 07:36:07

ProtoXyne
Guest

Re: Java; Where to start?

Paraphrasing a programmer friend of mine: "Once you wrap your mind around object oriented programming, it just clicks and suddenly makes perfect sense."

Results may vary, but I think it's quite true. Your perspective shifts and aligns itself, so if it seems daunting at first, just stick with it. Keep trying to focus on the concepts behind it instead of the syntax too, I think that helps.

Good luck!

#7 2008-07-30 15:04:25

magnum_opus
Member
Registered: 2005-01-26
Posts: 132

Re: Java; Where to start?

While I'm endorsing java for this task
http://www.javabat.com/ was mentioned in another thread. it's pretty cool (i'd love something like it for other languages)

Offline

#8 2008-07-30 15:11:00

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: Java; Where to start?

The Java Tutorials from Sun are pretty good: they expect you to know nothing at all, and cover relevant topics: http://java.sun.com/docs/books/tutorial/.

Now I'm going to talk a lot about the problem even though I have very little info about it:

The intuitive (and maybe naïve) way to do OO is to create a class for each type of form. Each class would have methods for input, output (printing), storage (db), etc. Eventually you'll want to check for consistency between different forms (I'm guessing they're at least partially correlated); if so, you'll probably realize things would be easier if another OO scheme was used, maybe something like one class for firemen, another for fires, another for equipment, etc. And then you'll have to start over, but you'll get something better in the end.

Another way would be to concentrate only on the task at hand (digitize paper forms). There's probably a way to do this pretty easily in PHP, or Perl or Ruby etc. if you want to learn something new. Eventually you could add routines for other forms. Over time you'll probably notice repetitions in all your functions and do a little refactoring, e.g. writing a common printing function that works for any form. One day you might notice a high-level OO pattern (one class for firemen, another for fires, etc.) and implement it, re-using the general functions you've already written.

I don't know which approach is less work; it probably depends mostly on what you're comfortable with, how you think. There is more than one way to do it. What I'm saying is: you don't have to use OO. It will probably be very appropriate eventually, but you can start with what you know, and learn as you go along. Good luck, have fun!

Offline

#9 2008-07-30 15:11:20

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: Java; Where to start?

You might also want to take a look at C#. It will probably leverage your VB experience better. I'm not sure how useful it is for cross platform development (depends how mature mono is, which I can't answer),

Having said that, python is the best language for most tasks. :-D If I was doing the project I'd use python.

Dusty

Offline

#10 2008-07-30 15:43:16

mintcoffee
Member
From: Waterloo, ON
Registered: 2007-10-05
Posts: 120
Website

Re: Java; Where to start?

This example is indeed very convoluted, but it does demonstrate many issues that you will encounter with OO programming.

static HelloWorld helloObj;  //Line 1

Ths line is a static reference of the HelloWorld object, which is "itself".  It is important to understand that everything in Java, with the exception of primatives, are pointers. As a result, this declaration is simply saying that it can, and may point to a HelloWorld object in the future. It is also in the class scope, meaning it can be accessed from any method and will persist across method invocations. The static keyword, separates the variable from the object, such that you no longer have to construct an instance of its class (HelloWorld) to access it. Since it is static, there is only one copy or instance of the variable, and more copies can not be created. As a result, if we have 5 HelloWorld objects, there will only be one helloObj variable shared among the 5 HelloWorld objects.

helloObj = new HelloWorld();  //Line 2

Here is instantiate the HelloWorld object. Note that the main(String[] args) method is a static method, meaning that it too, is not encapsulated by the HelloWorld object.

System.out.println(helloObj.printMessage());

In this case, we have use the helloObj variable because it is contains a reference to a HelloWorld Object. The printMessage() and output variables are NOT static, and must be accessed through a HelloWorld reference.

Now that I've looked at the code, there really is no reason for having the line:

static HelloWorld helloObj;  //Line 1

declared in the class scope (as a field). It should really belong in the main method. I don't think I've made much sense in this post, but needless to say, there are better tutorials out there. I think Sun has one right on their site.

Last edited by mintcoffee (2008-07-30 15:45:16)


Arch on a Thinkpad T400s

Offline

#11 2008-07-30 23:27:06

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Java; Where to start?

Whoosh.... lol

I'm going to have a look at Python today, and probably have a go at the Sun tutorials to see what I can glean from there.

Thanks everyone for your input; I'll post how I go hopefully.

Offline

Board footer

Powered by FluxBB