Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
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 Few Terms Program Programming Programability 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 Programming – By Example Mean of three Numbers Instructions Program Counter Fetch and Execute Cycle Flow Charts 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. Flowchart The notations for flowchart are Process Start / End Decision Input / Output T F Draw a flowchart that will compute the sum, average and product of three numbers. How to develop Algorithm Write Algorithm and draw flow chart of 10 numbers in a loop Table of 2 Factorial Jumping to Programming Languages History (Paradigms) Unstructured Languages Structured / Procedural Languages Single continuous block of code e.g Assembly Functions and procedures e.g C, Pascal, Fortran Object-Oriented Languages Real-world modeling (Attributes, Behavior) e.g C++, Java 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 …. 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? How will I understand????? Computer and Humans Computers understand 0’s and 1’s High level Language Machine level Language Execution of a Program Source Code Other Object Files Execute Compiler .exe file Linker Object Code 010101010 101010101 101000000 …… MyProg.java public class Sample { public void main() { println( “hello”); } } Java Interpreter Other class Files A2 HJ JI NJ JI JO JO 99 O1 JVM Compiler JAR Archive Linker MyProg.class AB CD F3 S6 JS JH N9 J5 33 A2 N8 BH HJ BK JI KO O9 NJ JK L8 J9 JI JO KJ KO K3 K9 98 90 …. 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 Java Features Automatic garbage collection No pointers or pointer arithmetic No off-by-one bugs Arrays are first-class objects No manual memory allocation and deallocation Never have to worry about memory leaks Array bounds are always checked Multiple inheritance replaced by interfaces Eliminates complexities of multiple inheritance 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 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 machineindependent file format called a class file 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 Instructions for Java Installation Download and Install JDK NetBeans 6.7.1 Refference Book The Complete Reference Java 2 Fifth Edition. By Herbert Schildt Hello World class HelloWorld { public static void main(String args[]) { System.out.println("Hello World"); } } 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); } } 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(); } } } Tables Output 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?