Tuesday, February 22, 2011

Basics of java

Identifiers
are used to represent names of variables, methods and classes.

Naming Convention
Many Java programmers use the following conventions:
Classes: start with upper case, then start each word with an upper case letter
Ex: StringBuffer, BufferedInputStream, ArrayIndexOutOfBoundsException
Methods and variables: start with lower case, then start each word with an upper case letter
Ex: compareTo, lastIndexOf, mousePressed

Literals

Values that are hard-coded into a program.

Variables
Memory locations that are associated with identifiers
In Java, variables fall into two categories:

Primitive Types
Simple types whose values are stored directly in the memory location associated with a variable
Example: int var1 = 100;
There are 8 primitive types in Java:
byte, short, int, long, float, double, char, boolean

Reference Types (or class types)
Types whose values are references to objects that are stored elsewhere in memory
Ex: String s = new String(“Hello There”);

starting java

Introduction to Java
Java is an object-oriented language developed by Sun Microsystems in the early 1990s and released in 1995. Java combined many of the best ideas from Pascal, C and various other object-oriented languages.

Java's strengths:


* Good object-oriented model
* Cross-platform language
* Hard to make mistakes that cause a program to crash
* Large standard library of code you can use in your program
* Many non-standard libraries available for free
* Popular (easy to find other programmers to talk to)

Java's weaknesses:
* The virtual machine needs to be running alongside your application. This increases the amount of memory your program needs.
* Because the program runs on a virtual machine, it may be slightly slower than a natively compiled program.
* Because the standard code libraries are designed to be cross-platform, you cannot easily take full advantage of all features unique to a given platform.