Skip to content

Instantly share code, notes, and snippets.

View dangnhdev's full-sized avatar

Nguyễn Hải Đăng dangnhdev

  • Hanoi, Vietnam
View GitHub Profile
public class Test {
public static void main(String[] args) {
int argument1 = 10000;
int argument2 = 9999;
method(argument1, argument2)
}
public static void method(int parameter1, int parameter2){
System.out.println(parameter1);
System.out.println(parameter2);
//A GET method in my stupid REST service for example.....
public Response sendMsg(String content, @QueryParam("msgType") String msgType) {
//Open class loader in try-with-resource
//Use null in constructor if you don't want to use parent class loader.
//In this case it's useful because I don't load any class from system classpath.
try (URLClassLoader clsLoader = URLClassLoader.newInstance(new URL[] {new URL("file:/lib/ACM_0.1.0.jar")}, null)){
Class<?> clazz = clsLoader.loadClass("com.hs.acm.client.message.in." + msgType);
Object msgObj = clazz.newInstance();
private AcmClientReqMsg getObjectFromJSon(MapMessage msg) {
try {
String msgContent = msg.getString("msgContent");
String msgType = msg.getString("msgType");
switch (msgType) {
case "MsgType1":
return gson.fromJson(msgContent, MsgType1.class);
case "MsgType2":
return gson.fromJson(msgContent, MsgType2.class);
case "MsgType3":
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
*
* @author dangg
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.glassfish.jersey.servlet.ServletContainer;
/**
*
* @author dangg
*/
import java.time.*;
public interface TimeClient {
void setTime(int hour, int minute, int second);
void setDate(int day, int month, int year);
void setDateAndTime(int day, int month, int year,
int hour, int minute, int second);
LocalDateTime getLocalDateTime();
}
import java.time.*;
public interface TimeClient {
void setTime(int hour, int minute, int second);
void setDate(int day, int month, int year);
void setDateAndTime(int day, int month, int year,
int hour, int minute, int second);
LocalDateTime getLocalDateTime();
ZonedDateTime getZonedDateTime(String zoneString);
}
import java.time.*;
public interface TimeClient {
void setTime(int hour, int minute, int second);
void setDate(int day, int month, int year);
void setDateAndTime(int day, int month, int year,
int hour, int minute, int second);
LocalDateTime getLocalDateTime();
static ZoneId getZoneId (String zoneString) {
try {
import com.hs.acm.client.message.in.AcmClientReqMsg;
import com.hs.acm.client.message.in.JoinCallReqMsg;
import java.net.URL;
import java.net.URLClassLoader;
public class Test {
public static void main(String[] args) throws Exception {
URL[] urls = new URL[]{new URL("file:./lib/ACM_0.1.0.jar"),
new URL("file:./lib/ActiveStudy.Utility.2.0.1.jar")};
import java.nio.file.*;
import static java.nio.file.StandardWatchEventKinds.*;
/*
Author: NguyenHaiDang@ActiveStudy
*/
public class Watcher {
public static void main(String[] args) {
Path this_dir = Paths.get(".");
System.out.println("Now watching the current directory ...");