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

Lecture 1 Introduction to Java

The document outlines the syllabus for a Java programming course taught by Dr. Muhammad Waqar, covering topics such as Java basics, loops, arrays, and methods. It includes a detailed grading scheme, assignments, quizzes, and a final exam, along with recommended textbooks. Additionally, it discusses the importance of programming languages, the development of C and Java, and the execution of Java code using NetBeans IDE.

Uploaded by

mwaslam2303
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)
3 views

Lecture 1 Introduction to Java

The document outlines the syllabus for a Java programming course taught by Dr. Muhammad Waqar, covering topics such as Java basics, loops, arrays, and methods. It includes a detailed grading scheme, assignments, quizzes, and a final exam, along with recommended textbooks. Additionally, it discusses the importance of programming languages, the development of C and Java, and the execution of Java code using NetBeans IDE.

Uploaded by

mwaslam2303
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
You are on page 1/ 27

5/17/2020

IN2203

Fundamentals of
Programming (Java)

Instructor
Dr. Muhammad Waqar
[email protected]

Contents
01 Basics of Java
Programming in Java, Data types, variables

02 More on Java and Math, String Classes

Selection Statements, Math Class and Strings

03 Loops and Methods


for and while Loops, Defining and using
Methods

04 Arrays
Single and multi dimensional arrays

1
5/17/2020

Break up
Week Week Tests Week
1-2 3-5 6-8

Week 4
Assignment
Introduction Selection (15%) Loops
to Java and Statements,
Programming Math Class, Week 5
Basics Strings Class Quiz
(10%)

Break up
Week Week Week
Tests
9-10 11-12 13

Week 8
Assignment
Single and (15%)
Defining and Multi- Week 10 Final Exam
Calling dimensional Class Quiz (30%)
Methods Arrays (10%)

Week 11
Project (10%)

2
5/17/2020

Grading Scheme
Test Percentage
Attendance/Class Participation 10%
Assignments (2) (Week 4, 8) 30% (15% each)
Quizzes (2) (Week 5, 10) 20% (10% each)
Project (Week 11) 10%
Final Test (Week 13) 30%
Total 100%
Easy to change colors.

Grading
Marks Point Meaning
A (80-100%) 4 EXCELLENT: Outstanding performance
B (70-79%) 3 GOOD: Better than average achievement
C (60-69%) 2 SATISFACTORY: Achievement sufficient to enable the
student to progress in the course
D (50-59%) 1 MARGINAL: Minimum acceptable level of
achievement; Exception: for courses where the
passing grade is a “C”, a grade of “D” represents an
insufficient achievement; must repeat.
F (0-49%) 0 UNSATISFACTORY: Insufficient achievement; must
repeat. Student must consult with Program
Coordinator.

The passing percentage for this course is 60% (Grade C, Point 2)

3
5/17/2020

Textbooks
Tests
1. Fundamentals of Programming using Java, 1st edition by Edward Currie (2006)

2. Java: The Complete Reference, Herbert Schildt

Google Class Room


• It will be used for sharing all the materials and any announcements
related to this course
• Please see your google class room code at the end of lecture and
use it to join google class room.
• Please use your college email address for joining class and also for
any correspondence.
• t

4
5/17/2020

INTRODUCTION
CHAPTER 1

10

Computers and Languages


• Life in this age depends on smart devices
• Automobiles, Smart homes, Smart cities all of these depend on
computers
• The computer program's role in this technology is essential;
without a list of instructions to follow, the computer is virtually
useless.
• Programming languages allow us to write those programs and
thus make computers do something useful.

10

5
5/17/2020

11

Elements of a Computer System


• The elements of a computer system fall into two major categories:
hardware and software.

• Hardware is the equipment used to perform the necessary


computations (central processing unit (CPU), monitor, keyboard,
power supply, drives, RAM, etc.

• Software consists of the programs that enable us to solve


problems with a computer (lists of instructions to perform).

11

12

Computer Hardware
Essentially, modern computers consist of:

1. Main memory

2. Secondary memory, which includes storage devices such as hard


disks and flash drives

3. Central processing unit

4. Input devices, such as keyboards and mouse

5. Output devices, such as monitors and printers

12

6
5/17/2020

13

Computer Software
Operating System
• The collection of computer programs that control the interaction of
the user and the computer hardware is called the operating
system (OS): e.g.: UNIX, Windows, MAC-OS X
• The operating system of a computer is the software that is
responsible for directing all computer operations and managing all
computer resources.

Application Software
• Application programs are developed to assist a computer user in
accomplishing various tasks (i.e. word processing, financial
calculations etc.) e.g. Notepad, MSWord, MATLAB etc.

13

14

Computer Languages
• Developing new software requires writing lists of instructions for a
computer to execute.
• The language directly understood by a computer is called
machine language (or machine code) and is a collection of binary
numbers.
• For brevity Software developers rarely use the machine language
directly because:
1. It is not standardised – depends on the CPU
2. Difficult to use – long development times
However it does have some advantages
1. Faster execution
2. Requires less memory.

14

7
5/17/2020

15

High-level Languages
• To write programs that are independent of the CPU on which they will
be executed, software designers use high level languages, which
combine algebraic expressions and symbols taken from English.

• There are many high-level languages available.

• Fortran (Scientific), Cobol (Business), LISP (Artificial Intelligence (AI))


Prolog (AI), Java (Internet), C++ (General), Python (General)

15

16

Programming Languages

https://www.webopedia.com/TERM/H/high_level_language.html

16

8
5/17/2020

17

Execution Steps

https://thebittheories.com/levels-of-programming-languages-b6a38a68c0f2

17

18

Software Development Method


1. Specify the problem requirements.
2. Analyze the problem.
3. Design the algorithm to solve the problem.
4. Implement the algorithm.
5. Test and verify the completed program.
6. Maintain and update the program.

18

9
5/17/2020

19

Problem Specification
Specifying the problem requirements allows you to:

1. State the problem clearly and unambiguously


2. Gain a clear understanding of what is required for its solution
3. Eliminate unimportant aspects

To achieve this goal you may find you need more information from the
person who posed the problem.

19

20

Analysis
Analyzing the problem involves identifying the:

1. Inputs - the data you have to work with


2. Outputs - the desired results
3. Additional requirements or constraints on the solution.

20

10
5/17/2020

21

Design
Designing the algorithm
1. Develop a list of steps called an algorithm to solve the problem
2. Verify that the algorithm solves the problem as intended. Writing the
algorithm is often the most difficult part of the problem-solving
process. Coding and algorithm is simple once you know the
programming language syntax

Don't attempt to solve every detail of the problem at the beginning.

Top-down Design Approach


1. List the major steps, or subproblems, that need to be solved
2. Solve the original problem by solving each of its sub-problems.

21

22

Implementation
Implementing the algorithm

• Involves writing the algorithm as a computer program.


• You must convert each step of the algorithm into one or more
statements in a programming language.
• Requires a full grip on programming language syntax and
constraints

22

11
5/17/2020

23

Testing and Verification


Testing and verification

• Requires testing the completed program to verify that it works as


desired.
• Don't rely on just one test case.
• Run the program several times using different sets of data, making
sure that it works correctly for every situation provided for in the
algorithm.

23

24

Maintenance
Maintaining and updating

• Involves modifying a program to remove previously undetected


errors and to keep it upto-date as government regulations or
company policies change.

• Many organizations maintain a program for five years or more, often


after the programmers who originally coded it have left or moved on
to other positions.

24

12
5/17/2020

25

Development of C Language
• The creation of C language changed the way programming was
approached and thought about
• The creation of C was direct result of need of a structured, efficient
high level language that could replace assembly language
• C was first developed in 1970s by Dennis Ritchie
• C was formally standardized in 1989
• C++ is enhancement of C which supports Objected oriented
Programming (OOP) that helps organize large complex problems.

25

26

Development of Java
• Language innovation is driven by two factors: improvement in art of
Tests
programming and computing environment
• Java inherits the rich legacy of C and C++ and adds new features
required by current state of art systems
• Java offers features that streamline programming for a distributed
architecture
• Java was initially conceived in 1991 by a group of programmers at
Sun Microsystems and was initially called “Oak” but it was renamed
as Java in 1995.

26

13
5/17/2020

27

Purpose of Java
• C++ required a different compiler for each of these devices as these
Tests
had a different kind of CPU and compilers are expensive and time
consuming
• The primary motivation was the need to have a platform independent
language that could be used in consumer electronics, microwave,
toasters, remote control etc.
• The need for platform independent language increased after the
development of internet as internet connected devices consisted of
various types of computers, CPUs and operating systems.
• Internet caused Java programmers to switch from consumer
electronics to internet

27

28

Java and C/C++


• Java is directly related to C/C++ as it inherits syntax from C/C++.
• Its object oriented model is adapted Tests
from C++
• Any programmer who knows C/C++ can easily understand Java and
vice versa.
• Java takes the best of the past languages and adds new features
needed for the online and platform independent environment
• Although java was influenced by C/C++, it is not an enhanced
version of C/C++ and is not compatible with C/C++.
• Java is not designed to replace C/C++ and both of these will coexist
as these sort different sorts of problems.

28

14
5/17/2020

29

Java’s Success
• Java’s success lies in its adaptability to changing programming
environments Tests
• Java’s release cycles is about 1.5 years compared to 10 years for
other languages
• Java is more secure and portable

29

30

Java’s Magic: The Bytecode


• Java’s security and portability advantage lies in the fact that it java
compiler does not produce an executable
Tests file, it produces java
bytecode
• Bytecode is a highly optimized set of instructions designed to be
executed by java runtime systems called java virtual machine (JVM).
• Translating a java program into bytecode makes it easier to run on a
variety of platforms as only JVM needs to be updated
• Although details of JVM will differ from platform to platform, all
understand same bytecode
• Since JVM is in control so it prevents from generating side effects
and makes system more secure

30

15
5/17/2020

31

Java’s Magic: The Bytecode


• Compiling program to an intermediate
Testsform and then interpreting it
makes process slower compared to if it was compiled to an
executable code, the difference is not great because bytecode is
highly optimized

• It is not practical to compile an entire Java program into executable


code all at once, because Java performs various run-time checks
that can be done only at run time.

31

32

Java Buzz Words


• Simple
• Secure Tests
• Portable
• Object-oriented
• Robust
• Multithreaded
• Architecture-neutral
• Interpreted
• High performance
• Distributed
• Dynamic

32

16
5/17/2020

33

Running Java Code


• Different learning environments available
Tests for running Java program
• Popular are NetBean, Eclipse, BlueJ, Jedit, Jgrasp etc.
• In this course we will be using NetBeans IDE.
• Go to start menu and search for NetBeans and open it

33

34

Using NetBeans
Tests

34

17
5/17/2020

35

Creating New Project


Go to File> New Project

Tests

35

36

Creating New Project

Tests

36

18
5/17/2020

37

Creating New Project

Tests

37

38

Creating New Project

Tests

38

19
5/17/2020

39

Creating New Project

Tests

39

40

Creating New Project

Tests

40

20
5/17/2020

41

Creating New Project

Tests

41

42

Writing first Program


/*
This is a simple Java program.
Tests
Call this file "Example.java".
*/
public class Example {
// Your program begins with a call to main().
public static void main(String args[]) {
System.out.println("This is a simple Java program.");
}
}

42

21
5/17/2020

43

Building first Program

Tests

43

44

Output of Build

Tests

44

22
5/17/2020

45

Running Program

Tests

45

46

Output of Run

Tests

46

23
5/17/2020

47

A closer look at the program


/* (Comments)
This is a simple Java program.
Tests
Call this file "Example.java".
*/

// Your program begins with a call to main().

The contents of a comment are ignored by the compiler. Instead, a


comment describes or explains the operation of the program to anyone
who is reading its source code.

47

48

public key word


public class Example1 {
} Tests

The public keyword is an access specifier, which allows the programmer


to control the visibility of class members. When a class member is
preceded by public, then that member may be accessed by code
outside the class in which it is declared.

The opposite of public is private, which prevents a member from being


used by code defined outside of its class

48

24
5/17/2020

49

static and void

public static void main(String args[ ])


Tests

The keyword static allows main( ) to be called without having to


instantiate a particular instance of the class.

The keyword void simply tells the compiler that main( ) does not return
a value.

49

50

main() method

public static void main (String args[ ])


Tests

• All Java applications begin execution by calling main( )


• main( ) must be declared as public, since it must be called by code
outside of its class when the program is started.
• Keep in mind that Java is case-sensitive. Thus, Main is different from
main.
• It is important to understand that the Java compiler will compile
classes that do not contain a main( ) method. But java has no way to
run these classes.

50

25
5/17/2020

51

String args[ ]

public static void main(String args[ ])


Tests

• String args[ ] declares a parameter named args, which is an array of


instances of the class String.
• Objects of type String store character strings. In this case, args
receives any command-line arguments present when the program is
executed.

51

52

Printing a statement

System.out.println("This is a simple Java program.");


Tests

This line outputs the string “This is a simple Java program.” followed by
a new line on the screen.

Output is actually accomplished by the built-in println( ) method. In this


case, println( ) displays the string which is passed to it.

println( ) can be used to display other types of information, too.

52

26
5/17/2020

53

Another Simple Program


class Example2 {
public static void main(String args[]) {
Tests
int num; // this declares a variable called num
num = 100; // this assigns num the value 100
System.out.println("This is num: " + num);
num = num * 2;
System.out.print("The value of num * 2 is ");
System.out.println(num);
}
}

53

Thank You

54

27

You might also like