32
Introduction to Programming Languages

Introduction to Programming Languages. Problem Solving in Programming

Embed Size (px)

Citation preview

Page 1: Introduction to Programming Languages. Problem Solving in Programming

Introduction to Programming Languages

Page 2: Introduction to Programming Languages. Problem Solving in Programming

Problem Solving in Programming

Page 3: Introduction to Programming Languages. Problem Solving in Programming

Problem Solving

Primitive and Higher calculations Computer programming is artifact (tool) used

for the Problem solving mechanism via computers

Page 4: Introduction to Programming Languages. Problem Solving in Programming

Few Terms

Program Programming Programability

Page 5: Introduction to Programming Languages. Problem Solving in Programming

Algorithm and program

Algorithm is sequence of steps usually written in natural language readable for humans

Programming is the algorithm translated in programming language so that computer can understand

Page 6: Introduction to Programming Languages. Problem Solving in Programming

Programming – By Example

Mean of three Numbers Instructions Program Counter Fetch and Execute Cycle

Page 7: Introduction to Programming Languages. Problem Solving in Programming

Flow Charts

Page 8: Introduction to Programming Languages. Problem Solving in Programming

FlowCharts

Is common type of chart used to represents an algorithm or process.

The steps are shown in boxes of various kinds, and their order by connecting these with arrows.

Flowcharts are used in analyzing, designing, documenting or managing a process or program in various fields.

Page 9: Introduction to Programming Languages. Problem Solving in Programming

Flowchart The notations for flowchart are

Draw a flowchart that will compute the sum, average and product of three numbers.

Process Start / End

Decision Input / OutputT

F

Page 10: Introduction to Programming Languages. Problem Solving in Programming

How to develop Algorithm

Write Algorithm and draw flow chart of 10 numbers in a loop

Table of 2 Factorial

Page 11: Introduction to Programming Languages. Problem Solving in Programming

Jumping to Programming Languages

Page 12: Introduction to Programming Languages. Problem Solving in Programming

History (Paradigms) Unstructured Languages

Single continuous block of code e.g Assembly

Structured / Procedural Languages Functions and procedures e.g C, Pascal, Fortran

Object-Oriented Languages Real-world modeling (Attributes, Behavior) e.g C++, Java

Page 13: Introduction to Programming Languages. Problem Solving in Programming

Why we are going towards OOP? Object-oriented creatures Advantages:

Simpler, easier to read programs More efficient reuse of code Faster time to market More robust, error-free code

Concepts on the way ….

Page 14: Introduction to Programming Languages. Problem Solving in Programming

some basic questions??

What are the objects in OOP? What should be the objects in the design of

an object-oriented program? Is OOP better than previous programming

paradigms?

Page 15: Introduction to Programming Languages. Problem Solving in Programming

How will I understand?????

Page 16: Introduction to Programming Languages. Problem Solving in Programming

Computer and Humans

Computers understand 0’s and 1’s High level Language Machine level Language

Page 17: Introduction to Programming Languages. Problem Solving in Programming

Execution of a Program

Object Code

Source Code

Other Object Files

Linker

.exe fileExecute

Output

010101010101010101101000000……

Compiler

Page 18: Introduction to Programming Languages. Problem Solving in Programming

MyProg.class

MyProg.java

Compiler

Other class Files

Linker

A2 HJ JINJ JI JOJO 99 O1

JAR Archive

public class Sample{ public void main() { println( “hello”); }}

A2 N8 BH HJBK JI KO O9NJ JK L8 J9JI JO KJ KOK3 K9 98 90 ….

AB CD F3S6 JS JHN9 J5 33

JVM

hello

Java Interpreter

Page 19: Introduction to Programming Languages. Problem Solving in Programming

                         

                            

Page 20: Introduction to Programming Languages. Problem Solving in Programming
Page 21: Introduction to Programming Languages. Problem Solving in Programming

Java OOP language developed by SUN Microsystems Java is compiled into bytecodes Bytecodes are high-level, machine-independent

instructions for a hypothetical machine, the Java Virtual Machine (JVM)

The Java run-time system provides the JVM Extensive networking facilities Extensive set of APIs for GUIs, distributed

computing, 2D/3D graphics, mail, and others Portable: Write Once, Run Anywhere Multithreading support built into the language

Page 22: Introduction to Programming Languages. Problem Solving in Programming

Java Features Automatic garbage collection

No manual memory allocation and deallocation Never have to worry about memory leaks

No pointers or pointer arithmetic No off-by-one bugs

Arrays are first-class objects Array bounds are always checked

Multiple inheritance replaced by interfaces Eliminates complexities of multiple inheritance

Page 23: Introduction to Programming Languages. Problem Solving in Programming

Java Virtual Machine

Java is compiled into bytecodes Bytecodes are high-level, machine-independent

instructions for a hypothetical machine, the Java Virtual Machine (JVM)

The Java run-time system provides the JVM The JVM interprets the bytecodes during program

execution Since the bytecodes are interpreted, the performance of

Java programs slower than comparable C/C++ programs But the JVM is continually being improved and new

techniques are achieving speeds comparable to native C++ code

Page 24: Introduction to Programming Languages. Problem Solving in Programming

JVM All Java programs run on top of the JVM JVM was first implemented inside Web browsers, but

is now available on a wide variety of platforms JVM interprets the bytecodes defined in a machine-

independent file format called a class file

Page 25: Introduction to Programming Languages. Problem Solving in Programming

Types Of Java Programs

Application

Standalone Java program that can run independent of any Web browser

Applet

Java program that runs within a Java-enabled Web browser

Servlet

Java software that is loaded into a Web server to provide additional server functionality

Page 26: Introduction to Programming Languages. Problem Solving in Programming

Instructions for Java Installation Download and Install JDK NetBeans 6.7.1

Page 27: Introduction to Programming Languages. Problem Solving in Programming

Refference Book

The Complete Reference

Java 2 Fifth Edition. By Herbert Schildt

  

                                   

Page 28: Introduction to Programming Languages. Problem Solving in Programming

Hello World

class HelloWorld { public static void main(String args[]) { System.out.println("Hello World"); } }

Page 29: Introduction to Programming Languages. Problem Solving in Programming

Factorial

public class Factorial2{ public static void main(String args[]) { int n = 3; int fact = 1; for (int c = 1 ; c <= n ; c++ ) fact = fact*c; System.out.println("Factorial of "+n+" is = "+fact); }}

Page 30: Introduction to Programming Languages. Problem Solving in Programming

Table of Two or not ?

public class tables{ public static void main(String args[]) { for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { System.out.print(i + "x" + j + "=" + (i * j) + "\t"); } System.out.println(); } }}

Page 31: Introduction to Programming Languages. Problem Solving in Programming

Tables Output

Page 32: Introduction to Programming Languages. Problem Solving in Programming

Tasks

Just print Table of Two. Find Factorial with proper solution as output

like 5! = 5 x 4 x 3 x 2 x 1 = 120. Each new term in the Fibonacci sequence is

generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Write a program to find out if a number is prime?