CSC 208
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...
What make Java oop (characteristics of Java)
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;
Class B extends A {int y; int z;}
3. Abstraction: is not given background details of an object e.g. use of interface
* interface is a collection on abstract methods
* abstract methods are methods without a body I.e.
Public void run () {
The run () is a method, A method without a body
Public interface A implement B {
Public void run () {}
Public void eat () {}
Abstract method has name but no statement in their body
4. Class is a collection of objects e.g. school, university, fruit etc.
Fruit carrot = new fruit ();
Virus Corona = new virus ();
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
And finally note
*** Object Is an Instance of a Class
CLASS 2: CONCEPT OF JAVA
Java has some attributes similar to c.
First is comment
Comment is a descriptive statement
It can come in three styles
Single line
Multiple line
And inline comment
// 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
It allows you create many classes, Package is like collection of classes
IMPORT: Next is d import, import statement av to follow, is just like the include statement.
I.e. import java.util.*;
Import javax.swing.*;
Example:
*Public class newapplication {
*public class addition {
The public must start with small letter
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
1.// java programming comment here
package display
public class display{
public static void main(String[ ]arcs){
}
}
2. // java programming comment here
package display;
public class display{
public static void main(String[ ]args){
}( with this you are a java guru)
3. program to display I love Crawford
// java programming comment here
package display;
public class display{
public static void main(String[ ]args){
System.out.println("I love Crawford university");
System.out.println() is used just like println,to display outputs.
Class work.
Write a java code to display your bio data.
Answer.
// java programming comment here
package display;
public class display{
public static void main(String[ ]args){
System.out.println("Name:
Ogunfuye Samuel");
System.out.println("level: 200lvl") ;
System.out.println("matric no. : 180502021");
System.out.println("
Department: comp science ");
}.
Class 3
Did u all remember that java can compile and interpreter, It compile into bytecode and later can
be interpreted into target code...
So today we will start with java concept
Comment is a descriptive statement, it can come in three styles
1. Single line
2.Multiple line
3. And inline comment
*// single line
*/* 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
public class addition {
*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
// java programming comment here
package display;
public class display{
public static void main(String[ ]arcs){
*Let us write our first code Program to display I love Crawford university
// java programming comment here
package display;
public class display{
public static void main(String[ ]args){
System.out.println("I love Crawford university");
System.out.println() is used just like println, To display output
*Write a java code to display ur biodata
// java programming comment here
package display;
public class display{
public static void main(String[ ]args){
System.out.println("Name:Alonge Joshua ,level: 200lvl, matric no. : 190502062,
Department: computer 💻 science ");
public class demostration {
public static void main(String[]args)
double a,b, sum;
Scanner obj = new Scanner(System.in);
a= obj.nextDouble();
b= obj.nextDouble();
sum = a+b;
System.out.println(sum);
}
CLASS 4: PRORAM CONTROL
Program control is a way a program is executed. There are three of them;
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...
Selection/branching are your If condition , if else condition.
Example
// java programming comment here
package display;
import java.until.Scanner;
public class areaCircle{
public static void main(String[ ]args){
double r,area;
Scanner obj = new Scanner(System.in);
r = obj.nextDouble();
if (r>=4.0){
area = 3.142*r*r;
System.out.println(area);
This is a Program to find the area of a circle if r is greater than 4 or equal to 4.
// java programming comment here
package display;
import java.until.Scanner;
public class areaCircle{
public static void main(String[ ]args){
double r,area;
Scanner obj = new Scanner(System.in);
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:
"Check your radius"
This is a simple grading system.
// java programming comment here
package display;
import java.until.Scanner;
public class grading{
public static void main(String[ ]args){
Scanner obj = new Scanner(System.in);
score= obj.nextInt();
if (score>= 70 & & score <=100){
String grade= "A" ;
if (score>= 60 & & score <=70)
grade= "B";
if (score>= 50 & & score <=60) {
grade= "C" ;
Else {
grade= "F" ;
System.out.println(grade);
LOOPING
for(int index= initial; condition ; increment)
Statement;
}
Example
This program sums up all the numbers from 1 to 50
public class Sum{
public static void main(String[] args) {
int num = 50, sum = 0;
for(int i = 1; i <= num; ++i)
sum += i;
System.out.println("Sum = " + sum);
package class2;
import java.util.*;
public class demostration {
public static void main(String[]args)
int sum =0;
for(int i=1;i<=100;i++) {
sum = sum +i;
System.out.println(sum);
}
package class2;
import java.util.*;
public class demostration {
public static void main(String[]args)
int sum =0;
for(int i=1;i<=100;i++) {
if(i%4==0) continue;
sum = sum +i;
System.out.println(sum);