Search Java Tutorials

Custom Search

What You Will Want to Complete This Tutorial?

You must have at least 1st and 2nd pre-requirements to start the tute. Other requirements will require for last chapters only. These all are free to use and download!
  1. Java Development Kit Standard Edition (JDK / J2SE) Any Version(www.java.com)
  2. Any Text Editor (Note Pad quite enough or get Notepad++ from (http://notepad-plus.sourceforge.net)
  3. Java Run Time Environment (JRE) Any Version(www.java.com)
  4. Java Enterprise Edition (J2EE) for advanced developing (For last few chapters)(www.java.com)
  5. Java Wireless Toolkit for Mobile Application Development (For Mobile Application Development Chapters) (www.java.com)
  6. Tomcat Web Server to run Servlets. (www.tomcat.apache.org/)
Your operating system may be any version of Windows.
What will you learn (As a summary)?
  1. How to build console and windowed applications using Java
  2. How to build web page elements with Java Applets
  3. How to build Database Programs with Java
  4. How to build enterprise applications with Beans
  5. How to add Email functions to Java programs
  6. How to program smart devices (Phone, PDA etc…) with Java

Improving your code

There is no use of a program at least it can’t hold the data given by its user. So, lets do something to improve our sample code we used in chapter one,

This is what we coded in chapter 01:

Now this program has no ability to hold values from the user. On the other hand, that means

your program do not interact with computer memory seriously. It just prints “First Java Program” that defined as a literal string inside the program code.

Following is little bit changed, and improved code. Other than printing texts directly from the code, this program first hold texts in computer main memory, and then gets them back and print on screen.

In this code, we use something called “Variable”. A Variable is a named memory location that we can use to hold/store values. This program will declare a memory location called “strCountry” and then assign a value “Sri Lanka”.

Line 1: Declares the class “Variables01”.

Line 2: Open the class

Line 3: Declares the method “main”

Line 4: Opens the method

Line 5: Creating a variable in computer memory known as “strCountry”

Line 6: Set the value in “strCountry” to “Sri Lanka

Line 7: Prints “Your Country is:” on screen

Line 8: Prints value in “strCountry” on screen

Line 9: Closing “main” method

Line 10: Closing “Variables01” class

Following figure shows how to compile and run this program, and also its output.


This is how your memory looks like while the program is running.

No comments: