Introduction To Java Programming
Introduction To Java Programming
(BE04000231)
Prof. H. S. Sanghavi
Computer Engineering Department
Government Engineering College, Bhavnagar
About the subject
• Category of the Course : Professional Core Course
(forms the backbone of your engineering skillset. We will be using Java, a language famous for its platform
independence and rich libraries. If you want to build Android apps, enterprise web systems, or big data tools
later in your career, this is where it starts)
1 Android Mobile Applications Primary language for Android apps; used in WhatsApp, Spotify, Signal
4 Big Data Technologies Supports tools like Apache Hadoop, Spark, Kafka
6 Cloud-Based Applications Cloud-native apps using Spring Boot; runs on AWS, Azure, Google Cloud
7 Embedded Systems / IoT Java ME used in smartcards, set-top boxes, IoT sensors
9 Desktop GUI Applications Java Swing/JavaFX for apps like NetBeans, Eclipse, Jitsi
Used for live monitoring and trading platforms due to concurrency and low
10 Real-Time Trading & Analytics Dashboards
latency
5
Real-World Examples (Why this matters)
Here we connect the syllabus topics to actual problems we will solve in the labs.
OOP Java is the easiest, scoring and my favorite subject
6
Real-World Examples (Why this matters)
Example B: The Shopping Mall
•
OOP Java is the easiest, scoring and my favorite subject
Concept: Polymorphism "Think of a billing counter at a mall.
• The Scenario: You have Regular customers and Privileged customers.
• The Code: You don't want to write completely different code for every customer type. You want one
method, generateBill(), that behaves differently depending on who the customer is.
• The Tech: This is called Polymorphism and Method Overloading. We will build a billing system that
automatically applies flat discounts for privileged members and percentage discounts for festive offers.“
7
Java vs Other Programming Languages
8
Teaching and Examination Scheme
9
OOP Java is the easiest, scoring and my favorite subject
Syllabus
Course Roadmap (Syllabus Walkthrough)
11
In-detail Syllabus
12
In-detail Syllabus
13
Reference Books
14
OOP Java is the easiest, scoring and my favorite subject
Introduction
Welcome to the world of Programming
What is Language?
A language is a system of communication used by a particular country or community.
OOP Java is the easiest, scoring and my favorite subject
16
Programming Language
A programming language is a computer language that is used by programmers (developers)
to communicate with computers. OOP Java is the easiest, scoring and my favorite subject
17
Types of Programming Languages
1. Low-level programming language
It is a machine-dependent (hardware specific) programming language.
OOP Java is the easiest, scoring and my favorite subject
It consists of a set of instructions that are either in the binary form (0 or 1) or in a symbolic
and human-understandable mnemonics (ADD, MOV, SUB).
E.g. Machine level language, Assembly language, etc.
2. High-level programming language
It is closer to human languages than machine-level languages.
It is easy to read, write, and maintain as it is written in English like words.
It allows to write the programs which are independent of a particular type of machine
(hardware).
A compiler is required to translate a high-level language into a low-level language.
E.g. Python, Java, JavaScript, PHP, C#, LISP, FORTRAN, etc.
3. Middle-level programming language
Middle-level programming language lies between the low-level and high-level
programming language.
E.g. C, C++, etc.
18
OOP Java is the easiest, scoring and my favorite subject
Introduction to
JAVA
Java is a general-purpose computer-programming language that is open source, platform
independent, object-oriented and specifically designed to have as few implementation
OOP Java is the easiest, scoring and my favorite subject
dependencies as possible.
Java was originally developed by James Gosling at Sun Microsystems and released in 1995.
Java was initially named as Oak language and renamed to JAVA in 1995.
20
Features of JAVA
Simple: Java inherits C/C++ syntax and many object-oriented features of C++.
OOP Java is the easiest, scoring and my favorite subject
Robust: Java has a strong memory management system. It helps in eliminating error as
it checks the code during compile and runtime.
21
Features of JAVA (Cont.)
Architectural Neutral: Java is platform independent which means that any application
OOP Java is the easiest, scoring and my favorite subject
High Performance: Java achieves high performance through the use of bytecode which
can be easily translated into native machine code. With the use of JIT (Just-In-Time)
compilers, Java enables high performance.
22
Features of JAVA (Cont.)
Dynamic: Java has ability to adapt to an evolving environment which supports dynamic
memory allocation due to which memory wastage is reduced and performance of the
application is increased.
23
Components of Java
Java Virtual Machine (JVM)
JDK Java Runtime Environment (JRE)
OOP Java is the easiest, scoring and my favorite subject
Launcher
([Link]), Runtime
AppletViewer, Libraries
etc..)
24
Java Development Kit (JDK)
JDK contains tools needed ,
To develop the Java programs and
OOP Java is the easiest, scoring and my favorite subject
25
Java Runtime Environment (JRE)
The JRE is required to run java applications.
OOP Java is the easiest, scoring and my favorite subject
26
Java Virtual Machine (JVM)
JVM is a virtual machine that enables a computer to run Java
programs as well as programs written in other languages and
OOP Java is the easiest, scoring and my favorite subject
Compiler
28
Java Interview Question
1. Difference between JRE and JVM?
OOP Java is the easiest, scoring and my favorite subject
29
Hello World Java Program File must be saved as [Link]
{
public static void main(String[] args)
{ String must start with capital letter
[Link](“Welcome to Semester-5");
}
System must start with capital letter
}
We have to save this in [Link] file as it has public class named HelloWorld.
String and System are inbuilt Java Classes.
Classes in java are always written in Camel case.
30
How to execute Java Program?
1. Save the program with the same name as the public class with .java extension.
OOP Java is the easiest, scoring and my favorite subject
31
How to execute Java Program?
2. Open command prompt (cmd) / terminal & navigate to desired directory / folder.
OOP Java is the easiest, scoring and my favorite subject
32
OOP Java is the easiest, scoring and my favorite subject
Tokens
Tokens
The smallest individual unit of a language / program is known as a token.
OOP Java is the easiest, scoring and my favorite subject
35
OOP Java is the easiest, scoring and my favorite subject
Identifiers
Identifiers
They are used for class names, method names and variable names.
OOP Java is the easiest, scoring and my favorite subject
38
OOP Java is the easiest, scoring and my favorite subject
Literals
Literals
A constant value in Java is created by using a literal representation of it
OOP Java is the easiest, scoring and my favorite subject
40
Comments
Single Line Comments : //
OOP Java is the easiest, scoring and my favorite subject
Separators
most commonly used separator in Java is the semicolon
41
OOP Java is the easiest, scoring and my favorite subject
Java Keywords
Keywords
Keywords
combined with the syntax of the operators and separators, form the foundation of the
OOP Java is the easiest, scoring and my favorite subject
Java language.
cannot be used as names for a variable, class, or method
In addition to the keywords, Java reserves the following: true, false, and null. These are
values defined by Java.
43
Data Types
Java Datatypes
Primitive Non-primitive
Floating-point
Integers Characters Boolean Class
numbers
44
Primitive Data Types
Data Type Size Range Example
OOP Java is the easiest, scoring and my favorite subject
45
Escape Sequences
Escape sequences in general are used to signal an alternative interpretation of a series of
characters. OOP Java is the easiest, scoring and my favorite subject
For example, if you want to put quotes within quotes you must use the escape sequence, \",
on the interior quotes.
[Link]("Good Morning \"World\"");
46
Type Casting
Assigning a value of one type to a variable of another type is known as Type Casting.
OOP Java is the easiest, scoring and my favorite subject
47
Automatic Type Casting
When one type of data is assigned to other type of variable , an automatic type conversion
will take place if the following two conditions are satisfied:
OOP Java is the easiest, scoring and my favorite subject
48
Casting Incompatible Types
To create a conversion between two incompatible types, you must use a cast
OOP Java is the easiest, scoring and my favorite subject
Operator
Perform definite operation
Operators
1. Arithmetic Operators
OOP Java is the easiest, scoring and my favorite subject
2. Relational Operators
3. Bitwise Operators
4. Logical Operators
5. Assignment Operators
6. Conditional / Ternary Operator
7. Instance of Operator
51
Operators
An operator is a symbol to perform specific mathematical or logical functions.
OOP Java is the easiest, scoring and my favorite subject
52
Arithmetic Operators
An arithmetic operator performs basic mathematical calculations such as addition,
subtraction, multiplication, division etc on numerical values (constants and variables).
OOP Java is the easiest, scoring and my favorite subject
53
Relational Operators
A relational operators are used to compare two values.
OOP Java is the easiest, scoring and my favorite subject
They check the relationship between two operands, if the relation is true, it returns 1; if the
relation is false, it returns value 0.
Relational expressions are used in decision statements such as if, for, while, etc…
54
Bitwise Operators Note : A = 60 & B = 13
>>> Shift right zero fill operator. A >>>2 = 15 which is 0000 1111
55
Logical Operators
Logical operators are decision making operators.
OOP Java is the easiest, scoring and my favorite subject
57
Assignment Operators
Assignment operators are used to assign a new value to the variable.
OOP Java is the easiest, scoring and my favorite subject
The left side operand of the assignment operator is a variable and right side operand of the
assignment operator is a value or a result of an expression.
Meaning of = in Maths and Programming is different.
Value of LHS & RHS is always same in Math.
In programming, value of RHS is assigned to the LHS
Operator Meaning
= Assigns value of right side to left side. Suppose a=5 and b=10. a=b means now value of a is
10.
+= a += 1 is same as a = a + 1
-= a -= 5 is same as a = a – 5
*= a *= b is same as a = a * b Shorthand Assignment Operators
/= a /= c is same as a = a / c
%= a %= 10 is same as a = a % 10
58
Increment / Decrement Operators
Increment and decrement operators are unary operators that add or subtract one, to or
from their operand. OOP Java is the easiest, scoring and my favorite subject
the increment operator ++ increases the value of a variable by 1, e.g. a++ means a=a+1
the decrement operator -- decreases the value of a variable by 1. e.g. a–– means a=a–1
If ++ operator is used as a prefix (++a) then the value of a is incremented by 1 first then it
returns the value.
If ++ operator is used as a postfix (a++) then the value of a is returned first then it increments
value of a by 1.
Expression
Expression Evaluation (Let’s say a=10, c=15)
b = a++
b = --a + c++ b = ??
b = ++a
b = a++ + ++c b = ??
b = a--
b = ++a - ++c b = ??
b = --a
59
Conditional Operator (Ternary)
Conditional Operator ( ? : )
Syntax:
OOP Java is the easiest, scoring and my favorite subject
60
OOP Java is the easiest, scoring and my favorite subject
Thank You