java in artificial intelligent

40
AI Programming with JAVA By:Virat Andodariya M.S.University 1

Upload: virat-andodariya

Post on 14-Aug-2015

49 views

Category:

Engineering


8 download

TRANSCRIPT

Page 1: JAVA in Artificial intelligent

1

AI Programming with JAVA

By:Virat Andodariya M.S.University

Page 2: JAVA in Artificial intelligent

2

How Artificial Intelligence Programmed?

Java Basics

Graph coloring Problem

Uniform Cost Search

Contents

Page 3: JAVA in Artificial intelligent

3

How Artificial Intelligence Programmed?

C++

C#

Java

Lisp

Python

Page 4: JAVA in Artificial intelligent

4

• The Java Virtual Machine• Applications & Applets• Classes & Objects• Start up Java• Variables & Assignments• Strings & Characters• Arithmetic Operators & Expressions• Comments• Keywords• Creating and Compiling Programs• Modifiers

Page 5: JAVA in Artificial intelligent

5

Bytecodes and the Java Virtual Machine

Page 6: JAVA in Artificial intelligent

6

Java Program

• Java Application Program– Application• Program written in general programming language

– Applet• Program running in Web Browser Environment• Can be viewed by appletviewer or Web browser with

JVM

Page 7: JAVA in Artificial intelligent

7

Classes and Objects

• Object– Memory Space to Define State and Operation– Instance of Class

• Class– A class is a template or blueprint for objects. To program in

Java, you must understand classes and be able to write and use them.

– Template of Creating Object

Page 8: JAVA in Artificial intelligent

8

The Java Class Libraries

• java.applet : Applet related• java.awt : Abstract Window Toolkit• java.awt.event : Event process from awt component• java.awt.image : Image processing• java.beans : JavaBeans Component• java.io : File or Network I/O Support• java.lang : Java Language Support• java.net : Network related functions• java.util : Utility function

Page 9: JAVA in Artificial intelligent

9

Start a Java Application

Page 10: JAVA in Artificial intelligent

10

Variables and Assignments

• Types– char 16bits Unicode character data– boolean Boolean Variable– byte 8 bits signed integer– short 16 bits signed integer– int 32 bits signed integer– long 64 bits signed integer– float 32 bits signed floating point number– double 64 bits signed floating point number

Page 11: JAVA in Artificial intelligent

11

Variables and Assignments

• String : sequence of characterString s = “Enter an integer value: ” ;

• Concatenation Operator ‘+’String s = “Lincoln said: ” + “\” Four score and seven years

ago\”” ;Result : Lincoln said: “Four score and seven years ago”

Page 12: JAVA in Artificial intelligent

12

Comments

• Single Line Comment– int i = 10 ; // i is counter

• Multiple Line Comment/* Some comments*/

• Documentation Comment/** Documentation Comment*/

Page 13: JAVA in Artificial intelligent

13

Java Keywords

• 50 Java Keywordsabstract double int superboolean else interface s witchbreak extends long synchronizedbyte final native thiscase finally new throwcatch float package throwschar for private transient*class goto* protected tryconst* if public voidcontinue implements return volatiledefault import short whiledo instanceof static strictfp

assert (New in 1.5) enum (New in 1.5)

Page 14: JAVA in Artificial intelligent

14

Control Statement

• A statement represents an action or a sequence of actions. To change the execution order of program • As the method of controlling the execution order – Conditional Statement : if St., switch St.– Repeat Statement : for St., while St., do-while St.– Branch Statement : break St., continue St., return St.

Page 15: JAVA in Artificial intelligent

15

For Statement

Repeat the sequence of statement as many as defined. Form of for statement

for ( <expr. 1> ; < expr. 2> ; < expr. 3>) <statement>

<expr. 1> : initialize the control variable <expr. 2> : check the control variable <expr. 3> : modify the control variable

s = 0; for (i=1; i<=N; ++i) // sum from 1 to N : i increment s += i;

Page 16: JAVA in Artificial intelligent

16

Break Statement

• To move control to the out of the block• From of break statement

break [label] ;

Page 17: JAVA in Artificial intelligent

17

Creating and Compiling Programs

Source Code

Create/Modify Source Code

Compile Source Code i.e. javac Welcome.java

Bytecode

Run Byteode i.e. java Welcome

Result

If compilation errors

If runtime errors or incorrect result

Page 18: JAVA in Artificial intelligent

18

Modifiers

Java uses certain reserved words called modifiers that specify the properties of the data, methods, and classes and how they can be used.

Examples of modifiers are public and static. Other modifiers are private, final, abstract, and protected. A public datum, method, or class can be accessed by other programs. A private datum or method cannot be accessed by other programs.

Page 19: JAVA in Artificial intelligent

19

Graph coloring Problem

Graph In Matrix

Page 20: JAVA in Artificial intelligent

20

Graph Coloring

Page 21: JAVA in Artificial intelligent

21

Page 22: JAVA in Artificial intelligent

22

Page 23: JAVA in Artificial intelligent

23

Page 24: JAVA in Artificial intelligent

24

Page 25: JAVA in Artificial intelligent

25

Result

Page 26: JAVA in Artificial intelligent

26

UniformCostSearch

Page 27: JAVA in Artificial intelligent

27

Page 28: JAVA in Artificial intelligent

28

Page 29: JAVA in Artificial intelligent

29

Page 30: JAVA in Artificial intelligent

30

Page 31: JAVA in Artificial intelligent

31

Page 32: JAVA in Artificial intelligent

32

Page 33: JAVA in Artificial intelligent

33

Page 34: JAVA in Artificial intelligent

34

Page 35: JAVA in Artificial intelligent

35

Page 36: JAVA in Artificial intelligent

36

Page 37: JAVA in Artificial intelligent

37

Page 38: JAVA in Artificial intelligent

38

Page 39: JAVA in Artificial intelligent

39

References

• Java™ 2:The Complete Reference,Fifth Edition Herbert Schildt• JDK Developer Kit• JGRASP (CSD) Compiler

Page 40: JAVA in Artificial intelligent

40

Thank you