Lecture1 Dsa
Lecture1 Dsa
Module
Introduction
Course Structure
• 2 credits Course
Plagiarism Policy
Follow institute policy
– First instance of cheating – one letter grade reduction
– Second instance of cheating – F in the course.
Tasks
• Register (Join) for the course on Classroom page.
Contact
• Email id: [email protected]
• Office hours
– Thursday: 2-4pm
– Location: Google Meet
• Teaching Assistants (TAs) allotted
[email protected] Shivank Agrahari
[email protected] Vasudev Singhal
[email protected] Harshit Singh Chhabra
[email protected] Atif Abdus Samad
[email protected] Saksham
[email protected] Gaurav
[email protected] Pragya Pal
Introduction to
Java
11 Buzzwords for
• Simple • Portable
• Object Oriented • Interpreted
• Network Savvy • High performance
• Robust • Multithreaded
• Secure • Dynamic
• Architecture
Neutral
Java:
• Syntax is cleaned up version of C++
• No need of header files
• No pointer arithmetic/syntax
• No operator overloading
Java: Object
• Object Oriented Design: Focus on Data (objects) and interfaces.
• Object oriented features comparable to C++
• More simplified because of different handling of
multiple inheritance using ‘interfaces’.
Java: Secure
• Stack overrun, Memory corruption andReading/Writing
files without permission are much more difficult inJava.
Java: Architecture Neutral and
• Java Virtual Machine
• Sizes of primitive data types are specified
Java: Dynamic
• Support for libraries etc.- adding new methods to libraries
without affecting client
• Possible to find runtime type information.
Java Programming
• JDK Java
}
Control Statements: while, do-while
while (balance < goal) do
{ {
balance += payment; balance += payment;
double double
interest=balance*interestRate/100; interest=balance*interestRate/100
; b a l a n c e + = interest;
b a l a n ce+= interest;
ye a r + + ;
years++;
// print current balance
}
. . .
S ys t e m. o u t . pr i nt l n( ye ar s + " years."); / / a s k i f r e a d y to retire a n d g e t input
. . .
}
wh i l e ( i n p ut.e qual s(" N"));
Control Statements: for
f o r ( i n t i = 10; i > 0; i - - )
{
System.out.println("Counting d o w n . . . " +i);
}
S ys t e m . o u t . p r i n t l n ( " Ti m e up!"); Scope of i ?
int i;
f o r ( i = 10; i > 0 ; i - - )
{
System.out.println("Counting d o wn . . . " + i ) ;
}
Scope of i ?
S ys t e m . o u t . p r i n t l n ( " Ti m e up!");
Strings in
• operations on strings
public class StringDemo {
p u b l i c static vo i d m a i n ( S t r i ng a r g s [ ] ) {
S trin g p a l i n d r o m e = " D o t saw I was To d " ;
i n t len = palindrome.length();
System.out.println( "String Length i s : " + len ) ;
}
}
Array
• 1D, 2D array(array of arrays)
• length P u b l i c c l a s s Te s t A r r a y {
p u b l i c static vo i d ma i n ( S t r i n g [ ] a r g s ) {
• Array class d o u b l e [ ] m yL i s t = {1.9, 2 . 9 , 3.4, 3.5};
• Forloop on arrays
/ / P r in t a l l th e a rra y e le m e n ts fo r
(double element: myList) {
System.out.println(element);
}
}
}
Input output from/to
• Scanner public class InputTest
{
• Print, println p u b lic static v o i d m a in (S t rin g[ ] a r g s )
{
Scanner in = new Scanner(System.in);
/ / get f i r s t input
S ys t e m . o u t . p r i n t ( " W h a t is y o u r name?");
S t r i n g name = i n . n e x t L i n e ( ) ;