Enter your email address:

    Delivered by FeedBurner

Java Programming


History
• Rapid development
• 1990: developed for use in electronic devices
• about 1995: gained popularity because of possible use in the Internet
• by now: accepted as scalable programming language for different purposes

Java is Designed For
• A fresh start (no backwards compatibility)
• Pure OOP: C++ syntax, Smalltalk style
• Improvements over C++, near guarantee that you can’t run a bad program
• Internet programming: probably can’t create viruses, programmability at the browser end, easier client/server programming
• Larger, more complex programs; smaller teams, less time
• There is the speed issue, which we’ll examine

How does Java generally work ?
• Compilation creates bytecode
• Platform-independent
• Interpreted
• Bytecode is either :
– interpreted statement by statement => "slow"
– once compiled to a program in machine language
=> "fast"

Naming Conventions
• Words run together, no underscores
• Intermediate words capitalized (getValue)
• Classes: first word capitalized (Cell)
• Methods and variables: first word lower case (value, getValue)
• Constants: all caps with underscores to separate words (like C).

Using Other Components
• Bring in a library of components using import keyword
• Can specify specific element in library :
import utility.MyTools;
• Can specify entire library :
import java.util.*;

Java Applications - Important Steps
• Create some source code within your text editor like the class Cell
• Save it as .java - file, use the name of the (primary) class plus the extension .java (e.g. Cell.java)
• Compile the source file :
javac Cell.java
• You get bytecode within a .class - files, for all the classes included (Cell.class)
• Run your application by interpreting the primary class' bytecode java Cell
• The Java interpreter looks for the main-method and executes it.

Booleans
• The primitive type used to express that something can have exactly two different states is called boolean.
• The two literals are true and false.
• Operations on booleans:
– Comparison: ==, !=
– Negation: !
– binary logic: &, |, ^
– short-circuit-evaluation logic: &&, ||

Statements
• There are two general kinds of statement
– simple statements
– compound statements
• Simple statements end with a semicolon.
• Compound statements encompass several statements and are enclosed in brackets.
• Compound statements are also called blocks.
• Blocks are important for scoping.

What does switch do ?
• Tests all case-conditions and executes the statement behind the colon, if the condition is true.
• If a condition is true and the attached statement is followed by a break, switch is finished.
• If no match occurs, the default-statement is executed.
• switch only works on integral values like int or char.

Writing a Java Program
import java.util.*;
class Cell {
int value = ...
void printValue(){
System.out.println(“Date: “ + new Date());
System.out.println(“Value: “+ this.value);
}
public static void main(String [] args){
Cell cell1 = new Cell();
cell1.setValue(4);
cell1.printValue();
}
}

History
• Rapid development
• 1990: developed for use in electronic devices
• about 1995: gained popularity because of possible use in the Internet
• by now: accepted as scalable programming language for different purposes

Java is Designed For
• A fresh start (no backwards compatibility)
• Pure OOP: C++ syntax, Smalltalk style
• Improvements over C++, near guarantee that you can’t run a bad program
• Internet programming: probably can’t create viruses, programmability at the browser end, easier client/server programming
• Larger, more complex programs; smaller teams, less time
• There is the speed issue, which we’ll examine

How does Java generally work ?
• Compilation creates bytecode
• Platform-independent
• Interpreted
• Bytecode is either :
– interpreted statement by statement => "slow"
– once compiled to a program in machine language
=> "fast"

Naming Conventions
• Words run together, no underscores
• Intermediate words capitalized (getValue)
• Classes: first word capitalized (Cell)
• Methods and variables: first word lower case (value, getValue)
• Constants: all caps with underscores to separate words (like C).

Using Other Components
• Bring in a library of components using import keyword
• Can specify specific element in library :
import utility.MyTools;
• Can specify entire library :
import java.util.*;

Java Applications - Important Steps
• Create some source code within your text editor like the class Cell
• Save it as .java - file, use the name of the (primary) class plus the extension .java (e.g. Cell.java)
• Compile the source file :
javac Cell.java
• You get bytecode within a .class - files, for all the classes included (Cell.class)
• Run your application by interpreting the primary class' bytecode java Cell
• The Java interpreter looks for the main-method and executes it.

Booleans
• The primitive type used to express that something can have exactly two different states is called boolean.
• The two literals are true and false.
• Operations on booleans:
– Comparison: ==, !=
– Negation: !
– binary logic: &, |, ^
– short-circuit-evaluation logic: &&, ||

Statements
• There are two general kinds of statement
– simple statements
– compound statements
• Simple statements end with a semicolon.
• Compound statements encompass several statements and are enclosed in brackets.
• Compound statements are also called blocks.
• Blocks are important for scoping.

What does switch do ?
• Tests all case-conditions and executes the statement behind the colon, if the condition is true.
• If a condition is true and the attached statement is followed by a break, switch is finished.
• If no match occurs, the default-statement is executed.
• switch only works on integral values like int or char.

Writing a Java Program
import java.util.*;
class Cell {
int value = ...
void printValue(){
System.out.println(“Date: “ + new Date());
System.out.println(“Value: “+ this.value);
}
public static void main(String [] args){
Cell cell1 = new Cell();
cell1.setValue(4);
cell1.printValue();
}
}

Qidzama

Recent Articles

Blog Archive