Tuesday, 21 January 2020

try catch finally in java manupulation

class Main {
  public static void main(String args[]) {
    int num1, num2;
    try {
      /*
       * We suspect that this block of statement can throw exception so we handled it
       * by placing these statements inside try and handled the exception in catch
       * block
       */
      try {
        num1 = 0;
        num2 = 62 / num1;
        System.out.println(num2);
        System.out.println("Hey I'm at the end of try block");
      } catch (ArithmeticException e) {
        System.out.println("iNNER CATCH try block");
      }
      finally {
      System.out.println("inNER finally block---");
    }
    } catch (ArithmeticException e) {
      /*
       * This block will only execute if any Arithmetic exception occurs in try block
       */
      System.out.println("You should not divide a number by zero-----" + e);
    } catch (Exception e) {
      /*
       * This is a generic Exception handler which means it can handle all the
       * exceptions. This will execute if the exception is not handled by previous
       * catch blocks.
       */
      System.out.println("Exception occurred" + e);
    } finally {
      System.out.println("in finally block");
    }
    System.out.println("I'm out of try-catch block in Java.");
  }
}

create folder and file in java

import java.io.File;

class Main {
  public void animalSound() {
  }

  public void sleep() {
    try{
    System.out.println("Zzz");
    File myObj = new File("pawan");
    myObj.mkdir();
    File myObjs = new File("pawan/filename123.txt");
    myObjs.createNewFile();
    } catch(Exception e) {
      System.out.println("error---"+e);
    }
  }

  public static void main(String arg[]) {
    Main gbh = new Main();
    gbh.sleep();
  }

import java.io.File;
import java.io.FileWriter;

class Main {
  public void animalSound() {
  }

  public void sleep() {
    try{
    System.out.println("Zzz");
    File myObj = new File("pawan");
    if(!myObj.exists()) {
    myObj.mkdir();
    }
    File myObjs = new File("pawan/filename123.txt");
    if(!myObjs.exists()) {
    myObjs.createNewFile();
    }
    FileWriter myWriter = new FileWriter("pawan/filename123.txt",true);
      myWriter.write("Files in Java might be tricky, but it is fun enough!");
      myWriter.close();
    } catch(Exception e) {
      System.out.println("error---"+e);
    }
  }

  public static void main(String arg[]) {
    Main gbh = new Main();
    gbh.sleep();
  }

}

Tuesday, 14 January 2020

Tuesday, 7 January 2020

convert time zone

CONVERT_TZ (dt, from_tz,to_tz)

SELECT convert_tz(sh_player_report.end_on,'UTC',sh_player_report.tz_name) as end_date , convert_tz(sh_player_report.start_on,'UTC',sh_player_report.tz_name) as start_on from sh_player_report where report_id=17183;

Wednesday, 1 January 2020

Node js API format.

node js api writing format.

1.file start with one line space with "use strict"
2.validate API fields
3.error handling with proper message
4.return response with proper key name.
5.file must not with with extra blank line.