0% found this document useful (0 votes)
22 views27 pages

AP M24 Week 1

The document outlines the course structure for Advanced Programming (CSE 201) focused on Object-Oriented Programming (OOP) using Java, covering topics such as classes, inheritance, polymorphism, and exceptions. It includes evaluation methods, textbook references, and basic programming concepts in Java, including data types, control flows, and I/O operations. The course aims to provide students with a comprehensive understanding of OOP principles and Java programming fundamentals.

Uploaded by

parul97verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views27 pages

AP M24 Week 1

The document outlines the course structure for Advanced Programming (CSE 201) focused on Object-Oriented Programming (OOP) using Java, covering topics such as classes, inheritance, polymorphism, and exceptions. It includes evaluation methods, textbook references, and basic programming concepts in Java, including data types, control flows, and I/O operations. The course aims to provide students with a comprehensive understanding of OOP principles and Java programming fundamentals.

Uploaded by

parul97verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Advanced Programming

CSE 201
Instructor: Sambuddho
(Semester: Monsoon 2025)
Week 1 – Introduction and Basics
Introduction
• What is this course about ? – Introduction to OOP
(using Java)
• Course outline:

Basics of Java.

Classes and objects.

Inheritance.

Polymorphism.

Abstract classes.

Interfaces.

Exceptions and exception handling.

Collections.

I/O operations.

Multithread programming and synchronizations

Basics of design patterns.
Introduction
• Evaluations:

Assignments: 20% (total 4 assignments)

Quizzes: 10% (best 5 out of 6; 3 before midsem and
3 after midsem)

Midsem exam: 25%

Final exam: 25%

Project: 20% (in pairs)

Note about quizes: Must do attempt 2 before midsem
and 2 after midsem.

Textbook(s): (1) Core Java : Fundamentals, Volume I by
Horstmann. Pearson (2) Core Java : Advanced Topics, Volume II by
Horstmann. Pearson

Office hours: TBA.
Procedural Programming

• Most natural progression from algorithms to code.


• Program: set of functions, one calls another in a
fixed sequence.
• Abstract information is mapped to its storage.

Variables are actual memory locations based on
types.
• Convenient for simple procedures – best choice for
code e.g. device drivers, operating system etc.

• Not convenient for large application programs where


abstractions are a must.
What is OOP?

It is a programming paradigm based on the concept of “objects”, which


may contain data in the form of fields, often known as attributes; and
code, in the form of procedures, often known as methods
(Wikipedia)
What is OOP?
class

car
Properties / Attributes Method
fuel reFuel() getFuel()
maxspeed setSpeed() getSpeed()
OOP Features
• Encapsulation
• Method overloading
• Inheritance
• Abstraction
• Method overriding
• Polymorphism
Advantages of OOP
• Code reuse and recycling
– Objects can easily be reused
• Design benefits
– Extensive planning phase results better design and
lesser flaws
• Software maintenance
– Easy to incorporate changes in legacy code (e.g.,
supporting a new hardware)
• Simplicity
Abstraction

The main
The mainthing
thing
is Howto to
is How drivedrive
a car ……

How the car is


moving and how
the engine is
working, this
information is
hidden.

(Abstraction)
Basics of Java Programming Language
• Installing Java on Windows/Linux/MacOS/*nix

Oracle/Sun Java JDK (proprietary – you only get the compiler and
runtime)

OpenJDK/OpenJRE (open source – you can compile from the source)
Basics of Java Programming Language

• My first program:

• - Everything is a “class”.
• - The file name and classname
• must be the same.
• - [Link]
• - Java compilation:
• $ java [Link]
• - Program runs in the JVM:
• $ java Welcome

• Syntax very similar to


• C/C++.
Java vs C/C++

• - Machine indepenedent.
• - Runs on a Java Virtual Machine (JRE) which understands a special
byte-code format.
• - Doesn’t run on bare metal.
• - High portability (Java/Python) vs performance (C/C++).

• - Is Java a compiled or an interpreted language ?


Java: Types (Integer)
Java: Types (Floating point)
Java: Type casts/conversions

- Conversions without information loss


double → int [allowed by there wold be information
loss]
Java: Bitwise Operators

• & (‘and’)
• | (‘or’)
• ^ (‘xor’)
• ~ (‘not’)
• << (‘left shift’)
• >> (‘right shift’)
Java: Operator Precedence and Hierarcy.
Java: Abstract Data Types (Strings)

• - ‘String’ abstract type.


• - Behaves like an immutable C++ string.

• Substrings:

String greetings = “Hello”;

String s = [Link](0,3);

• Concatenation:
• String greeting1 = “Hello”;
• String greeting2 = “World”;
• String message = greeting1 + greeting2;

• Testing string equality:


• equals() method of String class used for testing equality of two
strings.
• <string object1>.equals(<string object2>)
• Output: boolean (true or false).
String Builder
String builder = new StringBuilder();
[Link](ch);
[Link](str);
String longString = [Link]();
Basic I/O
- Read input from stdin and write to stdout.
- Class ‘Scanner’

import [Link].*;

Scanner in = new Scanner([Link]);

[Link]();
[Link]();
[Link]();
[Link]();
[Link]() <-- boolean
[Link]() <-- boolean
Basic I/O
- Read input from stdin and write to stdout.
- Class ‘Scanner’

import [Link].*;

Scanner in = new Scanner([Link]);

[Link]();
[Link]();
[Link]();
[Link]();
[Link]() <-- boolean
[Link]() <-- boolean

[Link]() <-- Java adaptation to C/C++ stdio printf()


Basic I/O
Basic I/O (printf format
specifier)
Control Flows
- if else
- while()
- for()
- switch case
- do{ }while()
- break and continue

Semantics same as C/C++


Scope
- Determines the point in the code upto which a variable/function name
etc. are valid.

- Global / local

- Also associated with functions inside a class.


- Java is more conservative about scopes than C/C++.
Arrays and References
• - Contiguous ``allocate memory’’

• int[] arr = new int[100]; //new keyword mandatory.

• - Reference: much like pointers in C/C++ - Name of the object or


array.
• int[] arr = new int[100];
• int[] myref;
• myref = arr; // myref → arr : reference.
Multidimensional Arrays
<type>[][] <var-name>;

int[][] marray;
marray = new int [100];

for (int i=0;i<100;i++){


marray[i] = new int[100];

}

You might also like