java in Aartificial intelligent by virat andodariya

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

Transcript of java in Aartificial intelligent by virat andodariya

1

AI Programming with JAVA

By:Virat Andodariya M.S.University

2

How Artificial Intelligence Programmed?

Java Basics

Graph coloring Problem

Uniform Cost Search

Contents

3

How Artificial Intelligence Programmed?

C++

C#

Java

Lisp

Python

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

5

Bytecodes and the Java Virtual Machine

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

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

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

9

Start a Java Application

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

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”

12

Comments

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

• Multiple Line Comment/* Some comments*/

• Documentation Comment/** Documentation Comment*/

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)

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.

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;

16

Break Statement

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

break [label] ;

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

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.

19

Graph coloring Problem

Graph In Matrix

20

Graph Coloring

21

22

23

24

25

Result

26

UniformCostSearch

27

28

29

30

31

32

33

34

35

36

37

38

39

References

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

40

Thank you