INTRODUCTION TO O O P U S I N G
JAVA
Md. Nafis Tahmid Akhand
Acknowledged: Tanjina Helaly
W HA T I S P R O G R A M M I N G
Instruction to computer/device to perform task.
Computer understands only 0 and 1. Nothing
else.
So, we need to send the instruction in the form of
0, 1
⚫ Do you write program with just 0 and 1?
C L A S S I F I C A T IO N /E VO L U T I O N O F
PROGRAMMING
Machine level programming
⚫ Send instruction in binary format
Assembly Programming
⚫ send code instead of binary code.
⚫ Need assembler to convert to binary
High level programming
⚫ Code is close to English Language
⚫ Need Compiler to convert to binary
⚫ 3 types
Non structured
Structured/Procedural
Object Oriented Programming
C L A S S I F I C A T IO N /E VO L U T I O N O F
PROGRAMMING
Non structured
⚫ Generate spaghetti code
⚫ Sequential and has GoTo
⚫ C O B O L , BAS I C , F O RT R A N
Structured/Procedural
⚫ Use Subroutine/Function
⚫ improving the clarity, quality, and development time
⚫ C , PA S C A L
Object Oriented Programming
⚫ Object-oriented programming (OOP) is a programming
language model organized around objects rather than
"actions" and data rather than logic.
⚫ Historically, a program has been viewed as a logical
procedure that takes input data, processes it, and produces
output data.
⚫ Java, C++, C#
OUR GOAL
LEARN O B J E C T ORIENTED PROGRAMMING
U S I N G J A VA
PROGRAMMING LANGUAGE
A programming language is a formal constructed
language designed to communicate instructions
to a machine, particularly a computer.
JAVA’S LINEAGE
Java is related to C++, which is a direct
descendent of C .
⚫ Much of the character of J ava is inherited from these
two languages.
From C , Java derives its syntax.
Many of Java’s object-oriented features were
influenced by C++.
J A V A - CHARACTERISTICS
Uses C/C++ basic syntax and basic data types -int, char,
float, double, long, short, byte etc.
Uses standard C/C++ control structures
“Pure” O O language
No stand alone functions -All code is part of a class
No explicit pointers - uses references
Uses garbage collection
Java is strongly typed
J ava is normally compiled to a bytecode.
⚫ J ava bytecode is a machine language for an abstract
machine
⚫ Makes J ava secure and Portable
Each platform (or browser) that runs Java has a J ava
Virtual Machine (JVM) . The J V M executes J ava bytecodes
WHY J A V A
Platform Independent - Code once run anywhere
⚫ Byte code
Easy to learn
Secure
⚫ Byte code & V M
Free
JAVA IDE
Using J D K you can compile and run java
program from command line.
⚫ c:> javac HelloWorld. J ava
compiling here and
it will produce HelloWorld.class i.e. bytecode.
⚫ c:>java HelloWorld
It runs java byte code on native machine
JAVA IDE
Creating, Compiling, Debugging and Execution for these
four steps J D K is not user friendly. I D E is provided for
that. A list of IDEs are:
⚫ Eclipse
⚫ Netbeans.
⚫ IntelliJ I D E A
Yo u c a n i n s t a l l I n te l l i J I D E A u s i n g t h e t u to r i a l
h t t p s : / / yo u t u . b e / E M LTO M d I z 4 w ? s i = z 0 9 e f 0 to m G E a 1 R r j
AN EXAMPLE HELLOWORLD
public class HelloWorldExample
{
public static void main( String args[] )
{
System.out.println("Hello World");
}
}
JAVA SOURCE CODE NAMING
CONVENTIONS
All java source file should end with .java
Each .java file can contain only one public
class
The name of the file should be the name of
the public class plus ".java"
Do not use abbreviations in the name of the class
If the class name contains multiple words then
capitalize the first letter of each word ex.
HelloWorld.java
NAMING CONVENTION
Class Naming
⚫ Uses Capitalized word(s) i.e. Title case
⚫ Examples:- HelloWorld, MyList, StudentMark
Variable and method names
⚫ starts with a lowercase letter and after that use Title
case
⚫ Examples:- variableAndMethodNames, aFloat,
studentName
Names of constants
⚫ All are capital letters and separated by underscore.
⚫ Example: N A M E S _ O F _ C O N S TA N T S
J A V A IDENTIFIERS RULES
Identifier is a name given to a variable, class, or
method.
Java identifier
⚫ Can contain letter, number, underscore (_), or dollar
sign ($).
⚫ Cannot start with number.
⚫ Identifiers are case sensitive(var and Var both can be
declared in a program)
⚫ have no maximum length.
⚫ cannot be a keyword, but it can contain a keyword as
part of its name.
• Write down whether the following
identifiers are valid or not
Name Valid/invalid comment
myVar# invalid # is not allowed
myVar$ valid
$myVar valid
final invalid keyword
static invalid keyword
finalVar valid Can contain keyword as a part of name
1num invalid Cannot starts with number
main valid Not a keyword