Tuesday, June 28, 2011

Programming Methodologies

There have been many approaches to programming over the years. Two that are relevant to Java and that you'll probably hear of are:

* Structured Programming


A program is a piece of code with the flow of execution jumping all over the place. Structured programming tried to remove this "spaghetti logic" and enforce a rule where one routine (chunk of code) was responsible for one piece on computation. A program was written by successively invoking a number of these "subroutines".

* Object-Oriented Programming (acronym OOP)

In OOP you can create objects that are a combination of code and data. An object holds its data and knows how to perform various computations on it. For example, a school database program might contain a "Student" type of object. A given student object might hold information about the student's name, age, home address, grade level, test results, etc. The student object might also contain code that could calculate the end-of-year grade, current GPA, and years left until graduation.

Smalltalk was one of the first object-oriented languages. While it is still in use today, Java and C++ are the more currently favored object-oriented languages.

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.