Você está na página 1de 18

NOTES TO REVIEW:

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

APPLIC AND RUNTIME


JRE- java runtime environment

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

ERRORS: SYNTAX AND RUN-RUNTIME

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

part 4-programming fundamentals

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

JAVA COMMENTS (3)- DELIMITERS


C++ (//) single line
C (/* */) multiple lines
JAVADOC (/** */) can contain tags

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)

CLASSES AND METOHDS


c- all caps first letter (HelloWorld)
m- small cap first letter (helloWorld)
*multiword- charArray, ClassName
*avoid- underscore at start

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

DATA TYPES –PRIMITIVE AND REFERENTIAL


PRIMITIVE (8)
Boolean (logical)
Char (textual)
Byte
Short
Int
Long
Double
Float

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

● There are six logical operators:


– && (logical AND)
– & (boolean logical AND)
– || (logical OR)
– | (boolean logical inclusive OR)
– ^ (boolean logical exclusive OR)
– ! (logical NOT)
Truth tables:
&& AND &

&& (logical) & (Boolean logical)


&&- short circuit evaluations (partial)
&-not partial(evaluates both)

Truth table for || and |

(same as above)

^- bollean logical exclusive OR)

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

always be evaluated in order


to calculate the result of an
exclusive OR.

Truth table for !

**takes in one argument (variable, expression, constant)

LOGICAL: CONDITIONAL OPERATORS (?:)


(?)-ternary operator which takes in 3 arguments to forma conditional expression
Summary
● Java Comments (C++-Style
Comments, C-Style Comments,
Special Javadoc Comments)
● Java statements, blocks,

identifiers, keywords
● Java Literals (integer, floating

point, boolean, character,


String)
● Primitive data types( boolean,

char, byte, short, int, long,


float, double)
5-GETTING INPUT FROM THE KEYBOARD

BufferedReader AND JOptionPane


Classes used to get input from keyboard USING:
BR-console
JOP-GUI

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

JOPTION PANE- pop up dialog box


1. javax.swing (import javax.swing.*;)

6-CONTROL STRUCTURES

Decision (if,else, switch)


Repetition (while, do-while, for)
Branching statements (break, continue, return)

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

Int arr [ ]= new int [100];


ACCESSING ARRAY
Index/ subscript-

Você também pode gostar