Showing posts with label Core Java. Show all posts
Showing posts with label Core Java. Show all posts

Saturday, December 1, 2007

Precedence and Associativity Rules for Operators in Java

Precedence and Associativity Rules for Operators
Precedence and associativity rules are necessary for deterministic evaluation of expressions.

Precedence rules are used to determine which operator should be applied first if there are two operators with different precedence, and these follow each other in the expression. In such a case, the operator with the highest precedence is applied first.
2 + 3 * 4 is evaluated as 2 + (3 * 4) (with the result 14) since * has higher precedence than +.

Associativity rules are used to determine which operator should be applied first if there are two operators with the same precedence, and these follow each other in the expression.
Left associativity implies grouping from left to right, Right associativity implies grouping from right to left.

Monday, November 26, 2007

What is in java.lang package?

The lang package

The java.lang package provides classes that are fundamental to the Java programming language.
java.lang is automatically imported in all programs. It is java's most widely used package.

java.lang package provides 29 classes and three interfaces. Due to its importance, the java.lang package is provided with all Java platforms ranging from Embedded Java to the JDK.

Interfaces in java.lang

The java.lang package contains three interfaces namely

  • Cloneable
  • Comparable
  • Runnable

Cloneable : A class implements Cloneable to indicate the Object.clone() method that it is authorized to make a copy of instances of that class.

The exception CloneNotSupportedException will be thrown if the user clones instances, which do not implement the Cloneable interface. The interface Cloneable declares no methods.

Comparable : Java 2 adds a new interface to java.lang called Comparable. Classes that implement Comparable interface contain objects that can be compared with each other.

The comparable method declares only one method. The syntax is:

int compareTo(Object obj)

this method compares the invoking object with 'obj'. It returns 0 if the values are equal.

Runnable : Any class that initiates a separate thread of execution must implement the Runnable interface.

Runnable defines only one abstract method, called run(), which is the entry point to the thread. Threads that are created by the user must implement abstract void run() method.

Thursday, November 1, 2007

What is diffrence between java and java script?

What is diffrence between java and java script?

Java and javascript both based on objects and their is a tight relation ship between these two.
The major difference between these two are:

1.Java is compiled language but javascript is an interpreted language.
2.Java is strongly typed language i.e,it is necessary to declare variables before use but it is not the case with javascript.
3.Java is used independently while javascript is used with in html tags and require web browser to run.
4.java files have the file extension of '.java' while javascript files have extension of '.js'
5.Java can be used for designing standalone applications as well as web pages also while javascript can only be used for designing wed pages.

Wednesday, October 31, 2007

Generics in Java Programming.

Generics

Generics were added to the Java language syntax in version 1.5. This means that code using Generics will not compile with Java 1.4 and less.

Java was long criticized for the need to explicitly type-cast an element when it was taken out of a "container/collection" class. There was no way to enforce that a "collection" class contains only one type of object. This is now possible since Java 1.5.

In the first couple of years of Java evolution, Java did not have a real competitor. This has changed by the appearance of Microsoft C#. With Generics Java is better suited to compete against C#.

What are Generics?

Generics are so called because this language feature allows methods to be written generically, with no foreknowledge of the type on which they will eventually be called upon to carry out their behaviors. A better name might have been type parameter argument. Because, it is basically that, to pass a Type as a parameter to a class at creation time.

When an object is created, parameters can be passed to the created object, through the constructor. Now with Generics, we can also pass in Types. The type-place-holders will be replaced with the specified type, before the object is created.

Type parameter arguments can be set:
for a class
When an object is created from that class the type-parameter-argument will be replaced with the actual Type.
public class Person
{
private Person person;
...
}...// --- Create an Employee person ---
Person emplPerson = new Person();
...
// --- Create a Customer person ---
Person custPerson = new Person();

for a method

Just like class declarations, method declarations can be generic--that is, parameterized by one or more type parameters.
static public void assign( Person person, T obj )
{
person.setPerson( obj );
}
use of generics is optional


For backwards compatibility with pre-Generics code, it is okay to use generic classes without the generics type specification thing (). In such a case, when you retrieve an object reference from a generic object, you will have to manually typecast it from type Object to the correct type. The compiler should also warn about unsafe operations.

Introduction

Java is a "strongly" typed language. That's why it is so easy to use. Many potential problems are caught by the compiler. One area where Java was criticized was regarding the "Container/Collection" objects. Container objects are objects that contain other objects. Before Generics were introduced there was no way to ensure that a container object contains only one type of objects. When an object was added to a container, it was automatically cast to Java Object. When it was taken out an explicit cast was needed. Normally an explicit cast is checked by the compiler.

String st = "This is a String";
...
Integer integer = (Integer) st; // --- Compilation Error --

But in the case of container classes, the compiler was not able to catch an invalid type casting.

1 Collection collString = new ArrayList();
2 collString.add( "This is a String" );
...
3 Integer integer = (Integer) collString.get(0); // --- No Compilation Error; RunTime CastException

Just looking at line 3, we do not know what type of objects collString contains. If that contains Integers then the code is fine.

The above code using Generic:
Collection<String> collString = new ArrayList<String>();
collString.add( "This is a String" );
...
Integer integer = (Integer) collString.get(0); // --- Compilation Error

collString is a container object, that can contain only String objects, nothing else, so when we get out an element it can be casted only to class that normally a String can be casted.

With Generics, Java strict type checking can be extended to container objects. Using Generics with container classes, gives an impression that a new container type is created, with each different type parameter. Before Generics:

Collection collCustomer = new ArrayList();
collCustomer.add( new Customer() );
...
Collection collObject = collCustomer; // --- No problem, both collObject and collCustomer have the same type

With generics:
Collection collCustomer = new ArrayList();
collCustomer.add( new Customer() );
...
Collection(object) collObject = collCustomer; // --- Compilation Error

Both collObject and collCustomer have the same type, BUT it is against the Generic rule, that is collCustomer can contain only Customer objects, and collObject can contain only Object object. So there is an additional check to the normal type checking, the type of the parameter type has to be matched too.

Note for C++ programmers

Java Generics are similar to C++ Templates in that both were added for the same reason. The syntax of Java Generic and C++ Template are also similar.

There are some differences however. The C++ template can be seen as a kind of macro, that generates code before compilation. The generated code depends on how the Template class is referenced. The amount of code generated depends on how many different types of classes are created from the Template. C++ Templates do not have any run-time mechanisms. The compiler creates normal code to substitute the template, similar to any 'hand-written' code.

In contrast, Java Generics are built into the language. The same Class object handles all the Generic type variations. No additional code is generated, no matter how many Generic objects are created with different type parameters. For example.

Collection collString = new ArrayList<String>();
Collection collInteger = new ArrayList();

There is only one Class object created. In fact, at runtime, both these objects appear as the same type (both ArrayList's). The generics type information is erased during compilation (type erasure). This means, for example, that if you had function that takes Collection as an argument, and that collection happened to be empty, your function would have no way of instantiating another T object, because it doesn't know what T was.

The Class
class itself is generic since Java 1.5.

public final class Class extends Object implements Serializable, GenericDeclaration, Type, AnnotatedElement{
...
}

The T type here represents the type that is handed to the Class object. The T type will be substituted with the class being loaded.

Class

Since Java 1.5, the class java.lang.Class is generic. It is an interesting example of using genericness for something other than a container class.

For example, the type of String.class is Class, and the type of Serializable.class is Class. This can be used to improve the type safety of your reflection code.

In particular, since the newInstance() method in Class now returns a T, you can get more precise types when creating objects reflectively.

Now we can use the newInstance() method to return a new object with exact type, without casting.

Customer cust = Utility.createAnyObject(Customer.class); // - No casting
...
public static T createAnyObject(Class cls) {
T ret = null;
try
{
ret = cls.newInstance();
}
catch (Exception e) {
// --- Exception Handling
}
return ret;
}

And the above code without Generics:

Customer cust = (Customer) Utility.createAnyObject(Customer.class); // - Casting is needed
...
public static Object createAnyObject(Class cls)
{
Object ret = null;
try
{
ret = cls.newInstance();
}
catch (Exception e)
{ // --- Exception Handling }
return ret;
}

Get exact type when getting JavaBean property, using reflection

See the following code where the method will return the exact type of the Java Bean property, based on how it will be called.
// --- Using reflection, get a Java Bean property by its name ---

public static T getProperty(Object bean, String propertyName)
{
if (bean == null propertyName == null propertyName.length() == 0)
{
return null;
} // --- Based on the property name build the getter method name ---
String methodName = "get" +propertyName.substring(0,1).toUpperCase() + propertyName.substring(1);
T property = null;
try
{
java.lang.Class c = bean.getClass();
java.lang.reflect.Method m = c.getMethod(methodName, null);
property = (T) m.invoke(bean, null);
}
catch (Exception e)
{ // --- Handle exception -- }
return property;
}

Variable Argument

With Generic it is very easy to define a method with variable argument. Before generic usually passing in array was close to the variable argument. The only requirement is that the arguments in the list must have the same type.

The following code illustrates the method that can be called with variable arguments:
/**
* Method using variable argument list
* @param
* @param args
*/
public static List makeAList(T... args)
{
List argList = new ArrayList();
for (int i = 0; i <>
{
argList.add(args[i]);
}
return argList;
}

And the above method can be called with variable argument, see below:

List<String> list1 = makeAList("One", "Two", "Three");
List<String> list2 = makeAList("One", "Two", "Three", "Four");

In the above calls the arguments must be String. If we for the T, then we can pass in any kind of objects regardles of their type. See below:

List list3 = makeAList("One", 10);

Note: the number 10 in the above code will be converted (autoboxed) to Integer.

See also: java.util.Arrays.asList(T... a)

Wildcard Types

As we have seen above, generics give the impression that a new container type is created with each different type parameter. We have also seen that in addition to the normal type checking, the type parameter has to match as well when we assign generics variables.

In some cases this is too restrictive. What if we would like to relax this additional checking? What if we would like to define a collection variable that can hold any generic collection, regardless of the parameter type it holds?

Wildcard

The wildcard type is represented by the character , and pronounced Unknown, or Any-Type. This Unknown type matches anything, if it is used only by itself. Any-Type can be express also by . Any-Type includes Interfaces, not only Classes.

Tuesday, October 30, 2007

Core Java FAQs or Interview Questions--2

Core Java FAQs or Interview Questions:--2

1)What is the difference between an Abstract class and Interface?
Abstract classes may have some executable methods and methods left unimplemented. Interfaces contain no implementation code.
-- An class can implement any number of interfaces, but subclass at most one abstract class.
--An abstract class can have nonabstract methods. All methods of an interface are abstract.
--An abstract class can have instance variables. An interface cannot.
--An abstract class can define constructor. An interface cannot.
--An abstract class can have any visibility: public, protected, private or none (package). An interface's visibility must be public or none (package).
--An abstract class inherits from Object and includes methods such as clone() and equals().

2)What are checked and unchecked exceptions?
Java defines two kinds of exceptions :

-->Checked exceptions: Exceptions that inherit from the Exception class are checked exceptions. Client code has to handle the checked exceptions thrown by the API, either in a catch clause or by forwarding it outward with the throws clause. Examples - SQLException, IOxception

-->Unchecked exceptions: RuntimeException also extends from Exception. However, all of the exceptions that inherit from RuntimeException get special treatment. There is no requirement for the client code to deal with them, and hence they are called unchecked exceptions. Example Unchecked exceptions are NullPointerException, OutOfMemoryError, DivideByZeroException typically, programming errors.

3)What is a user defined exception?
User-defined exceptions may be implemented by

* defining a class to respond to the exception and

* embedding a throw statement in the try block where the exception can occur or declaring that the method throws the exception (to another method where it is handled).

The developer can define a new exception by deriving it from the Exception class as follows:

public class MyException extends Exception {
/* class definition of constructors (but NOT the exception handling code) goes here */
public MyException() {
super();
}
public MyException( String errorMessage ) {
super( errorMessage );
}
}

The throw statement is used to signal the occurance of the exception within a try block. Often, exceptions are instantiated in the same statement in which they are thrown using the syntax.
throw new MyException("I threw my own exception.")
To handle the exception within the method where it is thrown, a catch statement that handles MyException, must follow the try block. If the developer does not want to handle the exception in the method itself, the method must pass the exception using the syntax:
public myMethodName() throws MyException


4)What is the difference between C++ & Java?
Well as Bjarne Stroustrup says "..despite the syntactic similarities, C++ and Java are very different languages. In many ways, Java seems closer to Smalltalk than to C++..".

:* Java is multithreaded

* Java has no pointers

* Java has automatic memory management (garbage collection)

* Java is platform independent (Stroustrup may differ by saying "Java is a platform"

* Java has built-in support for comment documentation

* Java has no operator overloading

* Java doesn’t provide multiple inheritance* There are no destructors in Java


5)What are statements in JAVA ?
Statements are equivalent to sentences in natural languages. A statement forms a complete unit of execution. The following types of expressions can be made into a statement by terminating the expression with a semicolon

* Assignment expressions

* Any use of ++ or --

* Method calls

* Object creation expressions

These kinds of statements are called expression statements. In addition to these kinds of expression statements, there are two other kinds of statements. A declaration statement declares a variable. A control flow statement regulates the order in which statements get executed. The for loop and the if statement are both examples of control flow statements.

6)What is JAR file ?
JavaARchive files are a big glob of Java classes, images, audio, etc., compressed to make one simple, smaller file to ease Applet downloading. Normally when a browser encounters an applet, it goes and downloads all the files, images, audio, used by the Applet separately. This can lead to slower downloads.

7)What is JNI ?
JNI is an acronym of Java Native Interface. Using JNI we can call functions which are written in other languages from Java. Following are its advantages and disadvantages.

Advantages:

* You want to use your existing library which was previously written in other language.

* You want to call Windows API function.

* For the sake of execution speed.

* You want to call API function of some server product which is in c or c++ from java client.

Disadvantages:

* You can’t say write once run anywhere.

* Difficult to debug runtime error in native code.

* Potential security risk.

* You can’t call it from Applet.

8)What is serialization ?
Quite simply, object serialization provides a program the ability to read or write a whole object to and from a raw byte stream. It allows Java objects and primitives to be encoded into a byte stream suitable for streaming to some type of network or to a file-system, or more generally, to a transmission medium or storage facility. A seralizable object must implement the Serilizable interface. We use ObjectOutputStream to write this object to a stream and ObjectInputStream to read it from the stream.

9)Why there are some null interface in java ? What does it mean ? Give me some null interfaces in JAVA ?
Null interfaces act as markers..they just tell the compiler that the objects of this class need to be treated differently..some marker interfaces are : Serializable, Remote, Cloneable

10)Is synchronised a modifier?indentifier??what is it??
It's a modifier. Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.

Core Java FAQs or Interview Questions

Core Java FAQs or Interview Questions

1)What is singleton class?where is it used?

Singleton is a design pattern meant to provide one and only one instance of an object. Other objects can get a reference to this instance through a static method (class constructor is kept private). Why do we need one? Sometimes it is necessary, and often sufficient, to create a single instance of a given class. This has advantages in memory management, and for Java, in garbage collection. Moreover, restricting the number of instances may be necessary or desirable for technological or business reasons--for example, we may only want a single instance of a pool of database connections.

2)What is a compilation unit?

The smallest unit of source code that can be compiled, i.e. a .java file.

3)Is string a wrapper class?

String is a class, but not a wrapper class. Wrapper classes like (Integer) exist for each primitive type. They can be used to convert a primitive data value into an object, and vice-versa.

4)Why java does not have multiple inheritance?

The Java design team strove to make Java:
Simple, object oriented, and familiar
Robust and secure
Architecture neutral and portable
High performance
Interpreted, threaded, and dynamic

The reasons for omitting multiple inheritance from the Java language mostly stem from the "simple, object oriented, and familiar" goal. As a simple language, Java's creators wanted a language that most developers could grasp without extensive training. To that end, they worked to make the language as similar to C++ as possible (familiar) without carrying over C++'s unnecessary complexity (simple).

In the designers' opinion, multiple inheritance causes more problems and confusion than it solves. So they cut multiple inheritance from the language (just as they cut operator overloading). The designers' extensive C++ experience taught them that multiple inheritance just wasn't worth the headache.

5)Why java is not a 100% oops?

Many people say this because Java uses primitive types such as int, char, double. But then all the rest are objects. Confusing question..

6)What is a resource bundle?


In its simplest form, a resource bundle is represented by a text file containing keys and a text value for each key.

7)What is transient variable?

Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can't be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null.

8)What is Collection API?

The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces. Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.Example of interfaces: Collection, Set, List and Map.

9)Is Iterator a Class or Interface? What is its use?

Iterator is an interface which is used to step through the elements of a Collection.

10)What is similarities/difference between an Abstract class and Interface?

Differences are as follows:
* Interfaces provide a form of multiple inheritance. A class can extend only one other class.
* Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc.
* A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class.
* Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast.

Similarities:
* Neither Abstract classes or Interface can be instantiated.

Monday, October 29, 2007

API's and Javadoc: What are they?

API's and Javadoc: What are they?

An API stands for a "Java Application Programming Interface". It is like a super dictionary of the Java language, that one uses to look something up in. It has an index or collection of all Java packages, classes and interfaces, with all of their methods, fields and constructors, and how to use them. When one programs, there are many classes that are commonly used, and therefore pre created, so that the programmer doesn't need to create them from scratch. Let's look, for example, at a computer window frame. If the programmer had to create one from scratch, he would have to write hundreds of lines of code, to create the scroll down menu, the exit box, etc. Since a window frame is very popular, Sun has written the code for one, and all that you have to do is import the package that contains the window frame, and instantiate one with a new statement.
As with all of Sun's classes, we do not care how it is implemented, all we need to know are what the methods are, the constructors, and it's fields. Hence the name Java Application Programming Interface, the API is a collection of interfaces telling us what each class can do, not telling us how it is done. The API contains many packages for many different purposes, among them, the applet package for creating applets, the awt and swing packages for graphics and GUI, the io package for input and output, the sql package for Java databasing, and many many more. For every package that you use a class from you must import it, with the exception of the java.lang package that deals with basic programming classes, that is automatically imported into your program.

Each API is organized in the following way. When you start the API you are given three frames, the first listing all of the Java packages in that API, and when you click on any particular package, the second frame lists all of the interfaces, classes, and exceptions in that package. The main frame starts with an overview of all of the packages, and shows the index, class hierarchy for each package, and help section when you click for it on the top menu. Also, it gives you the details for each class document. The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields. The class document is set up with the top showing that class inheritance diagram and subclasses, the middle showing the field, method, and constructor summaries, and the bottom giving details for the fields, methods, and constructors.


In short, when you start programming, you're constantly going to have to look up something in the API. There's going to be some class or method that you don't know how to use, you're not sure what parameters it takes, etc, and you can find out all of the information in the API. When Shlomo started writing Java, a certain program always crashed during some String methods, and Shlomo spent hours trying to figure it out unsuccessfully. Finally someone looked up the String methods in the API, noticed that the method substring() was spelled substring() instead of the assumed subString(). Well, Shlomo was extremely impressed, until he himself figured out how to use the API, and realized how easy it was.

Javadoc is the ability to create these API looking documents out of your own code. When you write your code you place html tags and javadoc tags in special comments (that look like this)
/*
*
* place comments here
*
*/
These comments you place before the beginning of the code for your class, and before most of your methods. Then instead of typing in java or javac on the CMD console, you type "javadoc nameOfClass" or "javadoc NameOfPackage". The compiler will then create an html document, that explains your methods, fields and constructors, plus whatever HTML that you added, in the same exact way that the API looks.
For more information on javadoc, check out Sun's official tool section .

Basic Java terminology

Basic Java terminology

The purpose of this page is to help the beginner with the basic Java terminology. The terminology below is meant to be easily understood, and is therefore not given a technical definition.
  • processor: The processor is inside the brain of the computer, and it is its job to read, or process, the instructions. It takes each instruction (after it has been broken down into basic computer language by the compiler) and runs it, turning on and off switches, causing the program to execute.

  • CPU: The CPU or Central Processing Unit, is the brain of the computer. It holds inside it the processor, the Arithmetic Logical Unit (ALU: the computer's math machine), and controls and tells the rest of the computer what to do.

  • code: Code just means the instructions that the programmer writes. The code of a program means the part that the programmer wrote up, and will give to the computer to run.
    compiler The compiler "translates" the code that you have written in the language that you understand (like Java) into a language that the computer understands, either assembly language, or pure computer language (ones and zeros).

  • keywords: Keywords are words that have a very specific meaning to the compiler. Whenever the compiler sees one, it knows what it is, and translates it as such. For example, the word "int" means a number. Whenever in the program the programmer writes "int", it has only that meaning, a number. The programmer can never use it for something else. Another example is the word "if". If means try to see if what I am saying is true. If it is then do the next line, if not not. The word if can only mean that, and can never change. There are approximately 30 keywords.

  • control statements: Whenever the computer runs a Java program, it goes straight from the first line of code to the last. However, lets say you only want to run some code on condition. For example, you are writing an adventure game, and your player is hit, do you want him to die, or not. Well, it depends, how many "hits" is he allowed to have before he dies. So you want a control statement that says "if he is down to his last hit, then run the dying code, else subtract the number of hits that he is allowed, and continue". The if else is one kind of control statement, and it changes control to read from a different line of code, instead of the next.

  • Variables: Variables are words in your code, that have different meanings based on different times in the program. Why would I want that? The reason is, that that which makes a computer so powerful, is the ability to be given a set of instructions, and act differently based on the circumstances. For example, in the adventure game, your player has the ability to be hit 5 times before he dies. That number is going to change, as he runs through the game. Sometimes when he gets to the tower (for example) he will have 4 "hits" remaining, sometimes he will be down to his last one, and when the bad guy comes and hits him he will die. How is the computer able to keep track and know this? With variables. There will be one variable that is called "life", and you will start it off with 5. Every time that the player gets hit, you will tell life to subtract from itself one. You will also check, if life equals zero, then run the code to die. Since "life" is a variable and not a keyword, you will create this word. I called it life, but you can call it whatever you like. Also, when you go online, the computer asks you to tell them your name. You type in "Shlomo" (assuming that that is your name). Then for the rest of the time that you are on that site they always call you Shlomo. You go onto a new page, and they say "Shlomo, what do you want to buy?". They don't have a hundred premade web pages for each name. Instead, they collect your name into a variable, let's call firstName, and have one web page that says "print out 'firstName, what do you want to buy'".

  • operations and operands: Operations are symbols that have a specific meaning. Operands are the words that use the operations. For example the line " salary + bonus " means take the two operands of salary and bonus, and use the operation of "+" to add them. In Java the operation of "+" means to add, the operation of "=" means to get, and the operation of "==" means equal. "int payment = salary + bonus " means create a number variable called "payment" and let it get the variable of salary added to the variable of bonus.

  • int : in Java a number is represented by the word int. However, this is only one representation. For a complicated number like 4.5, you will need a different representation, like "double" or "float". The word "int" is a keyword that means number. If you write "int payment" you are saying that you are making a variable called payment that is a number. If you write "int payment = 5" you are saying that you are making a variable called payment that is a number and giving it the value of 5.

  • String : A string is a variable that holds a word, or a few words, or a mixture of characters, that do not mean anything besides for a quote. Meaning: when I go online and they ask me for my name, I tell them "Shlomo". They save that quote of "Shlomo" in a String variable. The actual word "Shlomo" doesn't mean anything to the compiler. However, whenever the program wants to call my name it says "print out that String that we called firstName" and whatever is in that String is printed. For example, if I were to write a piece of code "String message = "How are you today?", I would be telling the computer that there is a variable called message, and whenever I refer to that variable, I am referring to the String of "How are you today?".

  • Primitive : Almost everything in Java is an Object or Class, meaning that it has inside it operations, behaviors and methods. Primitives are the exception. A primitive is only what it is, and nothing more, it can not do anything but hold that one piece of information that it is supposed to hold. For example, an int is a primitive. It can only hold a number. A String is an Object, it can change itself. Meaning, I can tell the String change yourself to be capitalized, and the String of "hello" will change into "HELLO". A primitive can not do anything besides hold itself.

  • Debugging : debugging means finding the errors and fixing them.

  • interfaces, user interfaces, and GUI : An interface simply means the way that two entities communicate with each other. For example, if two people write two separate programs that interact with each other, they communicate with each other through an interface. If you write a program that works on a real system, like an ATM, then in order to communicate with the money dispenser, you will need an interface in between. An interface allows the ability to say I don't know how you do what you are doing, all I need is a common way to communicate and get the information that you are giving me that I need to use, and give you only what you need to use. (In Java there is a special thing called an interface, check out the above note). A user interface is the way that a user interacts with a machine. The user doesn't need to know how the machine works, or what is going on inside, it just needs to be able to interact with it. The command console below is a user interface. A GUI or Graphical User Interface is an user interface, that talks to the user using graphics. For example, Windows is a GUI. Instead of typing in the word "exit", "OK', or whatever you will need to type, in a GUI you can press a button, use a scrollbar, etc.

A Command Line User Interface (CUI)
The ability to talk to the computer. You need a new folder you type md, you need the directory you type dir, etc.




A Graphical User Interface (GUI)
The ability to talk to the computer with graphics. You need a new folder you right click, you need the directory you click the folder, etc.



Wednesday, October 24, 2007

Solution to the common error, while compiling your your java program

Prevent Errors like --> 'javac' is not recognized as an internal or external command

1. Go to http://java.sun.com and download the latest Version of Jave SDK or any Jace SDK as per your requirement and install on your system.

2. Accept all of the defaults and suggestions, but make sure that the location where Java will be installed is at the top level of your C: drive. Click on "Finish."
You should have a directory (folder) named C:\j2sdk1.5.0_04, with subfolders C:\j2sdk1.5.0_04\bin and C:\j2sdk1.5.0_04\lib4.

Modify your system variable called "PATH" (so that programs can find where Java is located).To do this for Windows 2000 or XP, either right-click on the My Computer icon or select "System" on the control panel. When the window titled "System Properties" appears, choose the tab at the top named "Advanced." Then, click on "Environment Variables." In the bottom window that shows system variables, select "Path" and then click on "Edit..." Add C:\j2sdk1.5.0_04\bin as the first item in the list. Note that all items are separated by a semicolon, with no spaces around the semicolon. You should end up with a path variable that looks something likeC:\j2sdk1.5.0_04\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\system32\Wbem For Windows 98 or ME, open the file AUTOEXEC.BAT in Notepad. You should find a line in this file that beginsSET PATH=...Modify this line to add C:\j2sdk1.5.0_04\bin; immediately after the equals sign.5. Modify or create a system variable called "CLASSPATH," as follows. In the lower "System Variables" pane choose "New..." and type in Variable Name "CLASSPATH" and value (note that it begins with dot semicolon).;C:\j2sdk1.5.0_04\lib6.

To test Java to see if everything is installed properly, open a command window (a DOS window) and type the command "javac" The result should be information about the Usage of javac and its options. If you get a result that "'javac' is not recognized as an internal or external command, operable program or batch file" then there is a problem and Java will not work correctly.

Introduction to Java


Java is a programming language originally developed by Sun Microsystems and released in 1995 as a core component of Sun's Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode which can run on any Java virtual machine (JVM) regardless of computer architecture.
The original and reference implementation
Java compilers, virtual machines, and class libraries were developed by Sun from 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun made available most of their Java technologies as free software under the GNU General Public License.Java's design, industry backing and portability have made Java one of the fastest-growing and most widely used programming languages in the modern computing industry.
The Java language was created by James Gosling in June 1991 for use in a set top box project. The language was initially called Oak, after an oak tree that stood outside Gosling's office - and also went by the name Green - and ended up later being renamed to Java, from a list of random words. Gosling's goals were to implement a virtual machine and a language that had a familiar C/C++ style of notation.The first public implementation was Java 1.0 in 1995

(Duke is the mascot of Java)
Java promises "Write Once, Run Anywhere" (WORA), providing no-cost runtimes on popular platforms.

Tuesday, October 23, 2007

The history of Java


The Java language was created by James Gosling in June 1991 for use in a set top box project. The language was initially called Oak, after an oak tree that stood outside Gosling's office - and also went by the name Green - and ended up later being renamed to Java, from a list of random words. Gosling's goals were to implement a virtual machine and a language that had a familiar C/C++ style of notation. The first public implementation was Java 1.0 in 1995. It promised "Write Once, Run Anywhere" (WORA), providing no-cost runtimes on popular platforms. It was fairly secure and its security was configurable, allowing network and file access to be restricted.

Major web browsers soon incorporated the ability to run secure Java applets within web pages. Java became popular quickly. With the advent of Java 2, new versions had multiple configurations built for different types of platforms. For example, J2EE was for enterprise applications and the greatly stripped down version J2ME was for mobile applications. J2SE was the designation for the Standard Edition. In 2006, for marketing purposes, new J2 versions were renamed Java EE, Java ME, and Java SE, respectively.

In 1997, Sun Microsystems approached the ISO/IEC JTC1 standards body and later the Ecma International to formalize Java, but it soon withdrew from the process. Java remains a de facto standard that is controlled through the Java Community Process. At one time, Sun made most of its Java implementations available without charge although they were closed source, proprietary software.

Sun's revenue from Java was generated by the selling of licenses for specialized products such as the Java Enterprise System. Sun distinguishes between its Software Development Kit (SDK) and Runtime Environment (JRE) which is a subset of the SDK, the primary distinction being that in the JRE, the compiler, utility programs, and many necessary header files are not present.
On 13 November 2006, Sun released much of Java as free software under the terms of the GNU General Public License (GPL). On 8 May 2007 Sun finished the process, making all of Java's core code open source, aside from a small portion of code to which Sun did not hold the copyright.