# data[].attributes.body
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Student s=new Student();
s.sayHi();
// Person p=new Person();
// p.sayHi();
Person p;
p=s;
p.sayHi();

}
}

abstract class Person {
abstract void sayHi();
/* {
System.out.println("Ahoi from a Person");
}
*/
}

class Student extends Person {
void sayHi() {
System.out.println("Olla from a Student");
}

}

# data[].attributes.body
import java.lang.Math; // headers MUST be above the first class
import java.lang.Exception.*;

// one class needs to have a main() method
public class HelloWorld
{
// arguments are passed using the text field below this editor
public static void main(String[] args) {
OtherClass myObject = new OtherClass("Hello World!");
System.out.println(myObject);
try {
String s1=myObject.getString("WooHOO");
int i=myObject.getNumber();
String s2=myObject.getString("WhatLaoEh");
}
catch(ArithmeticException e1) {
System.out.println("Yo dude! Go back to Arihtmetic class!");
}
finally {
System.out.println("Finally I'm DONE!");
}
}
}

// you can add other public classes to this editor in any order
public class OtherClass {
private String message;
private boolean answer = false;
public OtherClass(String input) {
message = "Why, " + input + " Isn't this something?";
}
public String toString() {
return message;
}
public int getNumber() {// throws Exception {
int i=3/0;
System.out.println("in GET NUMBER");
return i;
}
public String getString(String stuff) {
System.out.println(stuff);
return stuff;
}
}

# data[].attributes.body
import java.lang.Math; // headers MUST be above the first class
import java.lang.Exception.*;

// one class needs to have a main() method
public class HelloWorld
{
// arguments are passed using the text field below this editor
public static void main(String[] args) {
OtherClass myObject = new OtherClass("Hello World!");
System.out.println(myObject);
try {
String s1=myObject.getString("WooHOO");
int i=myObject.getJunk1(); //myObject.getNumber();
String s2=myObject.getString("WhatLaoEh");
}
catch(ArithmeticException e1) {
System.out.println("Yo dude! Go back to Arihtmetic class!");
}
finally {
System.out.println("Finally I'm DONE!");
}
}
}

// you can add other public classes to this editor in any order
public class OtherClass {
private String message;
private boolean answer = false;
public OtherClass(String input) {
message = "Why, " + input + " Isn't this something?";
}
public String toString() {
return message;
}
public int getNumber() {// throws Exception {
int i=3/0;
System.out.println("in GET NUMBER");
return i;
}
public String getString(String stuff) {
System.out.println(stuff);
return stuff;
}
public int getJunk1() {
int a=0;
try {
a=this.getJunk2();
System.out.println("Normal Junk1");
}
catch(ArithmeticException e2) {
System.out.println("Caught ArithmeticException in getJunk1");
}
finally {
System.out.println("in JUNK1");
}
return a;
}

public int getJunk2() {
int b=0;
try {
b=this.getJunk3();
System.out.println("Normal Junk2");
}
finally {
System.out.println("in JUNK2");
}
return b;
}

public int getJunk3() {
int x=10/0;
System.out.println("Normal Junk3");
return x;
}
}

# data[].attributes.headline
What happens when you click  the 'PressMe' button:

# data[].attributes.subject
What happens when you click  the 'PressMe' button:

# data[].attributes.body
1. Since the Controller is a Listener to the button, the actionPerformed method is called;
2. The actionPerformed method calls the incrementValue() method in the Model;
3. The Model updates the counter value by 1, calls setChanged(), and finally notifyObservers() and passing the new counter value as parameter;
4. Since the View is an Observer (linked to the Model in the RunMVC constructor), it's update() method is called (via notifyObservers());
5. The update() method gets the counter value and sets the textField to the value.

# data[].attributes.body
public void decrementValue() {
--counter;
System.out.println("Model     : counter = " + counter);
setChanged();
notifyObservers(counter);
}

# data[].attributes.body
public void actionBtnDecrease() {
System.out.println("Controller: acting on Model");
model.decrementValue();
}

public void actionBtnReset() {
System.out.println("Controller: acting on Model");
model.setValue(0);
}

# data[].attributes.body
...
private Button btnIncrease;
private Button btnDecrease;
private Button btnReset;
private Controller myController;
...

in Constructor:
btnIncrease = new Button("Increase");
btnDecrease = new Button("Decrease");
btnReset = new Button("Reset");
panel.add(btnDecrease);
panel.add(btnReset);
panel.add(btnIncrease);
...
public void addController(ActionListener controller){
System.out.println("View      : adding controller");
btnIncrease.addActionListener(controller); //need instance of controller before can add it as a listener
this.myController=(Controller)controller;
btnDecrease.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed (java.awt.event.ActionEvent e)  {
myController.actionBtnDecrease();
}
}
);
btnReset.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed (java.awt.event.ActionEvent e)  {
myController.actionBtnReset();
}
}
);

} //addController()

# data[].attributes.body
SELECT * FROM AYAM WHERE WEIGHT<5

SELECT * FROM AYAM WHERE WEIGHT<5 OR TRUE

String sql="SELECT * FROM AYAM WHERE WEIGHT";

condition="<5 OR TRUE";

String sqlToExec = sql+condition;

# data[].attributes.body
Table: Balance
acctNo     balance
111     1000
222     1000

What SQL statement to execute to transfer 500 from account 111 to 222?

1. SQL1: UPDATE Balance SET balance=500 WHERE accountNum=111
2. SQL2: UPDATE Balance SET balance=1500 WHERE accountNum=222

What happens if system fails after executing SQL1 but before executing SQL2?

acctNo     balance
111          500
222        1000

I.e. acctNo has lost 500 to the 'system'!!!

To Avoid, use Transactions
transaction Start
SQL1
SQL2
...
transaction commit

# data[].attributes.body
void pause()  {
try {
out.printf("\n\n  Press ENTER..");
System.in.read();
}
catch(IOException exe){
out.printf("Error?");
}
}