Unit 1
Home-->Comp Sci
- Basic Java Syntax
public static void main(String args[]){
- Declaring variables
- Primitive data
- refrence variables are used to locate objects(ie. String objects)
- Constants in Java
int x=3;
- used as that value throughout the code unless redeclared
- Java arithmetic
- grouping ()
- method selector .
- uniary plus +, uniary minus -
- instantiation new
- casting int
- multiplication *
division /
modulus %
- addition +
substraction -
- assignment =
- Numbering Systems
- binary-> base 2 (1 & 0)
- hex-> base 16 (1-9,A,B,C,D,E,F)
- hex to binary, write each hex digit as 4-bit number
- two's complement notation(left most bit of a binary number is reserved for the sign(0-positive 1-negative)
- write negative in binary
- write positive number
- reverse each bit(1's complement)
- add a binary 1 to the value(2's complement)
- Casting and promotion
- the less inclusive type will be temporarily and automatically promoted to the more inclusive type
- casting is programmer initiated, it is a termporary manual change in data types
- Output statements
system.out.print[ln]( );
- concanation-> strings and numerical data linked together using the + symbol
- escape sequences
- "\t" tab space
- "\n" new line
- "\\" print backslash
- "\"" print quotes
- Using Java methods
- must know the method name, type of return value(if any), and number and type of parameters(if any)
- return_type name (parameters)
- if no return type, it is void, and no parameters, parenthesis are empty
- Reserved words-words that have a special meaning
- Import statements
- java.lang is already imported
import package.Name.ClassName;
- for entire package * is used in place of className
- Java input
Scanner reader=new Scanner(Sustem.in);
double=reader.nextDouble();
int=reader.nextInt();
String=reader.nextLine();