Escolar Documentos
Profissional Documentos
Cultura Documentos
part 1- intro
HISTORY:
1991
James gostling
Sun Microsystems
Oak
Motivation- platform independent language embedded in objects
Personal hand held remote-star 7
JAVA TECHNOLOGY(pdad)
Programming language
Development
Application
Deployment
DEVELOPMENT
Javac (complier)
Interprester (java)
Documentation generator (javadoc)
Class file packaging tool
DEPLOYMENT(2)
SDK-software development kit
Web browser
JAVA FEATURES
JVM- java virtual machine
Garbage collection
Code security
JVM
Imaginary machine, compile java codes
Bytecode- cde understood by all JVM
GARBAGE COLLECTION
Frees any memory auto
CODE SECURITY
JRE-perform class loading, code verification and code execution.
Class loader-
Bytecode verifier
Summary
● Java Background
– History
– Java Technology
●A programming language, development
environment, application environment
and deployment environment
– Java Features
●Java Virtual machine, garbage collection and code
security
● Phases of a Java Program
– Write, compile, run
part 3- getting to know your programming environment
CONSOLE
Where to type in commands (terminal, MSDOS command prompt)
TEXT EDITOR
Notepad, wordpas, vi
IDE (INTEGRATED DEVELOPMENT ENVIRONMENT)
GUI builder, text/ code editor, compiler, interpreter, debugger
SYNTAX
Typing errors- misspelled/ forgot semi colon
RUNTIME
Display only when run or when logical processes are incorrect
Summary
● My First Java Program
● Using a Text Editor and Console
– Write program
– Compile program
– Run program
● Errors
– Syntax Errors
– Runtime Errors
CLASS
CURLY BRACE
Start of block
COMMENT
Document part of code
MAIN METHOD
Starting point of java (all except applets)
public static void main(
String[] args ){
PRINT TEXT
System.out.println();
System.out.print();
JAVA EXTENSIONS
File name should match class
STATEMENTS
Lines of code terminated by (;)
BLOCK
Statements counded by cruly braces
IDENTIFIERS
Tokens that represent variables, methods, classes etc. (Hello, main, System, out)
Case sensitive
Begin with: letter, _, $, upper/lowercase, 0-9.
Cannot use: class, public, void (keywords)
KEYWORDS
Predefined and reserved for a purpose
Not for identifiers
LITERALS
Non-changing tokens (constant)
Types:
Integer
Floating point
Boolean
Character
String
INTEGER
Decimal (12)
Hexadeximal (0x12)
Octal (012)
FLOATING
Represent decimal/fractions
Standard (3.45) or scientific (3.45e2) notation
BOOLEAN
true/ false
CHARACTER
Single Unicode (16 bit) which allows inclusion of symbols, special characters from
other languages
Quote delimiter (‘a’)
‘\n’, ‘\r’, ‘\b’- newline, carriage return, backspace
STRING
Represent data type containing Multiple characters (“ “).
Not data type but CLASS
INTEGRAL
Byte, short, int, long
Used in 3 forms (decimal, octal, hexadecimal)
Int- default
L-long value
FLOATING POINT
Float and double
Double-default
e-exponential
VARIABLE
an item of data used to store the state of objects
*data type- indicates the type of value to be hold (int, char)
*name, must be followed for identifiers
TYPES OF VARIABLES
-primitive (int, long)- actual memory location
-reference () stores address in memory location
OPERATORS
Arithmetic
Relational
Logical
Conditional
(all follow a precedence for the compiler to evaluate frist)
ARITHMETIC
Increment (++)
Decrement (--)
(RELATIONAL)
Compare, evaluate and relate two values
(same as above)
s
The result of an exclusive OR
operation is TRUE, if and only
if one operand is true and the
other is false.
● Note that both operands must
identifiers, keywords
● Java Literals (integer, floating
BUFFEREDREADER
1.Java.io package (import java.io.*;)
OR
import java.io.InputStreamReader;
import java.io.IOException;
2.BufferedReader dataIn = new
BufferedReader( new
InputStreamReader(System.in) );
3. TRY CATCH BLOCK (temporary string to get input )
try{
String temp = dataIn.readLine();
}catch( IOException e ){
System.out.println(“Error in getting
input”);
}
**API- application programming interface
Containes presdefined classes
Packages conatin classes with related purpose
6-CONTROL STRUCTURES
CONTROL STRUCTURES
Can change ordering of statements in program
Two types:
DECISION- select specific areas to be exe
REPETITION- exe specific areas a number of times
DECISION
If
If-else
If-else-if
SWITCH
Branching on multiple outcomes
REPETITION
While
Do-while
For
BRANCHING STATEMENTS
Redirect flow of program
BREAK
Unlabeled- terminates enclosed statement
Labeled – terminates out statement
CONTINUE
Unlabeled- skips to end of innermost loop
Labeled –skips to out loop
RETURN
Exit the current method
7-JAVA ARRAYS
ARRAY
Stores multiple data tiems of same data type in a block of memory divided in slots
DECLARING ARRAY
Int arr [ ];
INSTANTIATION
Create araay
*constructor-method to create certain object