Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

 

 

 

Chapter I: Fundamentals

  • 1.1)What can java do?
  • 1.2)Structure of java program
  • 1.3)What is main() method
  • 1.4)java has a built in treasure Development Kit
  • 1.5)packages & import
  • 1.6)sequence is important
  • 1.7)data types
  • 1.8)java keywords
  • 1.9)identifiers
  • 1.10)initialising
  • 1.11)interface declaration & implementation

1.1)What can Java do?

Java is known for its support for internet applications through its applets.Java is a general-purpose, high-level programming language and a powerful software platform. Using the generous Java API, you can write many types of programs.Java is simple,Object Oriented, Distrinbuted, Portable, interpreted, architecture neutral, Robust, Secure, Multithreaded, Dynamic.

The most common types of programs are probably applets and applications, where a Java application is a standalone program that runs directly on the Java platform. A special kind of application known as a server serves and supports clients on a network. Examples of servers include Web servers, proxy servers, mail servers.Another specialized program is a servlet. Servlets are similar to applets in that they are runtime extensions of applications. Instead of working in browsers, though, servlets run within Java servers, configuring or tailoring the server.

Java API support all of these kinds of programs With packages of software components that provide a wide range of functionality. The core API is the API included in every full implementation of the Java platform.

learn more about java credits from original creaters of java.click here.

 

 

1.2)Structure of a java program

Java is completely object oriented which means java deals everything in terms of objects and object's behaviour.Writing java programs consists of defining the behaviour of user defined and API objects. A java source code file contains one or more classes.

Here is the first program of any programming language

Name this file as Hello.java exclude the line numbers.

1. public class Hello{

2. public static void main(String args[]){

3. System.out.println("hello");

4. }

5. }

  • The name of the file should be the name of the public class defined with the extension .java only.
  • All the code defining the public class is between opening brace ( { ) at line 1 and closing brace ( } ) at line 5.
  • Every typical java statement ends with a semicolon.
  • Java is case sensitive. Hello is not the same as hello.

 

1.3)What is main() method

Every java application must contain a main method whose signature is

public static void main(String args[])

or

static public void main(String args[])

  • Java interpreter starts by calling the class's main method.
  • This main method is the starting point for any application.
  • If you try invoke java interpreter on a class that does not have the main() the interpreter refuses to compile.
  • main methos accepts a single argument which is an array of string. This array is the mechanism through which the runtime system passes info to the application from the command line.
  • Argument index of the string array starts from 0. Therefore first argument is referenced by args[0].
  • any identifier can be used in place of args.

 

1.4)java has a built in treasure Development Kit

Java featured the concept of reuseability more than anything, this is proved by providing huge number of classes ready for use by the programmers and all these classes are bundled together in a heirarchical fashion known as packages.(you will learn more about how this is done later).Java provides a rich set of pre-written classes, giving programmers an existing library of code to support files, networking, graphics, and general language routines; each major category being supported by a collection of classes known as a package.

These are known the Java Foundation Classes(JFC) . These are the APIs included in JFC

  • The abstract Windowing toolokit(AWT):This provides the capability to create platform independent, GUI bases programs and this is very important contributor to the java popularity.
  • Swing:Swing is the code word used by the JavaSoft programming team for the next generation of AWT. Swing extends AWT by supplying many more types of GUI components, providing 100% pure java implementation (these dont depend on native platform OS to support them ) to support them.
  • Java 2D

1.5)using packages and import keyword

*Java allows us to group classes in a collection called Packages

*These are convenient for organising our work and for separating your work from code libraries provided by others

*We can organise packages by using levels of nesting .this guarantees the uniqueness of package names

ex1)name of package at the top of the file

2) In gregarion calender java

Package java.util;

This means that the gregarion calender.java file is part of the java.util package.

*If no explicit package defined java adds the classes in that same file to what is called the default package.

 

1.6 sequence is important

Ordering of Java source file elements: ·

  • When writing a package, the name of the package should be the first line in the source file.
  • import statements if any should be the next one and it should be before the source code of the class.
  • Next comes the public classes, followed by any non-public classes. Eventhough, the order of public and non-public classes doesn't matter usually the public class comes first.
  • A source file can contain atmost one public class definition, and the file name must match the name of the public class.
  • You can have as many top-level classes in one source file, but only one can be declared public and the source file name must match the public class name
  • A source file can contain any number of non-public classes, but each will be compiled into a separate .class file.
  • Having a public class in a source file is not a must. Even if a source file doesn't have a public class the compiler won't complain.
  • Comments are the exception. It can come anywhere in a source file, even before package statement.

For example;

  1. package acme.applications.userinterfaces;
  2. import java.awt.*;
  3. public class SomeClass
  4. { etc.

1.7: Data types and Variables

*Java has two types of variables,primitive variables and reference variiables.

*The primitive variables store data values directely.

*Reference variables store an indirect reference to an object.An object reference in java may be of a class type.You should not think of a reference variable as a direct pointer to an object;all references to objects are indirect and go through java's memory management system .

*Reference is like a handle to an object .

*Note: No pointer arithmetic exits in java and programmer can never manipulate the exact value stored in a reference variable . This is impossible .

*Primitive types : To avoid overhead assosiated with manipulating references , java provides eight common datatypes as primitives

Java primitives and Ranges :

Type Size

 

Range

byte 8 bits -128 to 127
short 16 bits -32768 to 32767
cher 16 bits \u0000 to \uFFFF
int 32 bits

-231

lang 64 bits  
float 32 bits  
double 64 bits  
boolean na true or false

* Classes easily confused with Primitives :

In java.lang package java has standard library classes that are closely related to primitives .

These classes are Byte,Short,Char,Integer,Lang,Float,Double and Boolean .Except for int and Integer,these classes differ from the primitives only in their initial uppercase letter .

Reference Variables :

Classes ,interfaces and array are all reference variable types . Reference variables are declared in statements that define the type of object to which the particular variable can refer .

No limitation exists on the number of variables thatt can refer to the same object .

 

1.8)Java Key words

abstract do implements private throws
boolean double import protected transient
break else inner public true
byte extends instanceOf rest try
byvalue false int return var
cast final interface short void
case finally lang statue volatile
catch fioat native strictfp while
char for new super widefp
class future null switch  
const generic operator synchronzed  
continue goto outer this  
default of package throw  

 

1.9)Identifiers

Identifiers may contain only letters, numbers, dollar signs, i.e. "$", or underscores, i.e. "_". The first character cannot be a number. Obviously an identifier cannot have the same spelling as a keyword or the boolean and null literals (true, false and null)

1.10)Initialising

Determine the value of a member variable of any type when no explicit assignment has been made to it. Class level variables (variables declared in the class, but outside of any methods, i.e. static and instance variables) are automatically initialised to a default value, if no explicit assignment has been made. The defaults are 0 for numerical types, '\u000' for chars, false for booleans, and null for objects.