# Java Backend for BSE Insider Trading Analyzer This directory contains Java code for fetching BSE insider trading data using ScraperAPI. ## Important Note about Java and Browsers **Java does NOT run directly in modern web browsers.** Despite the similar names, Java and JavaScript are completely different languages: - **JavaScript**: Runs natively in all modern browsers - **Java**: Runs on a Java Virtual Machine (JVM), typically on servers or desktop applications The Java code provided here must be compiled and executed on a server or desktop environment with JVM installed. It cannot be executed directly in a web browser. ## Backend Implementation The Java code in this directory is designed to run as a backend service: 1. `BseScraper.java` - Core scraping logic for BSE websites 2. `InsiderTradeServer.java` - Simple HTTP server providing an API endpoint 3. `pom.xml` - Maven project configuration file ## Setup Instructions ### Prerequisites - Java JDK 11+ installed - Maven for dependency management - ScraperAPI account (key already configured: `167259cf89a5c56e0e7ca670d6534743`) ### Building and Running 1. Build the project: ```bash cd java mvn clean package ``` 2. Run the server: ```bash java -jar target/bse-insider-server-1.0.jar ``` 3. The server will run on port 8080 by default (http://localhost:8080) ## API Endpoints - `GET /api/trades` - Get all insider trades - `GET /api/fetch` - Manually trigger data fetching ## Integration with Frontend Update the frontend application to fetch data from this Java backend: ```javascript const javaBackendUrl = 'http://localhost:8080/api/trades'; fetch(javaBackendUrl) .then(response => response.json()) .then(trades => { // Process trades data }) .catch(error => { console.error('Error fetching from Java backend:', error); }); ``` ## Alternative Approaches If you're looking for a solution that can run in the browser: 1. **JavaScript (Browser)**: Use a backend proxy service like our Node.js or PHP implementation 2. **WebAssembly**: For high-performance code in the browser (not Java) 3. **GraalVM**: Compile Java to native code (still requires a server) Java is primarily used for backend services, Android apps, and desktop applications - not for direct browser execution.