Skip to content
IT-504 (B) · E Commerce & Governance/Quick Revision Short Notes

E Commerce & Governance (IT-504 (B)) - Unit 2 Short Notes

Unit 2: Technologies for E-Commerce & Governance

2.1 Artificial Intelligence Fundamentals

2.1.1 Problem Solving & Search Algorithms

Uninformed Search (Blind Search)

  • Uses no problem-specific knowledge beyond the problem definition.

  • Breadth-First Search (BFS)

    • Explores all nodes at the present depth before moving to the next level.

    • Uses a queue (FIFO).

    • Complete? Yes (if branching factor finite). Optimal? Yes (for unit step costs).

    • Time Complexity: $$\displaystyle O(b^d) $$ | Space Complexity: $$\displaystyle O(b^d) $$

      • $b$ = branching factor, $d$ = depth of solution.
  • Depth-First Search (DFS)

    • Explores as far as possible along a branch before backtracking.

    • Uses a stack (LIFO).

    • Complete? No (infinite depth or cycles). Optimal? No.

    • Time Complexity: $$\displaystyle O(b^m) $$ | Space Complexity: $O(bm)$

      • $m$ = maximum depth of search tree.

[!TIP] Exam Comparison Table: DFS vs BFS

| Feature | BFS | DFS |

|---------|-----|-----|

| Data Structure | Queue | Stack |

| Completeness | Yes (finite $b$) | No |

| Optimality | Yes (unit cost) | No |

| Space Complexity | $$\displaystyle O(b^d) $$ | $O(bm)$ |

| Time Complexity | $$\displaystyle O(b^d) $$ | $$\displaystyle O(b^m) $$ |

| Use Case | Finding shortest path | Exploring deep paths, memory constrained |

Informed Search (Heuristic Search)

  • Uses heuristic function $h(n)$ to estimate cost from node $n$ to goal.

  • A Algorithm*

    • Evaluates nodes by: $$\displaystyle f(n) = g(n) + h(n) $$

      • $g(n)$: actual cost from start to node $n$.

      • $h(n)$: estimated cost from $n$ to goal (heuristic).

    • Optimal if $h(n)$ is admissible (never overestimates true cost) and consistent.

    • Application: 8-Puzzle Problem

      • $h(n)$ = Number of misplaced tiles (admissible but not always consistent).

      • $g(n)$ = Depth of node (number of moves from start).

      • Expand node with lowest $f(n)$.

Local Search

  • Used for optimization problems where path to goal is irrelevant; only goal state matters.

  • Hill Climbing

    • Greedy algorithm: moves to neighbor with best heuristic value.

    • Problems:

      1. Local Maxima: Peak higher than neighbors but not global max.

      2. Plateaus: Flat area where all neighbors have same value.

      3. Ridges: Sequence of local maxima with steep slopes.

2.1.2 Production Systems

  • Definition: A formalism for AI problem-solving consisting of:

    • Production Rules (Condition-Action pairs): IF <condition> THEN <action>.

    • Working Memory: Current state of problem.

    • Rule Interpreter: Matches rules to working memory, fires actions.

  • Characteristics: Modularity, Incrementality, Understandability.

  • Application: Water Jug Problem (4-gallon & 3-gallon jugs)

    • State Representation: $(x, y)$ where $x$ = water in 4-gal jug, $y$ = in 3-gal jug.

    • Goal: $(2, y)$ (any $y$).

    • Production Rules:

      1. IF (x < 4) THEN Fill 4-gal jug → $(4, y)$

      2. IF (y < 3) THEN Fill 3-gal jug → $(x, 3)$

      3. IF (x > 0) THEN Empty 4-gal jug → $(0, y)$

      4. IF (y > 0) THEN Empty 3-gal jug → $(x, 0)$

      5. IF (x > 0 AND y < 3) THEN Pour 4→3 → $(\max(0, x-(3-y)), \min(3, x+y))$

      6. IF (y > 0 AND x < 4) THEN Pour 3→4 → $(\min(4, x+y), \max(0, y-(4-x)))$

    • One Solution Path:

      $$\displaystyle (0,0) \xrightarrow{1} (4,0) \xrightarrow{5} (1,3) \xrightarrow{4} (1,0) \xrightarrow{6} (0,1) \xrightarrow{2} (0,3) \xrightarrow{5} (4,0?) $$ Wait, correct sequence:

      $$\displaystyle (0,0) \xrightarrow{\text{Fill 4}} (4,0) \xrightarrow{\text{Pour 4→3}} (1,3) \xrightarrow{\text{Empty 3}} (1,0) \xrightarrow{\text{Pour 4→3}} (0,1) \xrightarrow{\text{Fill 4}} (4,1) \xrightarrow{\text{Pour 4→3}} (2,3) $$ Goal reached: (2,3).

2.1.3 Knowledge Representation

Properties of a Good KR System:

  1. Representational Adequacy: Can express required knowledge.

  2. Inferential Adequacy: Supports deriving new knowledge.

  3. Inferential Efficiency: Guides inference process effectively.

  4. Acquisitional Efficiency: Easy to acquire new knowledge.

Representation Techniques:

  • Predicate Logic (First-Order Logic)

    • Uses predicates, variables, quantifiers ($\forall$, $\exists$), connectives.

    • Conversions:

      • "Everybody loves Ram": $\forall x \; Loves(x, Ram)$

      • "Everybody loves somebody": $\forall x \; \exists y \; Loves(x, y)$

      • "There is somebody whom everybody loves": $\exists y \; \forall x \; Loves(x, y)$

      • "There is somebody who Ram doesn't love": $\exists x \; \neg Loves(Ram, x)$

      • "There is somebody whom no one loves": $\exists x \; \forall y \; \neg Loves(y, x)$

  • Fuzzy Sets

    • Elements have degree of membership $\in [0,1]$.

    • Given: $$\displaystyle A = 1/x_1 + 0.3/x_2 + 0.5/x_3 + 0.2/x_4 $$, $$\displaystyle B = 0.5/x_1 + 0.4/x_2 + 0.1/x_3 + 1/x_4 $$

    • Union ($A \cup B$): $$\displaystyle \mu_{A\cup B}(x) = \max(\mu_A(x), \mu_B(x)) $$

      • $$\displaystyle = 1/x_1 + 0.4/x_2 + 0.5/x_3 + 1/x_4 $$
    • Intersection ($A \cap B$): $$\displaystyle \mu_{A\cap B}(x) = \min(\mu_A(x), \mu_B(x)) $$

      • $$\displaystyle = 0.5/x_1 + 0.3/x_2 + 0.1/x_3 + 0.2/x_4 $$
    • Difference ($A - B$): $$\displaystyle \mu_{A-B}(x) = \min(\mu_A(x), 1-\mu_B(x)) $$

      • $$\displaystyle = 0.5/x_1 + 0.3/x_2 + 0.5/x_3 + 0/x_4 $$
    • Complement ($\bar{A}$): $$\displaystyle \mu_{\bar{A}}(x) = 1 - \mu_A(x) $$

      • $$\displaystyle \bar{A} = 0/x_1 + 0.7/x_2 + 0.5/x_3 + 0.8/x_4 $$, $$\displaystyle \bar{B} = 0.5/x_1 + 0.6/x_2 + 0.9/x_3 + 0/x_4 $$
  • Schematic Nets (Semantic Networks)

    • Graph-based: nodes = objects/concepts, edges = relationships.

    • Used for representing is-a (inheritance), has-property, instance-of.

    • Example: Cat --is-a--> Mammal --is-a--> Animal; Cat --has-property--> (fur, meows).

2.1.4 Reasoning Methods

  • Forward Reasoning (Data-Driven)

    • Starts from known facts, applies rules to derive new facts until goal is reached.

    • Example: Medical diagnosis: symptoms → rules → disease.

  • Backward Reasoning (Goal-Driven)

    • Starts from goal, works backward to find supporting facts.

    • Example: Prove Loves(Ram, Sita)? Check rules with Loves(Ram, Sita) in THEN part.

  • Resolution Technique

    • Rule of inference for propositional/first-order logic.

    • Unifies two clauses containing complementary literals, produces resolvent.

    • Basis for Prolog and theorem proving.

  • Reasoning Paradigms

    • Monotonic Reasoning: Adding knowledge never retracts conclusions. Traditional logic.

    • Non-Monotonic Reasoning: Adding knowledge can invalidate previous conclusions. Used for default reasoning, e.g., "Birds fly" (unless penguin).

2.1.5 Advanced AI Topics & Applications

  • Game Theory: Min-Max Algorithm

    • Used in two-player, zero-sum games (e.g., Tic-Tac-Toe, Chess).

    • Max player (AI) tries to maximize score; Min player (opponent) tries to minimize.

    • Search game tree to a fixed depth, evaluate leaf nodes with evaluation function.

    • Back up values: Max node = max(child values), Min node = min(child values).

    • Example: Simple game tree

      DiagramSEARCH: min-max algorithm game tree example
      .

  • Machine Learning: Types in Neural Networks

    1. Supervised Learning: Labeled data (e.g., classification, regression).

    2. Unsupervised Learning: Unlabeled data (e.g., clustering).

    3. Reinforcement Learning: Agent learns via rewards/punishments.

    4. Semi-supervised Learning: Mix of labeled/unlabeled.

  • Natural Language Processing: Components of NLU

    1. Lexical Analysis: Tokenization, POS tagging.

    2. Syntactic Analysis: Parsing (syntax tree).

    3. Semantic Analysis: Meaning representation (e.g., logical form).

    4. Discourse Integration: Context across sentences.

    5. Pragmatic Analysis: Real-world knowledge, intentions.

  • Expert Systems

    • AI programs that emulate human expert's decision-making in a narrow domain.

    • Components: Knowledge Base, Inference Engine, User Interface, Explanation Facility, Knowledge Acquisition.

    • Characteristics: High performance, reliability, understandability.

  • Probability & Uncertainty: Bayes' Theorem

    • $$\displaystyle P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)} $$

    • Used to update belief in hypothesis $A$ given evidence $B$.

    • Application: Spam filtering, medical diagnosis.


2.2 Java Programming for E-Commerce Applications

2.2.1 Core Java & Object-Oriented Programming

Java as an OOP Language: Supporting Reasons

  • Everything is inside classes/objects.

  • Four Pillars: Abstraction, Encapsulation, Inheritance, Polymorphism.

  • No multiple inheritance via classes (via interfaces).

  • No global functions/variables (everything belongs to class).

Classes, Objects, Constructors

  • Class: Blueprint/template.

  • Object: Instance of class.

  • Constructor: Special method to initialize object.

    • Types:

      1. Default: No args, provided by compiler if none defined.

      2. Parameterized: Accepts arguments.

      3. Copy: Accepts object of same class.

    • Example: Area of Circle using Constructor

      
      class Circle {
      
          double radius;
      
          Circle(double r) { radius = r; } // Parameterized
      
          double area() { return Math.PI * radius * radius; }
      
      }
      
      

Keywords

  • static

    • Class-level member (one copy per class).

    • static methods can access only static members directly.

    • Used for main(), utility methods, constants.

  • final

    • Variable: Constant (value cannot change).

    • Method: Cannot be overridden.

    • Class: Cannot be subclassed (inherited).

Polymorphism

  • Method Overloading (Compile-time): Same method name, different parameters in same class.

  • Method Overriding (Runtime): Subclass provides specific implementation of superclass method.

  • Dynamic Method Dispatch: Runtime decision on which overridden method to call (via superclass reference).

Inheritance & Abstraction

  • Abstract Class:

    • Cannot be instantiated.

    • May have abstract methods (no body) and concrete methods.

    • Implementation Cases:

      1. Partial abstraction (some abstract, some concrete methods).

      2. All methods abstract (like interface pre-Java 8).

  • Interface:

    • Pure abstraction (pre-Java 8: all methods abstract by default).

    • Purpose: Define contract, achieve multiple inheritance.

    • Achieving Multiple Inheritance: A class can implement multiple interfaces.

      
      interface A { void methodA(); }
      
      interface B { void methodB(); }
      
      class C implements A, B { ... }
      
      

Program Example: nth Prime Number


import java.util.Scanner;

class Prime {

    static boolean isPrime(int n) {

        if (n <= 1) return false;

        for (int i = 2; i <= Math.sqrt(n); i++)

            if (n % i == 0) return false;

        return true;

    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), count = 0, num = 2;

        while (count < n) {

            if (isPrime(num)) count++;

            if (count == n) {

                System.out.println(n + "th prime: " + num);

                break;

            }

            num++;

        }

    }

}

2.2.2 Exception Handling & Memory Management

  • Exception Handling Mechanism

    • try: Block containing code that may throw exception.

    • catch: Handles exception of specific type.

    • throw: Explicitly throws an exception.

    • throws: Declares exception that method might throw (caller must handle).

    • Example:

      
      void divide(int a, int b) throws ArithmeticException {
      
          if (b == 0) throw new ArithmeticException("Divide by zero");
      
          System.out.println(a/b);
      
      }
      
      
    • Assertions: assert condition; or assert condition : message; – used for debugging, enabled with -ea flag.

  • Java Garbage Collection

    • Automatic memory management.

    • JVM reclaims memory from unreachable objects.

    • finalize(): Called by GC before object is destroyed (deprecated in Java 9+). Not reliable for cleanup.

2.2.3 Multithreading

  • Thread Creation:

    1. Extend Thread class, override run().

    2. Implement Runnable interface, pass to Thread constructor (preferred).

  • Lifecycle: NEW → RUNNABLE → RUNNING → BLOCKED/WAITING → TERMINATED.

  • Thread Synchronization

    • synchronized keyword: Ensures only one thread accesses method/block at a time.

      • Synchronized method: synchronized void method() {...}

      • Synchronized block: synchronized(this) {...}

    • Inter-Thread Communication:

      • wait(): Thread releases lock and waits.

      • notify() / notifyAll(): Wakes up waiting thread(s).

      • Must be called from synchronized context.

  • Example: Three Threads with Different Intervals

    
    class MyThread extends Thread {
    
        String msg; int interval;
    
        MyThread(String m, int i) { msg=m; interval=i; }
    
        public void run() {
    
            while(true) {
    
                System.out.println(msg);
    
                try { Thread.sleep(interval*1000); } catch (InterruptedException e) {}
    
            }
    
        }
    
    }
    
    // In main: new MyThread("Hello!",1).start(); new MyThread("Wear Mask!",2).start(); ...
    
    

2.2.4 Input/Output (I/O) Streams

  • Stream Concept: Sequence of data.

  • Byte Streams: InputStream/OutputStream (for binary data, 8-bit bytes).

  • Character Streams: Reader/Writer (for text, 16-bit Unicode).

  • Capturing User Input: Scanner (from System.in) or BufferedReader.

  • File Operations: Copy File using Character Streams

    
    import java.io.*;
    
    class CopyFile {
    
        public static void main(String[] args) throws IOException {
    
            FileReader fr = new FileReader("source.txt");
    
            FileWriter fw = new FileWriter("dest.txt");
    
            int ch;
    
            while ((ch = fr.read()) != -1) fw.write(ch);
    
            fr.close(); fw.close();
    
        }
    
    }
    
    

2.2.5 Graphical User Interface (GUI) & Applets

  • AWT vs Swing:

    • AWT: Heavyweight components (native), platform-dependent.

    • Swing: Lightweight components (Java), platform-independent, richer set (JButton, JFrame).

  • Components & Containers:

    • Component: Button, Label, TextField.

    • Container: Frame, Panel, Applet (holds components).

  • Event Handling:

    • Event Source: Component generating event (e.g., button).

    • Event Listener: Interface implementing method to handle event (e.g., ActionListener with actionPerformed()).

    • Register listener: button.addActionListener(this);

  • Applet Life Cycle:

    1. init(): Called once when applet first loads.

    2. start(): Called after init(), and whenever applet becomes visible/active.

    3. stop(): Called when applet is no longer visible (e.g., page changed).

    4. destroy(): Called once before applet is unloaded.

  • Swing Program: Sum of Two Numbers

    
    import javax.swing.*;
    
    import java.awt.event.*;
    
    import java.awt.*;
    
    class SumGUI extends JFrame implements ActionListener {
    
        JTextField t1, t2, res;
    
        SumGUI() {
    
            t1 = new JTextField(10); t2 = new JTextField(10); res = new JTextField(10);
    
            JButton b = new JButton("Add");
    
            b.addActionListener(this);
    
            add(t1); add(t2); add(b); add(res);
    
            setLayout(new FlowLayout());
    
            setSize(300,200); setVisible(true);
    
        }
    
        public void actionPerformed(ActionEvent e) {
    
            int a = Integer.parseInt(t1.getText());
    
            int b = Integer.parseInt(t2.getText());
    
            res.setText(String.valueOf(a+b));
    
        }
    
        public static void main(String[] args) { new SumGUI(); }
    
    }
    
    

2.2.6 Database Connectivity & Networking

  • JDBC (Java Database Connectivity)

    • Basic Steps:

      1. Load driver: Class.forName("com.mysql.jdbc.Driver");

      2. Establish connection: Connection con = DriverManager.getConnection(url, user, pass);

      3. Create statement: Statement st = con.createStatement();

      4. Execute query: ResultSet rs = st.executeQuery("SELECT * FROM table");

      5. Process results: while(rs.next()) { ... }

      6. Close resources: rs.close(); st.close(); con.close();

    • JDBC-ODBC Bridge: JDBC driver that translates JDBC calls to ODBC calls (deprecated, used for legacy databases).

  • Networking: Client-Server Communication (Socket Programming)

    
    // Server
    
    ServerSocket ss = new ServerSocket(1234);
    
    Socket s = ss.accept();
    
    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    
    PrintWriter out = new PrintWriter(s.getOutputStream(), true);
    
    out.println("Hello Client");
    
    // Client
    
    Socket s = new Socket("localhost", 1234);
    
    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    
    PrintWriter out = new PrintWriter(s.getOutputStream(), true);
    
    String msg = in.readLine();
    
    

2.2.7 Java Beans & JNDI

  • Java Beans

    • Reusable software components with no-arg constructor, getter/setter methods, serializable.

    • Introspection: Process of analyzing a bean's properties, events, methods at runtime.

    • BeanInfo Interface: Implemented by bean designer to explicitly provide bean information (property descriptors, event set descriptors) to IDE/tools, overriding default introspection.

  • JNDI (Java Naming and Directory Interface)

    • API for accessing naming/directory services (e.g., LDAP, DNS).

    • Context Interface Methods:

      • bind(String name, Object obj): Binds name to object.

      • rebind(String name, Object obj): Replaces existing binding.

      • createSubcontext(String name): Creates new subcontext.

      • getAttributes(String name): Returns attributes of named object.

      • modifyAttributes(String name, Attributes attrs): Modifies attributes.

2.2.8 Packages & Access Control

  • Creating Package: package com.mypkg; at top of source file. Place in corresponding directory com/mypkg/.

  • Using Package: import com.mypkg.MyClass;

  • Levels of Access Protection:

    | Modifier | Class | Package | Subclass | World | |----------|-------|---------|----------|-------| | public | ✓ | ✓ | ✓ | ✓ | | protected | ✓ | ✓ | ✓ | ✗ | | default (no modifier) | ✓ | ✓ | ✗ | ✗ | | private | ✓ | ✗ | ✗ | ✗ |

    • Implementation: Place modifier before class/interface/member declaration.
Go to where you left off?

Quick Add to Notes

Save questions, your own notes and screenshots into notes filed by unit. It takes a free account.

Create free account

Have an account? Log in