Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hello World Enterprise Edition
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
public class HelloWorld{
private static HelloWorld instance;
public static void main(String[] args){
instantiateHelloWorldMainClassAndRun();
}
public static void instantiateHelloWorldMainClassAndRun(){
instance = new HelloWorld();
}
public HelloWorld(){
HelloWorldFactory factory = HelloWorldFactory.getInstance();
IHelloWorld helloWorld = factory.createHelloWorld();
IHelloWorldString helloWorldString = helloWorld.getHelloWorld();
IPrintStrategy printStrategy = helloWorld.getPrintStrategy();
IStatusCode code = helloWorld.print(printStrategy, helloWorldString);
if(code.getStatusCode() != 0){
throw new RuntimeException("Failed to print: " + code.getStatusCode());
}
}
}
class StringFactory{
private static StringFactory instance = new StringFactory();
public static StringFactory getInstance(){
return instance;
}
public HelloWorldString createHelloWorldString(String str){
HelloWorldString s = new HelloWorldString();
s.s = str;
return s;
}
}
class PrintStrategyFactory{
private static PrintStrategyFactory instance = new PrintStrategyFactory();
public static PrintStrategyFactory getInstance(){
return instance;
}
public IPrintStrategy createIPrintStrategy(){
IPrintStrategy printStrategy = new PrintStrategyImplementation();
IStatusCode code = printStrategy.setupPrinting();
if(code.getStatusCode() != 0){
throw new RuntimeException("Failed to create IPrintStrategy: " + code.getStatusCode());
}
return printStrategy;
}
}
class PrintStrategyImplementation implements IPrintStrategy{
private OutputStream print;
public IStatusCode setupPrinting() {
try{
FileDescriptor descriptor = FileDescriptor.out;
print = new FileOutputStream(descriptor);
return new StatusCodeImplementation(0);
}
catch(Exception e){
return new StatusCodeImplementation(-1);
}
}
public IStatusCode print(IHelloWorldString string) {
try{
print.write(string.getHelloWorldString().getHelloWorldString().concat("\n").getBytes("UTF-8"));
return new StatusCodeImplementation(0);
}
catch(Exception e){
return new StatusCodeImplementation(-1);
}
}
}
class StatusCodeImplementation implements IStatusCode{
private int code;
public StatusCodeImplementation(int code){
this.code = code;
}
public int getStatusCode() {
return code;
}
}
class HelloWorldString{
String s;
public String getHelloWorldString(){
return s;
}
}
class HelloWorldStringImplementation implements IHelloWorldString{
public HelloWorldString getHelloWorldString(){
StringFactory factory = StringFactory.getInstance();
HelloWorldString s = factory.createHelloWorldString("Hello, World!");
return s;
}
}
class HelloWorldFactory{
private static HelloWorldFactory instance = new HelloWorldFactory();
public static HelloWorldFactory getInstance(){
return instance;
}
public IHelloWorld createHelloWorld(){
IHelloWorld helloWorld = new HelloWorldImplementation();
return helloWorld;
}
}
class HelloWorldImplementation implements IHelloWorld{
public IHelloWorldString getHelloWorld() {
IHelloWorldString string = new HelloWorldStringImplementation();
return string;
}
public IPrintStrategy getPrintStrategy() {
PrintStrategyFactory factory = PrintStrategyFactory.getInstance();
return factory.createIPrintStrategy();
}
public IStatusCode print(IPrintStrategy strategy, IHelloWorldString toPrint) {
IStatusCode code = strategy.print(toPrint);
return code;
}
}
interface IHelloWorldString{
public HelloWorldString getHelloWorldString();
}
interface IHelloWorld{
public IHelloWorldString getHelloWorld();
public IPrintStrategy getPrintStrategy();
public IStatusCode print(IPrintStrategy strategy, IHelloWorldString toPrint);
}
interface IStatusCode{
public int getStatusCode();
}
interface IPrintStrategy{
public IStatusCode setupPrinting();
public IStatusCode print(IHelloWorldString string);
}
@lolzballs

This comment has been minimized.

Copy link
Owner Author

lolzballs commented Apr 6, 2015

👍

@lolzballs

This comment has been minimized.

Copy link
Owner Author

lolzballs commented Apr 6, 2015

Needs more XML and JSON

@danderson00

This comment has been minimized.

Copy link

danderson00 commented Oct 2, 2015

Totally needs XMLDoc. No good enterprise project contains more code than XML documentation.

@schipplock

This comment has been minimized.

Copy link

schipplock commented Dec 17, 2015

There's not even a queue nor a single annotation :P. But still nice :).

@rapgro

This comment has been minimized.

Copy link

rapgro commented Dec 17, 2015

Better calculate the printed string in line #101 and read it from the back on.

@rapgro

This comment has been minimized.

Copy link

rapgro commented Dec 17, 2015

No java 8 features, like closure (okay, also compatible with java 7).

@rpip

This comment has been minimized.

Copy link

rpip commented May 21, 2016

LOL

@sivaprasadreddy

This comment has been minimized.

Copy link

sivaprasadreddy commented Jul 21, 2016

We are Spring fans. We just use @EnableHelloWorldProxyFactoryBeanProviderStrategy :-)

@TiBeN

This comment has been minimized.

Copy link

TiBeN commented Jul 21, 2016

Where is the instance of AbstractApplicationContextProviderRepositoryManagerAdapter ?

@cooervo

This comment has been minimized.

Copy link

cooervo commented Jul 21, 2016

No FactoryBuilderFacadeAdapterComposite? Doesn't pass

@egeshi

This comment has been minimized.

Copy link

egeshi commented Jul 25, 2016

Guys, is this really a HelloWorld? What went so wrong?

@jenyaza01

This comment has been minimized.

Copy link

jenyaza01 commented Jul 25, 2016

WHAT?
best hello world :)

@tonyshkurenko

This comment has been minimized.

Copy link

tonyshkurenko commented Jul 25, 2016

Too much singletons

@jacqueskang

This comment has been minimized.

Copy link

jacqueskang commented Jul 26, 2016

Lol no test?

@Intey

This comment has been minimized.

Copy link

Intey commented Jul 26, 2016

[sarcasm] As a gist? not serious. Also good to convert each comment to issue it task-manager. [/sarcasm]

@tobias-nitsche

This comment has been minimized.

Copy link

tobias-nitsche commented Aug 24, 2016

Do you have a Symfony Bundle for it?

@ollyjshaw

This comment has been minimized.

Copy link

ollyjshaw commented Oct 16, 2016

I'd like to see more of it taken out and put into libraries.

@mnmtanish

This comment has been minimized.

Copy link

mnmtanish commented Oct 17, 2016

I love what you did there with bad indentations and the line break. We really need some commented code and just more comments.

@roskenet

This comment has been minimized.

Copy link

roskenet commented Oct 17, 2016

The Factories have duplicated code (getInstance). You should definitely refactor extending an abstract base class using generics!

@eduardocl

This comment has been minimized.

Copy link

eduardocl commented Oct 17, 2016

Java....

@ujasur

This comment has been minimized.

Copy link

ujasur commented Oct 17, 2016

Forgot to create constants for status codes

@Sircheese

This comment has been minimized.

Copy link

Sircheese commented Oct 18, 2016

Why in one thread?

@BerkOzdilek

This comment has been minimized.

Copy link

BerkOzdilek commented Oct 19, 2016

nice one

@ColCh

This comment has been minimized.

Copy link

ColCh commented Oct 19, 2016

brilliant

@pabloorellana

This comment has been minimized.

Copy link

pabloorellana commented Oct 20, 2016

it is 2016, let's split this into microservices...

@dasMulli

This comment has been minimized.

Copy link

dasMulli commented Oct 27, 2016

The code calls new StatusCodeImplementation very often. This is a hardcoded dependency and should be de-coupled via a factory interface.

@bitsnaps

This comment has been minimized.

Copy link

bitsnaps commented Oct 27, 2016

Is it thread safe!!

@regiveerhuis

This comment has been minimized.

Copy link

regiveerhuis commented Nov 1, 2016

You should make the constructors of the singletons private, and the eager instantiation of the instance is debatable as well

@jeernest

This comment has been minimized.

Copy link

jeernest commented Nov 16, 2016

I found the string finally, it's on line 101

@Davidj361

This comment has been minimized.

Copy link

Davidj361 commented Dec 7, 2016

10/10 design, would hire

@beshur

This comment has been minimized.

Copy link

beshur commented Dec 15, 2016

Missing comments )

@ghost

This comment has been minimized.

Copy link

ghost commented Dec 17, 2016

yes =))

@Mart-Bogdan

This comment has been minimized.

Copy link

Mart-Bogdan commented Dec 30, 2016

Wait, it has logic in constructor! That's bad practices.

@silencieuxle

This comment has been minimized.

Copy link

silencieuxle commented Jan 10, 2017

Beginners like me will shout: "WHAT THE FUCK IS THIS?" lol.

@Blahartinger

This comment has been minimized.

Copy link

Blahartinger commented Mar 1, 2017

Where is the SOAP?

@8bitStrawberry

This comment has been minimized.

Copy link

8bitStrawberry commented Mar 2, 2017

I think I'm braindead. I should know this. But everything looks like squiggles.
Also, coding is like Wizardry. You're a wizard, Harry.

@foofoodog

This comment has been minimized.

Copy link

foofoodog commented Mar 14, 2017

The super optimizing recursive compiler I use dumps this out as 20 bytes of machine code dynamically linked.

@kaidokert

This comment has been minimized.

Copy link

kaidokert commented Apr 8, 2017

  • no internationalization, not ready from product perspective
  • devops will reject, no environment variables
  • potential vulnerability on line 71 due to unpatched JVMs in the wild, security blocks the release
@beeetooo

This comment has been minimized.

Copy link

beeetooo commented Jul 8, 2017

  1. No TDD
  2. Too few abstractions and design patterns
  3. Only applies the S and D of SOLID.
@JoeReis

This comment has been minimized.

Copy link

JoeReis commented Jul 9, 2017

I’m gonna need you to come in on Saturday

@calvincodes

This comment has been minimized.

Copy link

calvincodes commented Jul 10, 2017

Wish this is how they would have taught "Hello World" in my CS101 course! ;)

@vpiotr

This comment has been minimized.

Copy link

vpiotr commented Aug 21, 2017

Try to read the text from JDBC mapping connected using JNDI url stored in environment properties. If property not available try to load class implementing "JDBCConfiguration" interface using current class loader and execute it's private method "getDBUrl()". If class not available log a message on DEBUG level and skip the processing (do not print anything).

@Cyan101

This comment has been minimized.

Copy link

Cyan101 commented Aug 27, 2017

Needs documentation

@Gorczu

This comment has been minimized.

Copy link

Gorczu commented Oct 13, 2017

There should be some DI container

@iczero

This comment has been minimized.

Copy link

iczero commented Nov 27, 2017

We still need a HelloWorldFactoryFactoryFactory

@sebbekarlsson

This comment has been minimized.

Copy link

sebbekarlsson commented Dec 5, 2017

Can't really find where you get that "Hello World" string from, but I will just assume that it's coming from a HUGE XML file somewhere on your NTFS file system.

@byrro

This comment has been minimized.

Copy link

byrro commented Dec 6, 2017

Know what, you nailed it! Thanks so much for lots of laughs

@devTomek

This comment has been minimized.

Copy link

devTomek commented Dec 14, 2017

Forgot the meaning of greeting? :P

@kouddy

This comment has been minimized.

Copy link

kouddy commented Feb 8, 2018

Currently code coverage rate is too low. Please include unit tests as well. 80% code coverage is required as per our Director of Engineering.

@hrpatel

This comment has been minimized.

Copy link

hrpatel commented Feb 22, 2018

Ship it!

@adityasrini

This comment has been minimized.

Copy link

adityasrini commented Mar 6, 2018

It's 2018. Where are the REST endpoints? Also, no one has mentioned the lack of a docker file.

@minh-dai

This comment has been minimized.

Copy link

minh-dai commented May 4, 2018

i am beginner. best hello world :v

@srandawa

This comment has been minimized.

Copy link

srandawa commented Jun 7, 2018

No JMX? Can this truly be "enterprise"? How can this be monitored for performance?

@BubenIvanov

This comment has been minimized.

Copy link

BubenIvanov commented Jul 30, 2018

Bad packages structure, no docs , no REST endpoints, no constants for strings but i love it <3

@kujon

This comment has been minimized.

Copy link

kujon commented Aug 4, 2018

Do you think it's gonna autowire itself?!

@johanvergeer

This comment has been minimized.

Copy link

johanvergeer commented Jan 21, 2019

Where is J2EE? Where is Dependency Injection? Seriously.

But for real, you took this way further than I would have... Thanks man

@Miha-x64

This comment has been minimized.

Copy link

Miha-x64 commented Jan 24, 2019

Your StringFactory should use lazy double-check-locking with broken initialization of non-volatile instance variable.

@markozajc

This comment has been minimized.

Copy link

markozajc commented Jan 29, 2019

Needs a JUnit test for every method, otherwise +1.

@SenkoLS

This comment has been minimized.

Copy link

SenkoLS commented Feb 20, 2019

WTF?!?!?!?

Where is JavaDoc?

@amarao

This comment has been minimized.

Copy link

amarao commented Feb 22, 2019

We've tried to expand our business into EMEA but our attempts were failed by absolute lack of i18n support in our key HelloWorld product. Please, add support for code pages, i18n and l18n.

@ValentinDrazdov

This comment has been minimized.

Copy link

ValentinDrazdov commented Feb 22, 2019

It's better to use ENUMs than just return integer code of error :-)

@plechev

This comment has been minimized.

Copy link

plechev commented Mar 14, 2019

Code written 4 years ago and: (1) still with only one revision, (2) has not been deleted. What better proof of great and lasting design?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.