0% found this document useful (0 votes)
114 views

Unit 1 - OOP in Java Intro

This document outlines the content of an Object Oriented Programming in Java course. It covers OOP principles, the history and features of Java, setting up the development environment, basic program syntax like data types and control structures, and an example Box class. It also provides practice questions on if/switch statements and loops. The instructor's contact details are included.

Uploaded by

tgotora
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views

Unit 1 - OOP in Java Intro

This document outlines the content of an Object Oriented Programming in Java course. It covers OOP principles, the history and features of Java, setting up the development environment, basic program syntax like data types and control structures, and an example Box class. It also provides practice questions on if/switch statements and loops. The instructor's contact details are included.

Uploaded by

tgotora
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

COURSE: OOP IN

JAVA
INSTRUCTOR: MR T.T GOTORA
EMAIL: [email protected]
COURSE CONTENT
OOP Principles
History of Java
Java Buzzwords
Differences between Java, C++ and C#.
The Java Virtual Machine
Setting Up Environment
COURSE CONTENT
Program Execution
Program Syntax
Data Types
Control Structures
Class Basics
Example Program
OOP PRINCIPLES
Inheritance

Encapsulation

Polymorphism
HISTORY OF JAVA
Descendant of C.
Adopts it syntax from C and OOP features from C++.
Started as Oak in 1991 by J. Gosling and colleagues at Sun
Microsystems.
Renamed Java in 1995.
Created initially for consumer electronics.
Internet encouraged its populace due its platform independence nature.
JAVA BUZZWORDS
Simple
Secure
Portable
Object-oriented
Robust
Multithreaded
JAVA BUZZWORDS
Architecture-neutral
Interpreted
High performance
Distributed
Dynamic
Java Virtual Machine (JVM)
Enables Bytecode to be run on it.

Major reason why java programs run on any


platform.
SETTING UP ENVIRONMENT
Set path in Windows by :

Go to My Computer (Right Click), Select Properties then Advanced System Settings,
Click on Environmental Variables

Create Path (add jdk path) and Classpath (add rt.jar and tools.jar) System Variables.

Set path in Linux if bash is the shell, add the following line to the end of
.bashrc_profile file using vi editor ‘.bashrc: export PATH=/path/to/java:$PATH’
PROGRAM EXECUTION
/*
This is a simple Hello world program.
Call this file “Hello.java".
*/
class Hello {
// Your program begins with a call to main().
public static void main(String args[]) {
System.out.println(“Hello World.");
}
PROGRAM EXECUTION
To compile the program enter javac Hello.java in command line.

To run the program enter java Hello in command line.


COMMAND LINE EXECUTION
(Error When path not set properly)
COMMAND LINE EXECUTION
(Error When class path not set properly)
COMMAND LINE EXECUTION
Successful program execution
BASIC PROGRAM SYNTAX
Case Sensitivity - Java is case sensitive, which means identifier Hello and hello
would have different meaning in Java.
Class Names - For all class names the first letter should be in Upper Case. If
several words are used to form a name of the class, each inner word's first letter
should be in Upper Case.
Method Names - All method names should start with a Lower Case letter. If
several words are used to form the name of the method, then each inner word's first
letter should be in Upper Case.
Program File Name - Name of the program file should exactly match the class
name.
public static void main(String args[]) - Java program processing starts from the
main() method which is a mandatory part of every Java program.
PRIMITIVE DATA TYPES
DATA TYPE GROUPS DATA TYPE MEMORY
SIZE in BITS

Integers – Java supports signed integer types i.e. negative byte 8


and positive values short 16
int 32
long 64
Floating Point Numbers – Java implements the standard float 32
(IEEE–754) set of floating-point types and operators. They double 64
represent single- and double-precision numbers
Character – Java uses Unicode to represent characters which char 16
defines the international character set that can represent all
of the characters found in all human languages
Boolean – only one of two possible values, true or false. boolean Virtual machine
dependent.
CONTROL STATEMENTS
Selection:
If
Switch
Iteration:
While
Do…while
For loop
CONTROL STATEMENTS
Selection:
if(condition) statement; switch (expression) {
else statement; case value1:
// statement sequence
break;
If-else-if case value2:
if(condition) // statement sequence
statement; break;//is optional if left out next case will //execute
else if(condition) …
default:
statement; // default statement sequence
else }
Statement; //expression must be of type byte, short, int, char, an
enumeration or string as of JDK 7.
CONTROL STATEMENTS
Iteration:
while(condition) { for(initialization; condition;
// body of loop iteration) {
} // body
}
do {
// body of loop for(type itr-var : collection)
} while (condition); statement-block;
//the body of loop executes at least //Although the for-each for loop iterates until
once even if condition is false. all elements in an array have been examined,
it is possible to terminate the loop early by
using a break statement
CLASS BASICS
A class is a blueprint of an object.
An object is an instance of a class.
A member of a class can be data or methods.
Instance variable – data which falls within a class.
Local variable – defined within a scope.
Class variable - variables declared within a class, outside any
method, with the static keyword.
Example Program
//Box.java file
class Box { // class name
double width; //instance variables
double height;
double depth;
}
CLASSES
//BoxDemo.java
class BoxDemo {
public static void main(String args[]) {
Box mybox = new Box(); // object creation
double vol; // local variable
// assign values to mybox's instance variables
mybox.width = 10; mybox.height = 20; mybox.depth = 15;
// compute volume of box
vol = mybox.width * mybox.height * mybox.depth;
System.out.println("Volume is " + vol);
}
PRACTICAL QUESTIONS
Write a program which implements if statement which allows a user
to enter the; name, subject and mark with the following criteria
 0-44 Fail, 45-54 3, 55-64 2.2, 65-74 2.1, 75-100 1.
Write a program which implements switch statement allowing a
user to enter the; name, subject and mark with criteria as above.
Write a program which implements the do…while and for-each
loops allowing capturing of the child name and time of birth at a
hospital which has an ability to deliver a maximum limit of 10 babies
a day.
REFERENCES
1. Java The Complete Reference Ninth Edition, Herbert Schildt, McGraw-
Hill Education, 2014.
2. An Introduction to Object Oriented Programming with Java 5th Edition
C. Thomas Wu, 2008.
3. Oracle Certified Associate Java SE 8 Programmer I Study Guide Exam
1Z0-808 by Jeanne Boyarsky and Scott Selikoff, 2015
4. Java 8 in Action: Lambdas, streams, and functional-style programming,
Raoul-Gabriel Urma et al, Manning Publications Co. 2015.
5. http://www.tutorialspoint.com/java/ Java Tutorials [accessed on 3
March 2017]
6. Java 8 Pocket Guide by Robert Liguori and Patricia Liguori, 2014.

You might also like