Tag » Object Oriented Programming

MIT 6.00SC | Recitation 05 | Quiz 1 Answers and Object-Oriented Programming

The first 25 min of the Recitation is about Quiz 1 which we will not listen to now.

Object Oriented Programming

Classes allow to define a custom type. 963 more words

MIT OCW

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

public class DNADecoder {

/*
codonMap will iterate thru all the entries in the input file
containing the codons and their protein corresponding values,
and store them inside the codonsMap as key-value relationships
between codon-protein. 182 more words
CSE143

Colonies

The next consideration in the design of an ObjectTalk distributed processing capability was the way in which two ObjectTalk instances interact. In working through this it became apparent that there were 3 distinct approaches that would be the most appropriate for initial investigation. 1.108 more words

Object Oriented Programming

Sedikit Tentang, OOP

Object-Oriented Programming (OOP) adalah pemrograman yang tujuan utamanya membentuk objek, dan mengatur interaksi objek dengan objek lainnya untuk memecahkan masalah. Prinsip OOP ada 3, yaitu encapsulation, inheritance, serta polymorphisme. 122 more words

Geek Stuff

An Example for Thread

/*
 * Create an anonymous implementation of Runnable and then execute the Runnable Object by a Thread 
 */
public class usingThreadInJava {
	public static void main(String[] args) {		
		Runnable myRunnableClass = new Runnable() {
			public void run() {
				System.out.println("Thread from anonymous class Runnable is running");
			}
		};
		
		Thread t1 = new Thread(myRunnableClass, "Alpha Thread");
		t1.start();
		t1.run();
		System.out.println("Using Thread Object t1, Thread Name = "+t1.getName());
		
		Thread t2 = new Thread(myRunnableClass);
		t2.start();
		t2.run();
		
		System.out.println("Thread Properties for thread object t2");
		System.out.println("Id="+t2.getId());
		System.out.println("Name="+t2.getName());
		System.out.println("Priority="+t2.getPriority());
		System.out.println("Class ="+t2.getClass());
		System.out.println("State="+t2.getState());
		
		System.out.println(Thread.currentThread().getName()); // thread that is currently executing the code
	}

}
Object Oriented Programming

An Example for Anonymous Inner Class

anonymousInnerClass.java

public class anonymousInnerClass {	
	public void showQuoteMessage(greetingCard gc) {		
		System.out.println(gc.cardMessage());
	}	
	
	public static void main(String[] args) {		
		Greetings gr = new Greetings() {
			public void showMessage() {
				System.out.println("Using a Class: Hello World");
			}
		};
		gr.showMessage();	
		
		greetingCard gc = new greetingCard() {
			public String cardMessage() {
				System.out.println("Overriding Interface: Happy New Year");
				return "Merry Christmas";
			}
		};
		gc.cardMessage();		
		
		anonymousInnerClass aic = new anonymousInnerClass();
		aic.showQuoteMessage(new greetingCard() {
			public String cardMessage() {
				System.out.println("Using a Class, as a method argument: Happy New Year");
				return "Hello World";
			}
		});
	}

}
… 16 more words
Object Oriented Programming

A Java Class inside a Java Method

public class classInsideAMethod {
	
	public int methodA(final int i) {
		final class classA {
			public int methodB() {
				int j = i;
				return j+1;
			}
		}
		System.out.println(i);
		classA a = new classA();
		return a.methodB();
	}

	public static void main(String[] args) {
		classInsideAMethod imc = new classInsideAMethod();
		System.out.println(imc.methodA(11));
		System.out.println(imc.methodA(11));
		classInsideAMethod imc1 = new classInsideAMethod();
		System.out.println(imc1.methodA(11));
	}
}

OUTPUT

11
12
11
12
11
12
Object Oriented Programming