Introduction To Java PP1
Introduction To Java PP1
TTI 2014
Contact Info
Joseph Vinisky
Blog: codeny.blogspot.com
Email: codenyx@gmail.com
Course Topics
Introduction to Java
Fundamentals
Objects and Classes
Inheritance
Interfaces and Inner Classes
Deploying Applications
Debugging and Exceptions
Multithreading
Week 1
Introduction
What is Java?
Installing the Java SDK and Eclipse IDE
Language Fundamentals
History of Java
Began as a Sun Microsystems project called
Green
James Gosling
Javas Evolution
Versions of Java
Java SE Standard Edition
Java ME Micro Edition embedded devices
or resource constrained devices set top
boxes, blu-ray players, mobile devices
Java EE Enterprise Edition For server side
processing
Uses of Java
Write Once, Run Anywhere
Stand alone applications
Applets (java code embedded into webpages run
via we browser)
Servlets (server side Java code that interact with
clients typically using HTTP)
Android development
Programming Languages
Interpreted languages
Perl
Python
PHP
Compiled languages
BASIC
C/C++
Fortran
Java (to bytecode)
JVM Approach
Architecture neutral
Only need an implementation of JVM for the native
machine
Same Java code will run on all platforms
Portable
The results on x86 = results on ARM = results on PPC
Caveat: dont always fully utilize architecture capabilities
Object oriented
Everything is a class
Another Example
Uses an array of three strings and a loop
public class Greetings {
public static void main(String[] args) {
String[] greeting = new String[3];
greeting[0] = "Welcome to BNAI ZION";
greeting[1] = Introduction to Java";
greeting[2] = Spring 2012 ";
for(String thisline : greeting)
System.out.println(thisline);
}
}
Class
Class is a container for the program logic that
defines the behavior of an application
Building blocks with which all Java applications
and applets are built.
Everything in a Java program must be inside a
class.
Following the keyword class is the name of the
class.
Names must begin with a letter, and after that,
they can have any combination of letters and
digits.
Variables
For any meaningful program you need to modify data
Variables are used to store values
Operators operate on one or two variables
Forming expressions
Declare a variable called Name of type type:
type Name;
Example:
String name;
int a, b;
Integer Types
Range depends on size of each type:
long (8 bytes) -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
int (4 bytes) -2,147,483,648 to 2,147,483,647
short (2 bytes) -32,768 to 32,767
byte (1 byte) -128 to 127
Representing Characters
Unlike C, where char is almost always a single
byte, a Java char can hold a multi-byte Unicode
character
Every char is 16 bits (2 bytes), and stores either a
complete character of Unicode U+0000 to U+FFFF
or half of a U+10000 to U+10FFFF character
In most cases, String variable should be used to
avoid having to worry about character types and
lengths.
String pi = "\u03C0;
//
Boolean Types
Can only indicate two values , true or false
Unlike C/C++, integer 0 and 1 are not equivalent to
false and true
Avoid easy-to-create bugs. For example:
if((x=1)) {
statement;
} //this would not compile in Java
Must use true and false when assigning boolean
variables
No implicit conversion is possible between boolean
and other data types
Strings
Enumerated Types
Size shirtSize=Size.one-of-the-above;