Demo

Basic

  1. WAP to read 2 numbers and print addition
  2. WAP to read 2 numbers and print subtraction
  3. WAP to read 2 numbers and print multiplication
  4. WAP to read 2 numbers and print division
  5. WAP to read 2 numbers and print modulus (Remainder)
  6. WAP to read radius and print area and circumference of circle
  7. WAP to read length and breadth and print area and perimeter of rectangle

Conditional Statement (if else)

  1. WAP to read a number and check if its positive or negative
  2. WAP to read a number and check it is even or odd
  3. WAP to read 2 numbers and find greatest among them
  4. WAP to read 3 numbers and find greatest among them
  5. WAP to read marks of 5 subjects and check the student is pass or failed
    1. add validation for marks less than 0
    2. add validation for marks greater than 100

Loops

  1. WAP to print hello world 10 times with numbering
  2. WAP to print square of numbers from 1 to 10
  3. WAP to print numbers from 1 to given number
  4. WAP to print cube of numbers from 1 to given number
  5. WAP to read a number and print table of that number
  6. WAP to execute Fizz Buzz Problem / Print number 1 to 100
    1. if number is divisible by 3 then print Fizz
    2. if number is divisible by 5 then print Buzz
    3. if number is divisible by both 3 and 5 then print Fizz Buzz
  7. WAP to execute lift program of 20 floor
    1. print number with delay of 1 sec (use time module’s sleep method)
    2. skip 13 number
    3. break after printing 13
  8. WAP to create random jackpot number and take input from user to guess the number. Based on level the attempt to guess the number should change
    1. Easy – 20 attempts
    2. Medium – 10 attempts
    3. Difficult – 5 attempts

Interview Questions

  1. What is the difference between html and html5
  2. Tag name available in html5
  3. What is javascript
  4. What is ajax and its benefits
  5. what is the different type of request available in ajax
  6. what is jquery and its benefits
  7. Main difference between javascript and jquery
  8. Event in jquery
  9. example of jquery event
  10. what is difference between CSS and CSS3
  11. what is media query in CSS
  12. What is bootstrap
  13. what is grid system in bootstrap
  14. What is JSON
  15. What is API
  16. What is PHP
  17. what is variable in PHP
  18. what types of variable available in PHP
  19. what is array in PHP
  20. how many types of array available in PHP
  21. difference between associative array and multidimentional array
  22. Difference between library function and user defined function in php
  23. Give me example of library function
  24. Difference between sessions and cookies
  25. What is difference between get and post method
  26. What is database
  27. What is table
  28. What is database MYSQL queries
  29. Type of relationship available in MYSQL
  30. Which datatype is use to store image in table
  31. What is OOPS
  32. Difference between classes and objects
  33. What is the different type array function in PHP
  34. Difference between concat() and array_push()
  35. Difference between constructor() and destructor()
  36. Types of error available in PHP
  37. Difference between library file and helper file
  38. Give me any three datatype of date and time
  39. What is blob in MYSQL
  40. Difference between RDBMS and DBMS
  41. Difference between string datatype and varchar datatype
  42. Difference between text datatype and String datatype
  43. What is datatype in MYSQL
  44. What are the meaning of classes and objects
  45. Difference between argument and parameter
  46. difference between cookies and local storage
  47. what is the difference between session storage and local storage
  48. Difference between notice error and warning error
  49. What is the library
  50. Difference between authentication and authorization
  51. What is MVC
  52. What is polymorphism
  53. Difference between Primary key and foreign key
  54. What is the full form of DOM and give its types
  55. Can table have more than one primary key

Interceptor

index.js

import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import axios from 'axios';
// Add a request interceptor
axios.interceptors.request.use(
  config => {
    console.log("inside interceptor request", config)

    const token = "TOKEN FROM INTERCEPTORS"
    if (token) {
      console.log("INSIDE request use")
      config.headers['Authorization'] = 'Bearer ' + token
    }
    
    return config
  },
  error => {
    Promise.reject(error)
  }
)


axios.interceptors.response.use(
  config => {
    console.log("inside interceptor response", config)
    return config
  },
  error => {
    Promise.reject(error)
  }
)



const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

reportWebVitals();

App.js

import logo from './logo.svg';
import './App.css';
import { useEffect } from 'react';
import axios from 'axios';

function App() {

  useEffect(()=> {

    axios({
      method: 'get',
      url: 'http://localhost:1234/webservice.php'
    })
      .then(function (response) {
        console.log(response)
      });
    
  }, [])

  return (
    <>
    This is App component
    </>
  );
}

export default App;

webservice.php

<?php

header("Access-Control-Allow-Origin: *");

// echo "<pre>";
// print_r($_SERVER);

echo json_encode(["test" => "Hello world...."]);

Redux

src/store.js

import { combineReducers, configureStore } from "@reduxjs/toolkit";

const initial_state = { userid: 1, emailid: "admin@nstest.com" }

const adminreducer = (state = initial_state, {type, payload}) => {

  if(type == "SET_VAL") {
    console.log("INSIDE SET_VAL case")
    return {...state, emailid : payload.emailid }
  }

  return state
}

const userreducer = (state = { payload: {} }, {type, payload}) => {

    if(type == "SET_USER_VAL") {
      console.log("INSIDE SET_USER_VAL case")
      return {...state, payload : payload }
    }
  
    return state
  }


const reducer = combineReducers({adminreducer, userreducer})

const store = configureStore({reducer})

export default store;

src/index.js

import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import store from './store';
import { Provider } from 'react-redux';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <Provider store={store}>
    <App />
    </Provider>
  </React.StrictMode>
);

reportWebVitals();

src/App.js

import { useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import Admin from "./components/Admin";
import Contact from "./components/Contact";
import Home from "./components/Home";
import Layout from "./components/Layout";
import User from "./components/User";

function App() {

  const mystate = useSelector((state) => state)

  return (
    <div>
      This is app component <br />
      {mystate.payload}
      <Contact />
      <BrowserRouter>
        <Routes>
          <Route path="/" element={ <Layout />}>

            <Route index element={ <Home /> } />
            <Route path="admin" element={ <Admin /> } />
            <Route path="user" element={ <User /> } />

          </Route>
        </Routes>
      </BrowserRouter>
    </div>
  );
}

export default App;

src/components/Admin.js

import React, { useEffect } from 'react'
import { useDispatch } from 'react-redux'

export default function Admin() {

    const dispatch = useDispatch()

    useEffect(() => {
        console.log("Hello dispatcher...")
        dispatch({ type : "SET_VAL", payload: { "emailid" : "admin@devtest.com"} })
    }, [])

  return (
    <div>Admin</div>
  )
}

src/component/User.js

import React, { useEffect } from 'react'
import { useDispatch } from 'react-redux'

export default function User() {

    const dispatcher = useDispatch()

    useEffect(() => {
        console.log("Inside user use effect")

        dispatcher({ 
          "type" : "SET_USER_VAL", 
          payload : { emailid : "user@devtest.com", time: new Date().toJSON().slice(0, 10) }
        })

    }, [])

  return (
    <div>User</div>
  )
}

Setter and Getter for Redux

store.js

import { combineReducers, configureStore } from "@reduxjs/toolkit";

const appdata = (state = {}, {type, payload}) => {

  if(type == "SET_APP_DATA") {
    return {...state, [payload[0]]: payload[1] }
  }

  if(type == "DELETE_APP_DATA") {
    return {...state, [payload]: undefined }
  }

  return state
}

const reducer = combineReducers({appdata})
const store = configureStore({reducer})

export const setRedux = (key, val) => {
  store.dispatch({ type : "SET_APP_DATA", "payload": [key, val] })
}

export const getRedux = (key = undefined) => {
  return store.getState().appdata[key]
}

export const removeRedux = (key = undefined) => {
  store.dispatch({ type : "DELETE_APP_DATA", "payload": key })
}


export default store;

In component

setRedux("username", "admin")
setRedux("email", "admin@nstest.com")
setRedux("phoneno", "9876543210")

getRedux("email")
getRedux("name")

removeRedux("email")

Routing

npm i react-router-dom 
npx create-react-app routingapp

App.js

import Home from './components/Home';
import Blogs from './components/Blogs';
import Contact from './components/Contact';
import NoPage from './components/NoPage';
import { BrowserRouter, Outlet, Route, Routes } from 'react-router-dom';
import Layout from './components/Layout';

function App() {
  return (
    <>
    <h1>HELLO WORLD</h1>
    <BrowserRouter>
      <Routes>
        <Route path="/admin" element={<Layout />}>
          <Route index element={<Home />} />
          <Route path="contact" element={<Contact />} />
          <Route path="*" element={<NoPage />} />
        </Route>
        <Route path="/user" element={<Layout />}>
          <Route index element={<Home />} />
          <Route path="contact" element={<Contact />} />
          <Route path="blogs" element={<Blogs />} />
          <Route path="test" element={<div>This is test component</div>} />
          <Route path="*" element={<NoPage />} />    
        </Route>
      </Routes>
    </BrowserRouter>
    </>

  );
}

export default App;

Layout.js

import { Outlet, Link } from "react-router-dom";

export default function Layout() {
  return (
    <>
      <nav>
        <ul>
          <li>
            <Link to="/">Home</Link>
          </li>
          <li>
            <Link to="/blogs">Blogs</Link>
          </li>
          <li>
            <Link to="/contact">Contact</Link>
          </li>
        </ul>
      </nav>
      <Outlet />
    </>
  )
}

Outlet is the block where router components get loaded

Datatable

listing.html

<!-- https://datatables.net/examples/server_side/simple.html -->
<!-- https://datatables.net/manual/ajax -->
<!-- https://datatables.net/manual/ajax#Column-data-points -->
<!-- https://stackoverflow.com/questions/64526856/how-to-add-edit-delete-buttons-in-each-row-of-datatable -->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.css">
  
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.2.0/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.12.1/css/dataTables.bootstrap5.min.css">

    <script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-3.6.1.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.js"></script>
    <title>Document</title>
</head>
<body>
<table id="example" class="display table table-striped" style="width:100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Address</th>
                <th>Salary</th>
                <th>Action</th>
            </tr>
        </thead>
    </table>
</body>
<script>
    $(document).ready(function () {
    $('#example').DataTable({
        processing: true,
        serverSide: true,
        ajax: 'http://ciacloud.in/juhi/rems/get_employees.php',
        columns: [
            { data: 'name'},
            { data: 'address'},
            { data: 'salary'},
            { 
                data: 'id',
                render: (data,type,row) => {
                    console.log({data,type,row})
                   return `<a href='edit_form.php?id=${data}'>Edit</a> | <a href='delete.php?id=${data}'>Delete</a>`;
                 }
            }
        ],
        columnDefs: [
            { orderable: false, targets: -1 },
            {
                "defaultContent": "-",
                "targets": "_all"
            }],
            order: [0,1,2,3],
    });
});
</script>
</html>

get_employees.php

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$params = $_REQUEST;
header('Access-Control-Allow-Origin: *');

$search = isset($params['search']['value'])  && $params['search']['value'] != '' ? $params['search']['value'] : '';

try {
  $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  $where = '';

  if($search !== '')
	  $where = " name LIKE '$search%' ";
  else
	  $where = " 1 = 1 ";

  $sort_columns = ['name', 'address', 'salary'];
  $sort_column_index = $params['order'][0]['column'];
  $sort_order = isset($params['order'][0]['dir']) && $params['order'][0]['dir'] != 1 ? $params['order'][0]['dir'] : 'desc';

  $order_by = " $sort_columns[$sort_column_index] $sort_order";
	
  $offset = $params['start'];
  $limit = $params['length'];

  $sql = "SELECT * FROM employees WHERE $where ORDER BY $order_by LIMIT $offset, $limit";
  $stmt = $conn->prepare($sql);
  $stmt->execute();

  // set the resulting array to associative
  $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  $employees = $stmt->fetchAll();

} catch(PDOException $e) {
  echo "Error: " . $e->getMessage();
}

$count_sql = "SELECT COUNT(*) FROM employees WHERE $where";
$result = $conn->prepare($count_sql); 
$result->execute(); 
$totalRecords = $result->fetchColumn(); 

$conn = null;


$json_data = array(
		"draw"            => intval( $params['draw'] ),
		"recordsTotal"    => intval( $totalRecords ),
		"recordsFiltered" => intval($totalRecords),
		"data"            => $employees,
		"count_sql"	=> $count_sql,
		"sql"		=> $sql,
	);

echo json_encode($json_data);

Spring Boot

app.groovy

class Demo {

	public static String foo() {

		return "Hello Spring Boot";
	}

}


class Employee {

	String name;
	int salary;

	public Employee() {
		this.name = "";
		this.salary = 0;
	}

	public Employee(String n, int s) {
		this.name = n;
		this.salary = s;
	}

}


@RestController
class HelloWorld {
  @RequestMapping("/")
  String hello() {
    "Hello JournalDev World."  + Demo.foo();
  }

	@RequestMapping("/emps")
	public List<Employee> getEmps() {
		List<Employee> list = new ArrayList<>();
		list.add(new Employee("Alfi", 20000))
		list.add(new Employee("Nikhil", 30000))
		return list;
	}

	@RequestMapping("/sqr")
	String getSqr(@RequestParam("num") int x) {
		"Square of " + x + " is " + (x * x);
	}

	@RequestMapping("/emp")	
	public ResponseEntity<Employee> readRawJson(@RequestBody Employee e) {
		System.out.println("\n=============="+ e.name +"==============\n");
		return ResponseEntity.ok(e);
	}
}

To run via CLI

spring run app.groovy — –server.port=9000

Ref Link:
https://docs.spring.io/spring-boot/docs/current/reference/html/cli.html

SQL DQL Test 2

  1. list all selling in 2019
  2. count all selling year wise order by selling
  3. select all selling in march month of year 2019
  4. count selling in 22 week of year 2020
  5. select all selling from 1st Feb 2019 to 31st Mar 2019
  6. select all customers who place orders in 2019
  7. select all customers from USA who placed order in 2019
  8. select all customers whose order is on hold
  9. select all customers who placed order in march month only
  10. select top 5 customers from USA (who has maximum orders from country USA)

SQL DQL Test 1

  1. select employees in descending order – salary
  2. select all employees from Mumbai
  3. select all employees having salary more than average salary
  4. select sum of salary from table
  5. select all unique address
  6. select details, salary from table
    (details should be concatenation of name and address)
  7. select names of employees having max salary
  8. select employees having 2nd max salary
  9. count employees by address, order by employee count
    e.g. select count(name,address) from employee
  10. show count of employees from nagpur only
  11. select all employees whose names starts or ends with vowels
  12. find employees having max salary in particular city
  13. select top 5 salaried employees
  14. select 2nd highest salaried employees
  15. show cities having total salary more than 200000
  16. Show all students who appeared for exam
  17. show student, subject and total marks of students whose total marks are more than 80