Outdoors, Green Living, Homesteading, Sustainable living, Green Building

Posts tagged “Java

Java Ledger a simple free accounting program that I wrote

WANTED! Comments. Not wanted! Compliments. If you want your comment to be accepted first you must not be a spammer that WordPress recognizes and second you need to comment specifically on some of the article’s specific material or facts.

The Survival Pod Cast
Off Grid Net

*** Version II Is now available. So this post is out of date.. you an find the version
this post talks about in files ver1 folder on sourceforge page.

Need a simple free accounting program? I wrote one using the Java Programming Language. It is at Java Ledger at Source Forge This project uses two other projects. JCurses is at JCurses at Sourceforge and JDOM JDOM.org  And you may want to read my post on Java In Ten Minutes This will help you to install Java so that you may run this app. And as a prerequisite for the accounting read my post Home Accounting

JDOM is for reading the journal.xml and accounts.xml files. JCurses is for displaying colored text in the dos console. I downloaded both of these and put one under c:\dev\jdom and one under c:\dev\jcurses

Next I set the classpath with

set classpath=;.;c:\dev\jdom\*;c:\dev\jcurses\lib\*;

Next download and unzip the accounts.zip file. The install.zip file download contains the zip files for JDOM and JCurses. This is actually an Eclipse workspace. If you unzipped it under c:\dev then it will be in c:\dev\workspacejcurses and then

Here you will notice accounts.xml and journal.xml as example data files. You may edit these with dos edit command or notepad or vi on linux or jedit any other favorite text editor. Below are some samples from the files.

Sample Journal.xml

  <year value="2013">
    <month value="jan">
        <day value="1" />
        <credit account="400" note="Onhand wallet" />
        <debit account="100" note="cash onhand" />
        <amount value="78.64" />
        <day value="1" />
        <credit account="400" note="Onhand bank1" />
        <debit account="100" note="checking onhand" />
        <amount value="350.71" />
        <day value="1" />
        <credit account="400" note="onhand bank2" />
        <debit account="100" note="checking onhand" />
        <amount value="40.58" />
        <day value="1" />
        <credit account="100" note="Denny's 2 meals" />
        <debit account="501" note="2 meals + tip" />
        <amount value="26.50" />
        <day value="2" />
        <credit account="100" note="Flying J" />
        <debit account="501" note="Food, coke, water" />
        <amount value="4.65" />
        <day value="2" />
        <credit account="100" note="Van Insurance" />
        <debit account="507" note="Van" />
        <amount value="66.64" />
        <day value="2" />
        <credit account="100" note="Vending Candy" />
        <debit account="501" note="Candy Bar" />
        <amount value="1.00" />
        <day value="2" />
        <credit account="100" note="Flying J Pizza/Chicken" />
        <debit account="501" note="Pizza/Chicken" />
        <amount value="10.58" />
        <day value="3" />
        <credit account="400" note="WSE Deposit" />
        <debit account="100" note="WSE Pay" />
        <amount value="371.92" />

And Sample Accounts.xml

  <type name="asset">
    <account number="100" name="Cash"/>
    <account number="101" name="camper"/>
    <account number="102" name="boat"/>
    <account number="103" name="van"/>
    <account number="104" name="home"/>
    <account number="105" name="Camping"/>
    <account number="106" name="Hunting"/>
    <account number="107" name="Fishing"/>
    <account number="108" name="Gardening"/>
    <account number="109" name="Homestead"/>
  <type name="liability">
    <account number="200" name="CreditCards"/>
    <account number="201" name="CreditUnion"/>
    <account number="202" name="Ford Motor"/>
    <account number="203" name="Family"/>
  <type name="capital">
    <account number="300" name="Larry's Capital"/>
  <type name="income">
    <account number="400" name="Income"/>
  <type name="expense">
    <account number="500" name="Work Misc Expenses"/>
    <account number="501" name="Work Food"/>
    <account number="503" name="Work Phone/Internet"/>
    <account number="504" name="Work Entertainment"/>
    <account number="505" name="Home"/>
    <account number="506" name="Home Food"/>
    <account number="507" name="Insurance"/>
    <account number="508" name="Medical"/>
    <account number="509" name="Utility Gas/Electric"/>
    <account number="510" name="Rent"/>
    <account number="511" name="Vehicle"/>
    <account number="512" name="Satalite/Internet"/>
    <account number="513" name="Misc Internet"/>
    <account number="514" name="Taxes"/>
    <account number="515" name="Ministry Support"/>
    <account number="516" name="Camping"/>
    <account number="517" name="Hunting"/>
    <account number="518" name="Fishing"/>
    <account number="519" name="Gardening"/>
    <account number="520" name="Homesteading"/>
    <account number="521" name="Misc"/>
    <account number="522" name="Banking"/>
    <account number="523" name="Gifts"/>

Next cd bin to get to the bin folder. In here you will see some .class files.
Ledger.class is the main class. In this file you will see a comment which I
will give you below.

* This main method is the interface for this app. At least for now. Later
* I may make a GUI interface using Swing.
* example command line commands are
* 'java journal month nov2012' prints the journal for November 2012
* 'java accounts type asset'  prints the list of asset accounts
* 'java accounts type expense' prints the list of expense accounts
* 'java ledger month nov2012 100' prints the ledger records for cash account
* 'java ledger month nov2012 501' prints the ledger records for work food expenses
* 'java balance month nov2012 asset' prints the balance for the asset accounts
* 'java balance month nov2012 income' prints the balance for the income accounts
* 'java balance month nov2012 bal' prints the balance sheet
* @param args
public static void main(String args[]) {

Note that shows month nov2012 which is some bogus sample data I made up. I have real
data from my own life in jan2013 and will continue it for the rest of the year. You will get
to see how stupid I am with my money. Or how smart I am hopefully.

Next I will run some commands on Jan 2013 which covers data from 1/1/2013 to 1/22/2013.  22 Days.  I will grab some screen shots and show you the command and output below

c:\dev\workspacejcurses\accounting\bin>java Ledger accounts type expense

c:\dev\workspacejcurses\accounting\bin>java Ledger balance month jan2013 bal

c:\dev\workspacejcurses\accounting\bin>java Ledger balance month jan2013 asset

c:\dev\workspacejcurses\accounting\bin>java Ledger balance month jan2013 expense

c:\dev\workspacejcurses\accounting\bin>java Ledger ledger month jan2013 100

c:\dev\workspacejcurses\accounting\bin>java Ledger ledger month jan2013 501

c:\dev\workspacejcurses\accounting\bin>java Ledger ledger month jan2013 400

c:\dev\workspacejcurses\accounting\bin>java Ledger journal month jan2013

So you can see that this application does actually work. It still need some work however. I will be updating it over time. The latest source will be in the SVN code repository on the sourceforge site. This source will now make a good base for a Windows Desktop app or a Web Page App, maybe even a Phone app.

*** Version II Is now available. So this post is out of date.. you an find the version
this post talks about in files ver1 folder.


Java ITM (In Ten Minutes)

WANTED! Comments. Not wanted! Compliments. If you want your comment to be accepted first you must not be a spammer that WordPress recognizes and second you need to comment specifically on some of the article’s specific material or facts.

The Survival Pod Cast
Off Grid Net

ITM (In Ten Minutes)
I’m not sure if these articles/tutorials mean you will learn it in ten minutes or it simply took me around ten minutes to write it. But they are meant to hopefully get someone started.
Java ITM
In order to build a Java application follow a few steps I list below.

I) Download the Java Developers Kit (sometimes they call it JDK sometimes SDK who knows might be called ODK since Oracle has bought Java) Also note that IBM has a developers Kit and there is now an Open JDK as well. In this tutorial I am specifically talking about the developers kit from http://java.sun.com. There are several versions of this kit called SE, EE, ME etc. get the SE (Standard Edition) version. Find the one for your operating system and install it.

II) Lets say you installed the windows version and you put it in c:\java\sdk folder. Open up a command window by going to [start][run] then use “cmd”. I will not bother to teach you DOS commands in this section (see the scripts section) Find the bin folder. Here you will see a couple of important files. “java.exe” is one and “javac.exe is the other.

III) Open up notepad.exe (a text editor) and create a file named MyFirstApp.java. Within this file write the following…

public class MyFirstApp {
  public static void main(String args[]){
    System.out.println(“Hello World!”);

This would be the famous hello world application for the console of course.

IV) Next save this and close notepad. Compile this with the command “javac MyFirstApp.java”. If it goes well you will see no errors and a new file called MyFirstApp.class. This is the “bytecode” which the Java virtual machine(JVM) will now interpret (run/execute).

V) You may run (execute) this with the command “java MyFirstApp”. If all goes well you should see the text “Hello World!” appear in the console. You may alter the text in the main method and add extra System.out.println(); calls to your hearts content if you like. Congratulations You are now a Java Programmer. At http://java.sun.com/tutorial you will find a nice tutorial to help you along your new path. Note also that this application you just created would run without change on a Mac or any variety of Unix as well maybe even IBM’s OS2 Warp or possibly on a “Main Frame” operating system. It will run on any system which has a Java Virtual Machine installed. The only issue you could run into might be a Version issue. With such a simple application as this it is unlikely.

VI) One last note, you could have problems with system path, I won’t explain here. And you might have problems with an environment variable setting called CLASSPATH. JAVA_HOME is another one to look into. I will now direct you to internet forums or internet relay chat for further assistance. You would need to seek help concerning your operating system (windows, unix, mac, other) and environment variable settings.

The Java Programming Language

WANTED! Comments. Not wanted! Compliments. If you want your comment to be accepted first you must not be a spammer that WordPress recognizes and second you need to comment specifically on some of the article’s specific material or facts.

The Survival Pod Cast
Off Grid Net

What do you think of when you think of programming languages? Software right? Software is a set of instructions which the computer executes in, hopefully, logical sequences. Programming languages define and provide those instructions.

The base software on any machine is the Machine’s own Language known as ML(Machine Language) or Assembly. I won’t go into details here except to say that this is very cryptic to say the least. Each machine has its unique instruction set. Registers and Ram store data. There are very basic binary math functions. Memory functions. Different types of memory addressing etc. On windows DOS DEBUG command can give you some examples of ML by displaying it from ram directly.

In the 1960’s programmers saw a need to come up with a more generic language which would make programs more portable across machines. They came up with a language called C. Yes. C was meant to be a cross hardware portable language so that you only had to make minor adjustments to the source code to get the same program to run on one machine or another. C is cryptic but not nearly as cryptic as machine language. C is one of what is called a Von Neumann language. I won’t go into details but other Von Neumann languages might be BASIC, Pascal etc. Statements, branching, loops, subroutines and functions is what I think of when I think of a Von Neumann language . I’m assuming the reader knows enough about programming that I don’t have to explain statements, branching, loops etc.

Software execution may appear to the user in different ways on different levels. Software does not have to interface with a user at all for example. It can run silently in the “background”. However the user may experience some good indirect benefit hopefully (other than malware, spyware and viruses). This type is called Daemon software. Can also be called TSR, Drivers or background processes.

The first software was most noticeable on what was called a text console. Text meaning alphabet and symbols were displayed in one color with a different background color. White, amber and green were the first text colors with black background. Text was arranged in perfectly spaced rows and columns. And then we had the printer whereby text was spaced in a very similar fashion with black text on white paper or green/white paper. The graphics screen was another mode where the screen was divided into rows and columns of pixels. Later we added color to the scene, first 4 colors, then 16, then 256, then 1000’s and then Millions and so on. So to get to the point software first interfaced with humans as “output”. And a program basically performed this sequence. “Input”, “Process”, “Output”. We called these programs “console applications” or “terminal applications”

As computers have developed or advanced over the years the types of manifestations of computer software have increased significantly. I doubt I can possibly cover all of them. I will talk about some of the types related to Java programming. From the Console we added a pointing device(mouse) and the Graphical user interface, along with multitasking. We call this kind of software GUI Applications or Desk Top Applications.

A very exciting new type of software has been the Web Application. Web sites, and web development. This is software which runs on the web server. The user experiences this software in the form of web pages and files sent to the web browser. And some software runs on the web page or in the web browser as well.

I have been progressing towards telling you about the C++ programming language. This is another Von Neumann language and it is an extension of the C language. This language most notably adds what is called OOP(Object oriented programming) to the C language. OOP most notably combines data and subroutines into a package called an object. It can be thought of as a way to group and reference data and logic which pertain to one another. Its literally a program within a program or software within software.

This finally brings us to the Java Programming language which was meant like C to be portable, unlike C it is meant to be 100% cross platform(machine) portable. This means you do not have to change the source code at all or recompile and Java will run on any machine. Though there is a catch. The machine must have what is called a Virtual Machine and in this case a Java Virtual Machine. A Java virtual machine executes a generic machine code called “bytecode”. By execute I mean it “interprets bytecode”. So Java is first compiled to bytecode. Java like C++ is also an OOP language. In Java however everything is an Object and all things begin with Objects. All things are built upon Objects.

For those of you who don’t know what compiled means I will explain a bit. The first languages other than assembly were not compiled. They were what is called “interpreted”. Meaning the program steps are read as text commands each and every time the program was run. This text is known as source code or scripts. Software can be made to run more efficiently if it is converted from this source or scripts into straight binary machine code. I’ve heard this referred to as “running the application on the metal”. I can’t possibly go into why this is more efficient except to say that it removes a lot of decision making and branching from the execution process. Is this excess execution speed necessary? Maybe and maybe not. Faster is always better right? Maybe its always better but its not always necessary.

Java therefore can be thought of as being a hybrid between interpreted and compiled languages. By the way compilers have been written for many interpreted languages. And in fact there is an attempt to write a Java Interpreter. Java can also be completely compiled to the native platform but this defeats the purpose of Java and system independence. I guess the advantage of the interpreted langauge is that you don’t have this compilation step. An advantage of fully compiled to the metal software is that it doesn’t need the interpreter to be installed to run. So what we see here is pro’s and con’s for each type of software execution. Java must be compiled and it must have an interpreter. So we loose both of those typical advantages. However we gain the advantage of 100% Cross Platform portability. Yes I can write a Java program and without change it will run on a Macintosh, a IBM PC or clone. It will run on different operating systems without change as well, OS X, Linux, Unix, Windows etc. It will run without change on any machine and operating system which has had a Java Virtual Machine created specifically for that machine and operating system. It should run on cell phones for example but thats another story. Like I say, Pro’s and Con’s.

Since Java is a generic Machine it is what is known as a “Platform” for software. An operating system for example is a Platform. Hardware set is a platform. Another word for this I would think would be foundation. One good note is that Java is not the only language which is being developed for the Java Virtual Machine. Scala is another and there are more. This means that the JVM will be getting plenty of support as time goes by. Hopefully changes to the JVM will always be favorable for Java.

Computer languages can be thought of as being more or less popular. I’ve heard some languages being said to be “dead” or “alive”. Long live Java! Things are changing fast in computer programming. Java has its competition. J++ was one such and is in fact dead because of a Sun and Microsoft lawsuit. J++ became what is now C# (C-Sharp). J++ and C# is very similar to Java but not identical in many ways. The saga continues. Java has been purchased from Oracle, the database folks. However Java’s continued development and growth is managed by the Java community (those that use and love it). So there is plenty of hope for Java. Also many books and a huge source(code) base have been developed. Java will continue to be used for many years to come. Will it loose popularity? Yes and it will regain popularity as well. A new hope for Java is the VPS(Virtual Private Server) which promises to make Java web services more affordable. VPS means you can install any operating system on a virtual server and any web services you like. Like GPL Host , my setup here, you may therefore have Debian linux installed and Tomcat 5.5 web server. You are therefore paying a competitive price for the virtual server not for expensive “Java” web services.

What types of software is Java good for? Ah you want my opinion? Sure, I’ll list a few types and next to it show poor, fair, good, great and excellent.

TSR hardware drivers(impossible)
console applications(poor) with a 3rd party api JCurses (fair)
GUI applications(good to great)
Games general(poor to great) depends on the type of game
Games 3D(poor) except for using what is called OpenGL or JOGL addon’s in which case via the use of these 3rd party graphics api’s or libraries great 3d graphics can be achieved
Client software(great to excellent)
Web Applications(good to great) depending on who you ask. Java works as well as it ever did but may not be like the newest fads. We are talking here about Java Server Pages, Serlvets, Java Server Faces.
Applets[mini applications](poor as of lately) Webstart applications are favored now over applets.
Web Start[mini applications](great)
Networking apps(excellent)
Database (good to great)

Next I will list some uses for Java the same way.

Educational software.(sure)
Scientific software.(for many types)
Accounting software.(why not?)
Introductory Programming (excellent, the best)

So in conclusion I say that Java is a great programming language to use and learn. And Java software is very valuable software. Loosing some popularity? Yes. But dead? No by no means dead. Some say, “Use the right tool for the right job.” I say, “Use the tool you enjoy using. Use the tool that you know how to use well.” Much in the computer world and programming is fad. Java has been a fad. But more than a fad as well. Much in the computer world is experimental. The more things change the more they remain the same right? Reinvention of the wheel is all around us. The basics of programming remain the same. “Statements”, “Iteration”, “Decisions”, “Subroutine”. “Input”,”Process”,”Output”. But things are added over time such as GUI, Networking, Mobile, Virtual Machine. Hardware is improved or added on to for backward compatibility sake. What you learn when using and learning Java will be a foundation for more to come in the future. Even a foundation for learning other programming languages and technologies. I hope I have convinced you to at least learn a little more about Java, to experiment with Java and to test and try it out. Maybe even from a Java application end users viewpoint aye?