September 27, 2018

Motion Detection System in java

My first git hub project


The full source code will be available in Git Hub

Git Hub

http://javabelazy.blogspot.in/

September 26, 2018

Removing duplicate values from ArrayList in Java

/**
 * This is a sample java program
 * that demonstrate removing duplicate elements from an ArrayList
 *
 * 2 ways - one by using set and other by Iterating through each objects
 *
 * List Interface is implemented by ArrayList, LinkedList, Vector and Stack classes
 *
 */
package com.belazy.collections;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
 * @author Saurav
 *
 *
 * @version 1.6
 *
 */
public class RemoveDuplicates {

/**
* @param args
*/
public static void main(String[] args) {

List<String> orgList = new ArrayList<String>();
orgList.add("SACHIN");
orgList.add("SACHIN");
orgList.add("ANJALI");
orgList.add("SARA");
orgList.add("ARJUN");

List<String> processedList = new ArrayList<String>();

for(String str:orgList){
if(!processedList.contains(str)){
processedList.add(str);
}
}


Set<String> newSet = new LinkedHashSet<String>(orgList);

System.out.println(" Orginal List : "+orgList);
System.out.println(" After Removing duplicates : "+processedList);
System.out.println(" New Set : "+newSet);



}

}



Output

 Orginal List : [SACHIN, SACHIN, ANJALI, SARA, ARJUN]
 After Removing duplicates : [SACHIN, ANJALI, SARA, ARJUN]
 New Set : [SACHIN, ANJALI, SARA, ARJUN]

September 19, 2018

Currency Cron job sample

String url = "http://www.apilayer.net/api/live?access_key=" + currencyApiKey;
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("Accept", "application/json");
httpGet.addHeader("Content-type", "application/json");

HttpClient httpClient = HttpClientBuilder.create().build();
HttpResponse response = httpClient.execute(httpGet);

September 16, 2018

cron job example in java

package com.steffi.samples;

import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

public class CurrencyConvertor
{
    public static void main( String[] args ) throws Exception
    {
       
    JobDetail job = JobBuilder.newJob(Datascientist.class)
.withIdentity("steffi", "nijesh").build();


   
    Trigger trigger = TriggerBuilder
.newTrigger()
.withIdentity("steffi", "nijesh")
.withSchedule(
CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
.build();
   
    //schedule it
    Scheduler scheduler = new StdSchedulerFactory().getScheduler();
    scheduler.start();
    scheduler.scheduleJob(job, trigger);
 
    }
}


import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class Datascientist implements Job
{
public void execute(JobExecutionContext context)
throws JobExecutionException {

System.out.println("Hello Quartz!");

}

}

<dependencies>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.1.5</version>
</dependency>
</dependencies>

September 08, 2018

Read a list of json objects in java sample program

Read a list of json objects in java sample program




package com.belazy.json;

import java.io.File;
import java.io.IOException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class ReadJSONList {
private ObjectMapper mapper = null;

private ObjectMapper getObjectMapper(){
if(null == mapper)
mapper = new ObjectMapper();
return mapper;
}

public static void main(String[] args) {
ReadJSONList bscPhysics = new ReadJSONList();
bscPhysics.read("D:\\PTXSANCHAYKA\\zgc_physics.json");
}

private void read(String fileName) {
JsonNode rootArray;
try {
rootArray = getObjectMapper()
.readTree(new File(fileName));
for (JsonNode root : rootArray) {
JsonNode name = root.path("name");
System.out.println("Name of the student  : " + name);
System.out.println(getObjectMapper().writeValueAsString(root));
}
} catch (JsonProcessingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}}
}


Output



Name of the student  : "Lijesh"
{"name":"Lijesh","age":29,"cars":["Ford","BMW","Fiat"]}
Name of the student  : "Biju vas"
{"name":"Biju vas","age":32,"cars":["Ford","BMW","Fiat"]}
Name of the student  : "Smithesh"
{"name":"Smithesh","age":33,"cars":["Ford","BMW","Fiat"]}
Name of the student  : "Madhav haridas"
{"name":"Madhav haridas","age":28,"cars":["Ford","BMW","Fiat"]}
Name of the student  : "Murali Krishnan"
{"name":"Murali Krishnan","age":28,"cars":["Ford","BMW","Fiat"]}
Name of the student  : "Ranjini Raj"
{"name":"Ranjini Raj","age":28,"cars":["Ford","BMW","Fiat"]}


zgc_physics.json



[{
"name":"Lijesh",
"age":29,
"cars":[ "Ford", "BMW", "Fiat" ]
},{
"name":"Biju vas",
"age":32,
"cars":[ "Ford", "BMW", "Fiat" ]
},{
"name":"Smithesh",
"age":33,
"cars":[ "Ford", "BMW", "Fiat" ]
},{
"name":"Madhav haridas",
"age":28,
"cars":[ "Ford", "BMW", "Fiat" ]
},{
"name":"Murali Krishnan",
"age":28,
"cars":[ "Ford", "BMW", "Fiat" ]
},{
"name":"Ranjini Raj",
"age":28,
"cars":[ "Ford", "BMW", "Fiat" ]
}]




Facebook comments