aws workshop

AWS Workshop Details

Amazon Web Services (AWS) is a subsidiary of Amazon.com that provides on-demand cloud computing platforms to individuals, companies and governments, on a paid subscription basis with a free-tier option available for 12 months. The technology allows subscribers to have at their disposal a full-fledged virtual cluster of computers, available all the time, through the internet.

database cofiguration

 sudo apt-get install software-properties-common
 sudo apt-get install postgresql-client
 sudo apt-get update


 username: apssdc
 host:awscloud.cgsmzwe95pul.us-west-2.rds.amazonaws.com 
 password:apssdc123
 dbname:test

  
 to connect to remoto database

 sudo psql -U apssdc -h awsakash.cgsmzwe95pul.us-west-2.rds.amazonaws.com -p 5432 postgres


 CREATE SCHEMA apssdc;

 CREATE TABLE apssdc.student
(
  myname character varying,
  fathername character varying,
  mobileno character varying,
  email character varying,
  gender character varying,
  address character varying
);


INSERT INTO apssdc.student( myname , email ) values('akash','test@gmail.com');

application configuration

installing java in ubuntu

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default
java -version


installing tomcat in ubuntu

sudo wget http://www-eu.apache.org/dist/tomcat/tomcat-7/v7.0.81/bin/apache-tomcat-7.0.81.tar.gz
sudo tar xvzf apache-tomcat-7.0.81.tar.gz
sudo mv apache-tomcat-7.0.81 /opt/tomcat
sudo chmod -R 777 /opt/tomcat/ 

configuring jndi in tomcat server

in the context.xml add the below line in the <context> tag

<ResourceLink name="jdbc/amdds" global="jdbc/amdds" type="javax.sql.DataSource" />

in server.xml add the below lines inside <GlobalNamingResources>  before ending tag

<Resource name="jdbc/amdds" 
  auth="Container" 
  description="CTM RFID Application Database Connection" 
  driverClass="org.postgresql.Driver" 
  maxPoolSize="3" 
  minPoolSize="1"
  user="apssdc"
  password="apssdc123" 
  acquireIncrement="1"
  factory="org.apache.naming.factory.BeanFactory" 
  type="com.mchange.v2.c3p0.ComboPooledDataSource" 
  jdbcUrl="jdbc:postgresql://awscloud.cgsmzwe95pul.us-west-2.rds.amazonaws.com/postgres" />

build automation with tomcat and ant tool

build automation with tomcat and ant tool

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<project name="cert" default="war" basedir=".">
 <description>Application build file</description>

 <target name="war">
  <mkdir dir="dist" />

  <war destfile="dist/cert.war" webxml="WebContent/WEB-INF/web.xml" >
   <fileset dir="WebContent" />
   <classes dir="WebContent/WEB-INF/classes" />
  </war>

  <copy todir="E:\driveE\softwares\tomcat7\webapps" flatten="true">
   <resources>
    <file file="dist/cert.war" />
   </resources>
  </copy>
 </target>
</project>

java system time

how to get the system time using java programming

Reading system time in java

public class CurrentTime{

 public static void main(String[] args){
 
    System.out.println(System.currentTimeMillis());
    System.out.println(System.nanoTime());
    System.out.println(System.identityHashCode(new CurrentTime()));
    System.out.println(System.getProperties());
    System.out.println(System.getenv());
 }
}

java read from console

java read from console

Read from console and write again to console

import java.io.Console;

public class ConsoleRead {

 public static void main(String[] args) {

  System.out.println("Enter Text on Console");
  Console c = System.console();
  String s = c.readLine();
  System.out.println(s);

 }

}

find execution time using of a program in java

find execution time using of a program in java

Create a RunningTime object and call methods to get time


package utils;

public class RunningTime {

 long startTime;

 public void startTime() {
  startTime = System.currentTimeMillis();
 }

 public long endTime() {
  return  System.currentTimeMillis();
 }

 public String totalTimeInSec() {
  return ((endTime() - startTime)/1000+" Sec");
 }
 
 public String totalTimeInMin() {
  return ((endTime() - startTime)/60000+" Min");
 }

}

java recursive file display

java recursive file display

Reads recursively all folders and subfolders

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;

import object.Java;
import utils.FileUtils;
public class RecursiveFileDisplay {

 static int folderCount = 0;
 static int fileCount = 0;
 static int noDetailsFound = 0;
 static Java response = new Java();

 public static void main(String[] args) throws IOException {
  // File currentDir = new File("."); // current directory
  String currentDir = "C:/Users/myworld/Desktop/java/";
  displayDirectoryContents(new File(currentDir));
  System.out.println("Total Folders : " + folderCount);
  System.out.println("Total Files :" + fileCount);
  System.out.println("NoDetailsFound :" + noDetailsFound);
  
        System.out.println(runningTime.totalTimeInMin());
 }

 public static void displayDirectoryContents(File dir) throws IOException {

  File[] files = dir.listFiles();

  for (File file : files) {
   if (file.isDirectory()) {
    System.out.println("directory:" + file.getName());
    folderCount = folderCount + 1;
    displayDirectoryContents(file);
   } else {
    System.out.println("     file:" + file.getName());
    fileCount = fileCount + 1;

    String javaClass = file.toPath().toString();
    String classWithPackage = javaClass.replaceAll("\\\\", ".").replaceFirst(".*Desktop.java.", "");
    String sb = new String(classWithPackage);
    String fullyQualifiedPackageName = null;
    response = new Java();
    response.setFilePath(file.toURI().toString());
    response.setSize(file.length() / 1024 + "KB");
    response.setFilename(file.getName());

    if (sb.substring(sb.length() - 5, sb.length()).toString().equals(".java") && true) {

     try {
      fullyQualifiedPackageName = sb.substring(0, sb.length() - 5).toString();
      response.setPackageName(fullyQualifiedPackageName.toString());
      
      ArrayList<String> fieldsList = listFields(Class.forName(fullyQualifiedPackageName));
      ArrayList<String> methodList = listMethods(Class.forName(fullyQualifiedPackageName));

      response.setFields(fieldsList.size());
      response.setMethods(methodList.size());
      response.setFieldsList(fieldsList);
      response.setMethodsList(methodList);
     } catch (Exception e) {
      System.out.println(e);
     } catch (ExceptionInInitializerError e) {
      System.out.println(e);
     }

    } else {
     noDetailsFound = noDetailsFound + 1;
     System.out.println("error file:" + fullyQualifiedPackageName);
     
    }

    FileUtils.writeFile("C:/Users/myworld/Desktop/meta.js", response.toString());
   }
  }

 }

 public static <T> ArrayList<String> listFields(Class<T> clazz) {
  ArrayList<String> feildList = new ArrayList<String>();
  Field[] allFields = clazz.getDeclaredFields();
  for (Field field : allFields) {
   feildList.add(field.getName().toString());
  }
  return feildList;

 }

 public static <T> ArrayList<String> listMethods(Class<T> clazz) {
  ArrayList<String> methodList = new ArrayList<String>();
  Method[] allMethods = clazz.getDeclaredMethods();
  for (Method method : allMethods) {
   methodList.add(method.getName().toString() + "()");
  }
  return methodList;
 }

}

printing the output using print stream

printing the output using print stream

printing to console

//printing the output using printstream object

import java.io.PrintStream;

public class PrintOut{

   public static void main(String[] args){
   
      PrintStream ps = new PrintStream(System.out);
   ps.println("pring the output");
   }
}