Basic programming concepts
Program, source code, byte code, compiler and interpreter
Binary and hex numbers
Process of creating, editing , compiling and running a Java program
Java basic program structure and output
Java program structure ( write a complete Java program structure)
Using System.out.println or print to display an output
Display the Unicode characters
Escape sequences \n, \\, \
Variables, data types, arithmetic expressions and output format
Naming variables
Data types
Java arithmetic operator and expressions
Arithmetic operator order precedence
Cast
Use JOptionPane.showInputDialog for input
Divide by integer and/or real numbers
Output format
Invoke class methods (Math.pow and Math.sqrt)
Classes, objects and methods
Create an object
Class World
Constructor: new World( ) or new World(world object)
Turtle object methods
turnRight()
turnLeft()
turn(int angle)
forward(int numbeofsteps)
moveTo(int x, int y)
penDown()
penUp()
show()
hide()
Define an object method in the class
Invoke an object method
Arrays
Declare a one-dimensional array
Create a one-dimensional array
Declare and initialize a one-dimensional array
Input a one-dimensional array
Output a one-dimensional array
Process a one-dimensional array
Picture objects
Color representations
Color class
import java.awt.Color;
Color constructor
Color colorObj = new Color (red value, green value, blue value);
where red, green and blue values are ranged from 0 to 255
Color object methods
darker(), brighter()
FileChooser.pickAFile();
Creating a Picture object
Picture picObj = new Picture(filename)
where filename is a string object
Picture object methods
show()
Explore()
getHeight()
getWidth()
getPixels()
getPixel(int x, int y)
WritePictureTo(String filename)
Pixel object methods
getX() and getY()
getRed(), getGreen() and getBlue()
setRed(int value), setGreen(int value) and setBlue(int value)
getColor() return a Color object
setColor(Color object)
Loops
1. while loop
while(condition)
{ loop body
}
2. Counter-controlled loop
Ex Display Hello 100 times
int i =1;
while(i<=100)
{ System.out.println(Hello);
i=i+1;
}
Ex
int i =0;
while(i<10);
{ System.out.println(Hello);
i=i+1;
}
Output: Nothing outputs. A semicolon after the while loop makes an empty loop body.
c. Ex
int i=0;
while(i<10)
System.out.println(Hello);
i=i+1;
Output: Hello displays continuously because there is no brace to include the statement i = i + 1;
Correct solution:
int i=0;
while(i<10)
{ System.out.println(Hello);
i=i+1;
}
3. for loop
Ex Display Hello 100 times using for loop
for(int i=0 ; i<100 ; i=i+1 )
System.out.println(Hello);
Or
for(int i=0; i<100; )
{ System.out.println(Hello);
i=i+1;
}
Ex Use a for loop to display even numbers starting from 2 to 100
for(int i=2; i<=100; i=i+2)
System.out.println(i);
Ex Use a while loop to accumulate all the numbers starting from 2 to 200; display value
int sum=0; //accumulated variable
int i=2;
while(i<=200)
{sum=sum+i;
i=i+1;
}
System.out.println(sum);
Code Analyzing
i=2
i<=200 true
sum=0+2=2
i=3
i<=200 true
sum=2+3=5
i=4
.
4. for
each loop (Text Book on page 93)
Use only for objects
Ex Use for each loop to display the red values of all pixels in the picture whose filename is happy.gif
int redvalue;
Picture picObj= new Picture(c:/happy.gif);
Pixel[] pixArray = picObj.getPixels();
for(Pixel pixObj:pixelArray)
{redvalue=pixObj.getRed();
System.out.println(redvalue);
}
5. Relational operators: < , <=, >=, == and !=
5. Single-alternative decision statement
if (condition)
{ true body
}
dual-alternative decision statement
if (condition)
{ true body
}
else
{
false body
}