notes to review-ics3
TRANSCRIPT
-
8/14/2019 Notes to Review-ics3
1/18
NOTES TO REVIEW:
part 1- intro
HISTORY:
1991
James gostlingSun Microsystems
Oak
Motivation- platform independent language embedded in objectsPersonal hand held remote-star 7
JAVA TECHNOLOGY(pdad)
Programming languageDevelopment
Application
Deployment
DEVELOPMENTJavac (complier)
Interprester (java)
Documentation generator (javadoc)
Class file packaging tool
APPLIC AND RUNTIME
JRE- java runtime environment
DEPLOYMENT(2)SDK-software development kitWeb browser
JAVA FEATURESJVM- 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-
-
8/14/2019 Notes to Review-ics3
2/18
Bytecode verifier
SummaryJava Background HistoryJava Technology A programming language, developmentenvironment, application environmentand deployment environment
Java FeaturesJava Virtual machine, garbage collection and codesecurity
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
-
8/14/2019 Notes to Review-ics3
3/18
IDE (INTEGRATED DEVELOPMENT ENVIRONMENT)
GUI builder, text/ code editor, compiler, interpreter, debugger
ERRORS: SYNTAX AND RUN-RUNTIME
SYNTAXTyping errors- misspelled/ forgot semi colon
RUNTIMEDisplay 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 BRACEStart of block
COMMENT
Document part of code
MAIN METHOD
Starting point of java (all except applets)
-
8/14/2019 Notes to Review-ics3
4/18
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
KEYWORDSPredefined and reserved for a purpose
Not for identifiers
-
8/14/2019 Notes to Review-ics3
5/18
LITERALS
Non-changing tokens (constant)
Types:
IntegerFloating point
Boolean
Character
String
INTEGER
Decimal (12)
Hexadeximal (0x12)
Octal (012)
FLOATINGRepresent 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
-
8/14/2019 Notes to Review-ics3
6/18
PRIMITIVE (8)
Boolean (logical)
Char (textual)
Byte
Short
IntLong
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)
-
8/14/2019 Notes to Review-ics3
7/18
*name, must be followed for identifiers
TYPES OF VARIABLES-primitive (int, long)- actual memory location
-reference () stores address in memory location
OPERATORSArithmetic
Relational
Logical
Conditional
(all follow a precedence for the compiler to evaluate frist)
ARITHMETIC
Increment (++)
Decrement (--)
-
8/14/2019 Notes to Review-ics3
8/18
(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)
-
8/14/2019 Notes to Review-ics3
9/18
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
-
8/14/2019 Notes to Review-ics3
10/18
The result of an exclusive ORoperation is TRUE, if and only
if one operand is true and theother is false. Note that both operands mustalways be evaluated in orderto calculate the result of anexclusive 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
-
8/14/2019 Notes to Review-ics3
11/18
Summary
-
8/14/2019 Notes to Review-ics3
12/18
Java Comments (C++-StyleComments, C-Style Comments,
Special Javadoc Comments)Java statements, blocks,identifiers, keywordsJava Literals (integer, floatingpoint, boolean, character,String) Primitive data types( boolean,char, byte, short, int, long,float, double)
5-GETTING INPUT FROM THE KEYBOARD
BufferedReader AND JOptionPaneClasses 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 )
-
8/14/2019 Notes to Review-ics3
13/18
try{
String temp = dataIn.readLine();
}catch( IOException e ){
System.out.println(Error in getting
input);
}
**API- application programming interface
Containes presdefined classesPackages conatin classes with related purpose
JOPTION PANE- pop up dialog box1. 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 programTwo types:DECISION- select specific areas to be exe
REPETITION- exe specific areas a number of times
DECISION
If
-
8/14/2019 Notes to Review-ics3
14/18
If-else
If-else-if
-
8/14/2019 Notes to Review-ics3
15/18
SWITCHBranching on multiple outcomes
-
8/14/2019 Notes to Review-ics3
16/18
REPETITION
While
Do-while
For
BRANCHING STATEMENTSRedirect flow of program
BREAK
Unlabeled- terminates enclosed statementLabeled terminates out statement
-
8/14/2019 Notes to Review-ics3
17/18
CONTINUE
Unlabeled- skips to end of innermost loop
Labeled skips to out loop
RETURNExit 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];
-
8/14/2019 Notes to Review-ics3
18/18
ACCESSING ARRAY
Index/ subscript-