Sitemap
Link Exchange
Link Exchange More
 
Sponsored Links
Search
 
Free Link Exchange   | Coding Forums
 
you want to program in Java? That's great, and you've come to the right place. This column will give you a complete education on Java programming, starting with the basics, and covering all of the core concepts you need to become productive in the language. This column will be technical, with plenty of code examples to help you along. I'll assume that you already have some programming experience.

I'll start off with a short overview of what Java is and how it works, move on to basic coverage of some object-oriented programming concepts, and then jump right into creating Java classes -- the heart of Java programming.

I'll try to give examples and instructions that are as platform-neutral as possible, but I'll default to the Windows platform when necessary. Unix users should have an easy time interpreting these examples for the Unix world. Mac and other users will have to work a little harder (our apologies).

High-level overview of Java
Java is a general-purpose, object-oriented language that looks a lot like C and C++. Its design, however, was built on those of its predecessors, making it easier, safer, and more productive than C++. While Java started out as a niche language for developing applets or small programs that run in Web browsers, it has evolved to arguably become the most important programming language for developing ecommerce and other Web-driven applications. Its area of use is growing daily and includes dynamic Web-content generation with servlet technology, the building of business components with Enterprise JavaBeans, the creation of cross-platform user interfaces with Swing, and much more. Portable, distributed, multitier, object-oriented programs driven by the Web are the order of the day, and there is no language better than Java for writing these programs.

The Java Virtual Machine
Let's take a look at a central component of the Java architecture, the Java Virtual Machine (JVM). The JVM is what gives Java its cross-platform functionality and many of its security and safety capabilities. The JVM is basically an abstract computer implemented in software. I'll focus mainly on its instruction set, which is called bytecode. Bytecode is an intermediate language between Java source and the target computer you want to run on. The following figure demonstrates how it works at a very high level.


From Java source to bytecode to host machine code

  • Programs are written in Java and stored in .java files (for example, MyClass.java)
  • The .java files are compiled by the Java compiler into bytecode and stored in .class files (for example, MyClass.class)
  • The JVM loads the bytecode (the .class files), performs some checks on it, and then converts it to the machine code of the target platform that executes it

This is where Java gets its platform independence. The bytecode format is the same on all platforms because it runs in the same abstract machine -- the JVM. As long as there is a JVM on any given platform, you can run Java on it. There's an old saying in computer programming, "You can solve any problem with another level of indirection." The JVM and bytecode together is another level of indirection.

That's about it on the JVM for now. If you want to know more, check out Sun's JVM specification in the Resources section below.

Setting up Java on your system
The first thing you need is the Java 2 Software Development Kit or SDK (formerly known as the Java Development Kit, or JDK). This is a set of software and software tools supplied by Sun that includes all of the basic components needed to build Java programs. If you don't have this, you'll need to download the Java 2 SDK from Sun (see Resources below). Here's a brief description of what you need to do to install version 1.2.x for the Windows platform:

  • For Windows, the download will be a self-extracting archive, and the file name follows the form: jdk<version>-win.exe. For example, for version 1.2.2, the file is named jdk1_2_2-win.exe.
  • Execute the program to install the Java 2 SDK.
    • You can execute it by typing its name at a command prompt.
    • You can double-click it from Explorer.
    • On Windows, the default installation directory is C:\JDK1.2.x

  • You must set up your environment correctly
  • Your path must be set to include the bin subdirectory
  • For example, if you installed the Java 2 SDK in C:\JDK1.2.x, you must include C:\JDK1.2.x\bin in your path
    • If you are using Windows 95/98, you can do this in autoexec.bat
    • If you are using Windows NT, go to Control Panel, System, Environment
    • You can set environment variables in the dialog box there
  • There are other parts of the environment that are important, especially the CLASSPATH environment variable. I'll discuss this in future columns.

  • It's also important to download the javadoc HTML documentation for the core API classes. This is a separate download, in zip format, and the filename is in the form of jdk<version>-doc.zip (for example, jdk1_2_2-doc.zip).
  • The javadoc HTML documentation should be unzipped into the Java 2 SDK installation directory
    • Note that the zip file has a directory structure within it, so that unzipping it into C:\ will place all of the files at the root directory C:\JDK1.2.x\docs, which is a good place for them.

The following tools will be used to create and run our first program:

  • javac: the Java compiler that converts Java source to bytecode
  • java: the Java Virtual Machine



Sponsored Links

Top Offers

Mortgage rates are still low. Get the lowest Mortgage rates available and compare mortgage options for every situation. Bad Credit OK! Find the best Refinance mortgage rates fast and easy. Home loans, Home Equity Loans and Debt Consolidation at MortgageLoan.com.

Java Developers Wanted - J2ME Developer and Sr. Software Engineer positions open at 4INFO. Contact ijobs@4info.net

Real time internet mortgage leads delivered within minutes.

Personal Loans - Offers credit applications to a range of mortgage loans, auto loans, personal loans and credit cards.

Bad Credit Loans - Offers bad credit loan applications to a range of personal loans, mortgage loans, home equity, refinance and debt consolidation loans.

Refinance Mortgage Mortgage refinancing, home loans and home equity loans

Mortgage Leads Internet Mortgage Loan Leads Generation

California Home Loan California refinance mortgage lender and home equity loans.


 

Copyright ©  2006 Codingmentor.com All Rights Reserved.