==== Developer A side ======
class InterfaceTest2 { 
      public static void main(String[] args) { 
            A a = new A(); 
            a.methodA(); 
      } 
} 
==== Developer B side ======
=== Do not change Class name "A" and method "methodA"
=== Except two factors B side can change anything
class A { 
      void methodA() { 
           I i = InstanceManager.getInstance(); 
            i.methodB(); 
      } 
} 
interface I { 
      public abstract void methodB(); 
} 
class B implements I { 
      public void methodB() { 
           System.out.println("methodB in B class"); 
      } 
} 
class InstanceManager { 
      public static I getInstance() { 
            return new B(); 
      } 
}
Thursday, 27 March 2008
Friday, 21 March 2008
Java Split Example
public class Test {
public static void main(String[] args) {
String temp = "123.456";
String[] temp2 = new String[2];
temp2 = temp.split("[.]");
System.out.println(temp2[0]);
}
}
public static void main(String[] args) {
String temp = "123.456";
String[] temp2 = new String[2];
temp2 = temp.split("[.]");
System.out.println(temp2[0]);
}
}
Thursday, 20 March 2008
Simple JSon Example
<html>
<head>
<title>JSON test</title>
</head>
<body>
<select id="sel">
</select>
<script type="text/javascript">
var cafe = {"cafelist" : [
{"name" : "aaaaaa", "clubid" : "11111111"},
{"name" : "bbbbbbb", "clubid" : "2222222"},
{"name" : "CCC", "clubid" : 123213213}
]
};
for (var i=0; i<cafe.cafelist.length; i++)
{
//alert(cafe.cafelist[i].name + "," + cafe.cafelist[i].clubid);
var s = document.getElementById("sel");
s.options.add(new Option(cafe.cafelist[i].name, cafe.cafelist[i].clubid),i);
}
</script>
</body>
</html>
<head>
<title>JSON test</title>
</head>
<body>
<select id="sel">
</select>
<script type="text/javascript">
var cafe = {"cafelist" : [
{"name" : "aaaaaa", "clubid" : "11111111"},
{"name" : "bbbbbbb", "clubid" : "2222222"},
{"name" : "CCC", "clubid" : 123213213}
]
};
for (var i=0; i<cafe.cafelist.length; i++)
{
//alert(cafe.cafelist[i].name + "," + cafe.cafelist[i].clubid);
var s = document.getElementById("sel");
s.options.add(new Option(cafe.cafelist[i].name, cafe.cafelist[i].clubid),i);
}
</script>
</body>
</html>
Tuesday, 18 March 2008
Java Interface concept example2
===== TVBoard.java ===========
public interface TVBoard {
public void channelDown();
public void channelUp();
public void volumeDown();
public void volumeUp();
public void powerOnOff(boolean power);
}
========== SSgTV.java ===========
public class SSgTV implements TVBoard {
private String name = "SSg TV";
private int volume = 5;
private int channel = 7;
private boolean power = false;
 
public SSgTV() {
System.out.println("SSg TV is created.");
}
@Override
public void channelDown() {
this.channel -= 1;
System.out.println(this.name+"- channelDown");
}
@Override
public void channelUp() {
this.channel += 1;
System.out.println(this.name+" + channelIp");
}
 
@Override
public void volumeDown() {
this.volume -= 1;
System.out.println(this.name+" - volumnDown");
}
@Override
public void volumeUp() {
this.volume += 1;
System.out.println(this.name+" + volumnUp");
}
@Override
public void powerOnOff(boolean power) {
this.power = power;
  
if (this.power==false)
System.out.println(this.name+" power off");
else
System.out.println(this.name+" power on");
}
 
public void SleepTimer(int time) {
System.out.println(time+" please wait for power on or off");
  
this.powerOnOff(false);
}
}
============== LGsTV.java ==============
public class LGsTV implements TVBoard {
private String name = "LGg TV";
private int volume = 5;
private int channel = 7;
private boolean power = false;
 
public LGsTV() {
System.out.println("LGs TV is created.");
}
@Override
public void channelDown() {
this.channel -= 1;
System.out.println(this.name+"- channelDown");
}
@Override
public void channelUp() {
this.channel += 1;
System.out.println(this.name+" + channelIp");
}
 
@Override
public void volumeDown() {
this.volume -= 1;
System.out.println(this.name+" - volumnDown");
}
@Override
public void volumeUp() {
this.volume += 1;
System.out.println(this.name+" + volumnUp");
}
@Override
public void powerOnOff(boolean power) {
this.power = power;
  
if (this.power==false)
System.out.println(this.name+" power off");
else
System.out.println(this.name+" power on");
}
 
public void SleepTimer(int time) {
System.out.println(time+" please wait for power on or off");
  
this.powerOnOff(false);
}
}
=============== TVTestMain.java =============
public class TVTestMain {
/**
* @param args
*/
public static void main(String[] args) {
TVBoard tvBoard = new SSgTV();
tvBoard.powerOnOff(true);
tvBoard.channelUp();
tvBoard.channelDown();
tvBoard.volumeUp();
tvBoard.volumeUp();
tvBoard.volumeUp();
tvBoard.volumeUp();
tvBoard.powerOnOff(false);
System.out.println();
  
TVBoard gTvBoard = new LGsTV();
gTvBoard.powerOnOff(true);
gTvBoard.channelUp();
gTvBoard.channelDown();
gTvBoard.volumeUp();
gTvBoard.volumeUp();
gTvBoard.volumeUp();
gTvBoard.volumeUp();
gTvBoard.powerOnOff(false);
}
}
public interface TVBoard {
public void channelDown();
public void channelUp();
public void volumeDown();
public void volumeUp();
public void powerOnOff(boolean power);
}
========== SSgTV.java ===========
public class SSgTV implements TVBoard {
private String name = "SSg TV";
private int volume = 5;
private int channel = 7;
private boolean power = false;
public SSgTV() {
System.out.println("SSg TV is created.");
}
@Override
public void channelDown() {
this.channel -= 1;
System.out.println(this.name+"- channelDown");
}
@Override
public void channelUp() {
this.channel += 1;
System.out.println(this.name+" + channelIp");
}
@Override
public void volumeDown() {
this.volume -= 1;
System.out.println(this.name+" - volumnDown");
}
@Override
public void volumeUp() {
this.volume += 1;
System.out.println(this.name+" + volumnUp");
}
@Override
public void powerOnOff(boolean power) {
this.power = power;
if (this.power==false)
System.out.println(this.name+" power off");
else
System.out.println(this.name+" power on");
}
public void SleepTimer(int time) {
System.out.println(time+" please wait for power on or off");
this.powerOnOff(false);
}
}
============== LGsTV.java ==============
public class LGsTV implements TVBoard {
private String name = "LGg TV";
private int volume = 5;
private int channel = 7;
private boolean power = false;
public LGsTV() {
System.out.println("LGs TV is created.");
}
@Override
public void channelDown() {
this.channel -= 1;
System.out.println(this.name+"- channelDown");
}
@Override
public void channelUp() {
this.channel += 1;
System.out.println(this.name+" + channelIp");
}
@Override
public void volumeDown() {
this.volume -= 1;
System.out.println(this.name+" - volumnDown");
}
@Override
public void volumeUp() {
this.volume += 1;
System.out.println(this.name+" + volumnUp");
}
@Override
public void powerOnOff(boolean power) {
this.power = power;
if (this.power==false)
System.out.println(this.name+" power off");
else
System.out.println(this.name+" power on");
}
public void SleepTimer(int time) {
System.out.println(time+" please wait for power on or off");
this.powerOnOff(false);
}
}
=============== TVTestMain.java =============
public class TVTestMain {
/**
* @param args
*/
public static void main(String[] args) {
TVBoard tvBoard = new SSgTV();
tvBoard.powerOnOff(true);
tvBoard.channelUp();
tvBoard.channelDown();
tvBoard.volumeUp();
tvBoard.volumeUp();
tvBoard.volumeUp();
tvBoard.volumeUp();
tvBoard.powerOnOff(false);
System.out.println();
TVBoard gTvBoard = new LGsTV();
gTvBoard.powerOnOff(true);
gTvBoard.channelUp();
gTvBoard.channelDown();
gTvBoard.volumeUp();
gTvBoard.volumeUp();
gTvBoard.volumeUp();
gTvBoard.volumeUp();
gTvBoard.powerOnOff(false);
}
}
Thursday, 13 March 2008
Java Interface concept example
========= Example 1 =================
**** GuguInter.java ***
interface GuguInter {
public static final int input1 = 2;
public static final int input2 = 3;
public void printGugu2();
pulbic void printGugu3();
}
***** PrintGuguClass.java ******
public class PrintGuguClass implements GuguInter {
PrintGuguClass c = new PrintGuguClass();
c.printGugu2();
c.printGugu3();
}
public void printGugu2() {
System.out.println(GuguInter.input1+ " printed");
}
public void printGugu3() {
System.out.println(GuguInter.input2+ " printed");
}
}
============ Example 2 ====================
****** myInterface.java **********
interface myInterface {
public abstract void method();
}
**** CB.java ***********
class CB implements myInterface {
public void method() {
System.out.println("method in CB");
}
}
***** CC.java **********
class CC implements myInterface {
public void method() {
System.out.println("method in CC");
}
}
***** CA.java ********
class CA {
public void method(myInterface mi) {
my.method()
}
}
***** Cmain.java *****
class Cmain {
public static void main(String[] args) {
CA ca = new CA();
ca.method(new CB());
ca.method(new CC());
}
}
**** GuguInter.java ***
interface GuguInter {
public static final int input1 = 2;
public static final int input2 = 3;
public void printGugu2();
pulbic void printGugu3();
}
***** PrintGuguClass.java ******
public class PrintGuguClass implements GuguInter {
PrintGuguClass c = new PrintGuguClass();
c.printGugu2();
c.printGugu3();
}
public void printGugu2() {
System.out.println(GuguInter.input1+ " printed");
}
public void printGugu3() {
System.out.println(GuguInter.input2+ " printed");
}
}
============ Example 2 ====================
****** myInterface.java **********
interface myInterface {
public abstract void method();
}
**** CB.java ***********
class CB implements myInterface {
public void method() {
System.out.println("method in CB");
}
}
***** CC.java **********
class CC implements myInterface {
public void method() {
System.out.println("method in CC");
}
}
***** CA.java ********
class CA {
public void method(myInterface mi) {
my.method()
}
}
***** Cmain.java *****
class Cmain {
public static void main(String[] args) {
CA ca = new CA();
ca.method(new CB());
ca.method(new CC());
}
}
Subscribe to:
Comments (Atom)
 
