IITDU Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Great JOKES: JAVA OO design

3 posters

Go down

Great JOKES: JAVA OO design Empty Great JOKES: JAVA OO design

Post by BIT0112-Rokon Sun Apr 04, 2010 2:30 pm

class java{
public static void main(String[] args){
System.out.println("We all now very much familiar about Java Object oriented Design which is invented by the intelligent monkeys working at Sun Microsystems.");
}
}

by the way.. Java may seem to you a kind of joke while you are doing simple program with OOD. Okay now lets see a example;
Now Im going write a program with java as well as object oriented Design which will print a single line;
that is "Hell world";

Code:
package com.rokon;

public class HelloWorld1 {
   private String countryLang;
   private String[] hellowWorldArray = { "Hello World", "¡Hola, mundo",
         "Bonjour tout le monde", "مرحبا العالم", "नमस्ते दुनिया",
         "أهéل َلٍ êüَىï" };
   private String[] language = { "English", "Spanish", "French", "Arabic",
         "Hindi", "Greek" };

   public HelloWorld1(String countryLang) {
      this.countryLang = countryLang;
   }

   public String toString() {
      if (countryLang.equalsIgnoreCase(language[0]))
         return hellowWorldArray[0];
      else if (countryLang.equalsIgnoreCase(language[1]))
         return hellowWorldArray[1];
      else if (countryLang.equalsIgnoreCase(language[2]))
         return hellowWorldArray[2];
      else if (countryLang.equalsIgnoreCase(language[3]))
         return hellowWorldArray[3];
      else if (countryLang.equalsIgnoreCase(language[4]))
         return hellowWorldArray[4];
      else if (countryLang.equalsIgnoreCase(language[5]))
         return hellowWorldArray[5];
      else
         return "nothing found";
   }
}
Here is a class contain two array and one of them holds "hello world" in different language and other holds language name; another is a string variable named countryLan holds the language Name specified with the users;
and here is method name toString who is responsible for returning the Helloworld for the specified language;

Now lets write a another class named HelloWorldContstructor whose works is to consctruct Hello world;

Code:
package com.rokon;

public class HelloWorldContstructor {
   private HelloWorld1 theHeloWorld;

   public HelloWorldContstructor(String conLen) {
      theHeloWorld = new HelloWorld1(conLen);
   }

   public String toString() {
      return theHeloWorld.toString();
   }
}
Here we initialise the Helloword1 as theHelloworld and inject its value using constructor;


Now we'll write our main class. I named it HelloWorldMain;

Code:
package com.rokon;

public class HelloWorldMain {
   public static void main(String[] args) {
      try {
         HelloWorldContstructor tHWC = new HelloWorldContstructor(args[0]);
      } catch (ArrayIndexOutOfBoundsException e) {
         e.printStackTrace();
      }
   }
}


Here is main method. now If we run this program and wirte arabic in command Line.. it will print مرحبا العالم ;

Nice Jokes... to write simple Hello world we need 55 line code in object oriented desingn... ;
where we can write simple Hello World program in C with simple 4 line coding .. lets see some other Hello World program with various programming language;


In C
#include
int main(void) {
puts("Hello, World!");
}

In C++
#include
int main(void) {
std::cout << "Hello, World!\n";
}
In python and perl

print "Hello, World!"
In ruby
puts "Hello, World!"


Okay now We will see the loose coupling of java I mean object oriented design;
I know we everybody are very much familer on this because we already know the
spring framework ..;

Loose couping is a designing issue. Couping issuse comes when an object is dependent on others;
When an obeject cant work without another, we will say that they are tightly coupled;
But when two object can work independently, we will refer them loose coupled. More precisely, for say, A object is dependent on B. But somehow B become changed., so We need to change the A. But if the system is loose coupled then there is no need to change A. It will continue to work without modification.

Now see the example -
Code:
package com.rokon.loosecoupling;

public class Message {
   private String message;

   Message(String message) {
      this.message = message;
   }

   public void pirnt(Printer printer) {
      printer.print(this);
   }

   public String toString() {
      return message;
   }
}
Code:
package com.rokon.loosecoupling;

public interface Printer {
   void print(Message message);
}
Code:

package com.rokon.loosecoupling;

public abstract class AbstractPrinterFactory {
   public static AbstractPrinterFactory getFactory() {
      return new SystemOutPrinterFactory();
   }

   public abstract Printer getPrinter();
}
Code:
package com.rokon.loosecoupling;

public class SystemOutPrinterFactory extends AbstractPrinterFactory {
   public Printer getPrinter() {
      return new SystemOutPrinter();
   }
}

Code:
package com.rokon.loosecoupling;

public class HelloWorld {
   public static void main(String[] args) {
      Message message = new Message("Hello World");
      AbstractPrinterFactory factory = SystemOutPrinterFactory.getFactory();
      Printer printer = factory.getPrinter();
      message.pirnt(printer);
   }
}

and if you run it, output remain same as before and that is "Hello World";

if you need source code CLICK HERE

For more about it, I suggest you to google it. Im very much sure you'll enjoy tons of information about OOD of java..

Cheers


Last edited by bit0112-rokon on Sun Apr 04, 2010 2:44 pm; edited 4 times in total (Reason for editing : TLD used)
BIT0112-Rokon
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

http://blog.codexplo.org

Back to top Go down

Great JOKES: JAVA OO design Empty Re: Great JOKES: JAVA OO design

Post by BIT0105-kanak Sun Apr 04, 2010 2:57 pm

valo laglo.
BIT0105-kanak
BIT0105-kanak
Alpha Release
Alpha Release

Posts : 46
Points : 68

http://mitaly.webs.com

Back to top Go down

Great JOKES: JAVA OO design Empty Re: Great JOKES: JAVA OO design

Post by BIT0122-Amit Sun Apr 04, 2010 5:01 pm

babago Neutral
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

Great JOKES: JAVA OO design Empty Re: Great JOKES: JAVA OO design

Post by BIT0112-Rokon Mon Apr 05, 2010 11:16 am

Kanak ki valo lagce..? java'r object oriented design..?
BIT0112-Rokon
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

http://blog.codexplo.org

Back to top Go down

Great JOKES: JAVA OO design Empty Re: Great JOKES: JAVA OO design

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum