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

Java Programming

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.

Advertisements

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)
daemons(great)
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
Servers(excellent)
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?