Tuesday
Java ProgrammingBasics of Java Programming
Basic of Java Programming
- Basics of Java Programming
- Objects of Java
- Java Instance and Static Members
- Inheritance and Aggregation in Java Language
Introduction

Before embarking on the road to Java programmer certification, it is vital to know the basic terminology and concepts in object-oriented programming (OOP). In this chapter, the accent is on providing an introduction very than an exhaustive coverage. In-deepness coverage of the concepts follows in due course in subsequent chapters of the book.
Java supports the writing of many different kinds of executables: applications, applets, and servlets. The basic fundamentals of a Java application are introduced in this chapter. The ancient adage that practice makes perfect is certainly right when culture a programming language. To encourage programming on the computer, the mechanics of compiling and running a Java application are outlined.
Classes
One of the fundamental ways in which we handle complexity is abstractions. An abstraction denotes the essential properties and behaviors of an object that differentiate it from other stuff. The essence of OOP is modelling abstractions, using classes and stuff. The hard part in this endeavour is finding the right abstractions.
A class denotes a category of stuff, and acts as a blueprint for making such stuff. A class models an abstraction by defining the properties and behaviors for the stuff representing the abstraction. An object exhibits the properties and behaviors defined by its class. The properties of an object of a class are also called attributes, and are defined by fields in Java. A field in a class definition is a variable which can store a value that represents a particular property. The behaviors of an object of a class are also known as operations, and are defined using methods in Java. Fields and methods in a class definition are collectively called members.
An vital distinction is made between the narrow and the implementation that a class provides for its stuff. The narrow defines what services, and the implementation defines how these services are provided by the class. Clients (i.e., other stuff) only need to know the narrow of an object, and not its implementation, in order to avail themselves of the object’s services.

As an example, we will implement different versions of a class that models the abstraction of a stack that can push and pop font. The stack will use an array of font to store the font, and a field to indicate the top element in the stack. Using Unified Modeling Language (UML) notation, a class called CharStack is graphically depicted in Figure 1.1, which models the abstraction. Both fields and method names are shown in Figure 1.1a.
Declaring Members: Fields and Methods
Example 1.1 shows the definition of the class CharStack depicted in Figure 1.1. Its intention is to illustrate the salient features of a class definition in Java, and not effective implementation of stacks.
A class definition consists of a series of member declarations. In the case of the class CharStack, it has two fields:
- stackArray, which is an array to hold the fundamentals of the stack (in this case font)
- topOfStack, which denotes the top element of the stack (i.e., index of the last character stored in the array)
- The class CharStack has five methods that implement the essential operations on a stack:
- push() pushes a character on to the stack
- pop() removes and returns the top element of the stack
- peek() returns the top element of the stack for inspection
- isEmpty() determines whether the stack is empty
- isFull() determines whether the stack is full
The class definition also has a method-like declaration with the same name as the class, (2). Such declarations are called constructors. As we shall see, a constructor is executed when an object is made from the class. But, the implementation details in the example are not vital for the present discussion.
Example 1.1 Basic Fundamentals of a Class Definition
// Source Filename: CharStack.java
public class CharStack { // Class name
// Class Declarations:
// (1) Fields:
private char[] stackArray; // The array implementing the stack.
private int topOfStack; // The top of the stack.
// (2) Constructor:
public CharStack(int n) { stackArray = new char[n]; topOfStack = -1; }
// (3) Methods:
public void push(char element) { stackArray[++topOfStack] = element; }
public char pop() { return stackArray[topOfStack--]; }
public char peek() { return stackArray[topOfStack]; }
public boolean isEmpty() { return topOfStack < 0; }
public boolean isFull() { return topOfStack == stackArray.length – 1; }
}
Post Tags: Basic Java, Basic of Java, Basic of Java Programming, Java for Beginner, Java Programming, Learn Java
Related Posts
- The Basics of Multiple Threads in Java
- More About Multithreading in Java
- Computer Programming Essentials – Choose An Easy Way
- Exception Handling Techniques in Java
- Tomcat Performance Tuning
- Network Booting via PXE: the Basics
- Basic Charting with Perl
- Mastering PC Fundamentals From You Tube
- Concurrency—State Models & Java Programs
- Attractive Sites From Nashville Web Designers
Popular
- iPhone or iPod Touch, Which One Should You Choose? - 47,761 views
- Introduction to Facebook - 26,656 views
- 7 Top Twitter Topic Trackers - 16,376 views
- Introduction of Hacking Methodology - 15,051 views
- Google Hacking Keywords - 11,716 views
- LG BD390 Wi-Fi Blu-ray Player Review: So Packed You’ll Forget About Blu [Review] - 10,094 views
- BlackBerry Curve 3G: A Familiar, Powerful Phone - 9,775 views
- Complete Guide to Web Site Marketing - 9,774 views
- Microsoft’s Zune HD Wiill Have OLED, HD Radio - 9,302 views
- Photo Album and Printing Services - 8,953 views
Featured Articles
- The Elements of the Facebook Platform
- Introducing the Facebook Platform
- Social Skills Today Are Being Lost
- GibBook – Gibraltar Own Social Network Site
- 7 Deadly Twitter Sins
- Introduction to Facebook
- Google’s Wave: Many Online Apps in One Tool
- App Mapping War Casualties Debuts for Memorial Day Weekend
- Google@Omgili Mashes Traditional Web Search With Social Buzz
- Capital Factory: Austin-Based Incubator (RWS Interview)
Recent Posts
- Tweet via something
- Lightroom Review And Other Phot
- Several Words About The Advantages Of Tablet PCs
- Dissimilar Positive Features Of Table Computers
- Digi Link Doctor
- Why You Need Professional SEO Software
- Automated SEO Tools For Online Business
- How To Choose The Best Tablet PC
- Tablet PC – The Latest Computer Technology
- Tablet PCs Compared To Laptops