CSC 208 Java Programming
CSC 208 Java Programming
JAVA
LECTURER IN
4/24/20 JAVA PROGRAMMING
CHARGE: MR IKUDAISI
CLASS 1: Structured Programming)
JAVA is an object-oriented programming language... What makes it object oriented is because
all concept are object... Other object-oriented languages are python, c sharp, c plus plus, php and
the likes...
1. Polymorphism: means when object can exhibit in more than one form e.g. +...+ can be used
for addition and concatenation. An example is sum =a+b; and Name = "jesu" +"tomi".
2. Inheritance: is when an object acquires properties from another class. Types of class are
super and sub.
E. G
Class A {int x;
5. Encapsulation : is when a data and the method that is accessed the data is in a single unit.
Both data and method in the same class. A variable in a class declared as private can only be
accessible by method in that class
E.G
Private class A {
Int x;
Int y;
The class is declared private I.e. x and y is only meant for class A
First is comment
Single line
Multiple line
// single line
/* multiple line */
/*
/* */
*/
/*
/* inline */
*/
Package: After comment is package though it is not that compulsory, but most time when u use
NetBeans u will see it created for u automatically I.e. package addition;
USE OF PACKAGE
Import javax.swing.*;
Example:
Main method: like in C (Int main () in c), In java it is static void main(String [ ] rags), The main
method signify the beginning of program execution
JAVA SYNTAX
package display
}
}
package display;
package display;
Answer.
package display;
System.out.println("Name:
Ogunfuye Samuel");
System.out.println("level: 200lvl") ;
System.out.println("
}.
Class 3
Did u all remember that java can compile and interpreter, It compile into bytecode and later can
be interpreted into target code...
1. Single line
2.Multiple line
*/*
/* inline */
*/,
Next after comment is package, Though it is not that compulsory, But most time when u use
netbean u will see it created for u automatically, I.e. package addition; It allow you to create
many classes, Package is like collection of classes.
*Next is d import, Import statement have to follow just like d include statement, I.e. import
java.util.*;Import javax.swing.*;
*Next is d class name, Every program must have class name and must be save with that name
with .java extension
*Next is the main methodU remember we av Int main() in c, In java it is static void main(String [
] args), The main method signify the beginning of program execution
package display;
*Let us write our first code Program to display I love Crawford university
package display;
package display;
a= obj.nextDouble();
b= obj.nextDouble();
sum = a+b;
System.out.println(sum);
}
CLASS 4: PRORAM CONTROL
1.Sequence
2.Selection
3.Iteration
Sequential control is when a program is written and executed statement by statement. Like all the
basic programs we have written. Area of circle etc...
Example
package display;
import java.until.Scanner;
double r,area;
r = obj.nextDouble();
if (r>=4.0){
area = 3.142*r*r;
System.out.println(area);
package display;
import java.until.Scanner;
double r,area;
r = obj.nextDouble();
if (r>=4.0){
area = 3.142*r*r;
System.out.println(area);
else{
System.out.println("check ur radius");
This program will only find the area of the circle if the radius is greater or equal to 4. Othewise,
it will print:
package display;
import java.until.Scanner;
score= obj.nextInt();
grade= "B";
grade= "C" ;
Else {
grade= "F" ;
System.out.println(grade);
LOOPING
Statement;
}
Example
sum += i;
package class2;
import java.util.*;
for(int i=1;i<=100;i++) {
System.out.println(sum);
}
package class2;
import java.util.*;
for(int i=1;i<=100;i++) {
if(i%4==0) continue;
System.out.println(sum);