Monday 30 November 2015

How to Show ppt or PowerPoint presentation in Html without using Flash.

We use Google api to Show ppt..


<iframe src="http://docs.google.com/gview?url=www.cse.wustl.edu/~cdgill/courses/cs6785/Java_NIO.ppt&embedded=true" style="width:600px; height:500px;" frameborder="0">
<!--
 url=example.com/name.ppt  
You have to place  your url in case of "example.com/name.ppt  "
-->
</iframe>

It will Show as..

How to Use garbage collection in java?

import java.util.*;

 class GarbageCollection{  

 public static void main(String s[]) throws Exception  

 {      Runtime rs =  Runtime.getRuntime();

  System.out.println("Free memory in JVM before Garbage Collection = "+rs.freeMemory()); 

     rs.gc();//garbage collection    

  System.out.println("Free memory in JVM after Garbage Collection = "+rs.freeMemory()); 
//We can also use 
System.gc();

  }}

Friday 27 November 2015

POJO to JSON and JSON to POJO useing GSON api.

       
//POJO
package com.trail;

public class DataDTO {
 
 String name;
 String role;
 String ID;
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getRole() {
  return role;
 }
 public void setRole(String role) {
  this.role = role;
 }
 public String getID() {
  return ID;
 }
 public void setID(String iD) {
  ID = iD;
 }
 

}


Impl class..

       
package com.trail;

import com.google.gson.Gson;

public class TrailMain {

 public static void main(String args[]){
  
 DataDTO dataDTO=new DataDTO();
 //set data in POJO
 
 dataDTO.setID("1011");
 dataDTO.setName("Sky");
 dataDTO.setRole("Student");
 
 //make it to the JSON String By  useing GSON API
 Gson gson=new Gson();
 String jsonString=gson.toJson(dataDTO);
 
 /*
  * String jsonString contain the JSON data
  * like-{"name":"Sky","role":"Student","ID":"1011"}
  * */
  System.out.println(jsonString);
  
  
  //get data in POJO from JSON String
  
  DataDTO dataDTO2=gson.fromJson(jsonString,DataDTO.class);
 System.out.println(dataDTO2.getID());
 System.out.println(dataDTO2.getName());
 System.out.println(dataDTO2.getRole());
  
  
  
 }
 
 
}

set Gson.jar in classpath and Compile these code..It will Show Out put in Console

It will ....

Tuesday 3 November 2015

How to make Image to String like Base64 encryption in javcascript ?

<input type="file" onchange="imgLoad()"><br>
<img src="" height="200" alt="Image preview...">

<script>
function imgLoad(){
var p=document.querySelector('img');
var f=document.querySelector('input[type=file]').files[0];
var read=new FileReader();
read.onloadend=function(){
p.src=read.result;
alert(read.result)
}

if(f){
read.readAsDataURL(f);
}

}

</script>

Example....


Image preview...