piątek, 28 grudnia 2012

Java IO interview questions

  1. What is Java Streams
    • Briefly: Java IO streams are flows of data you can either read from, or write to.  Streams are typically connected to a data source or data destination like a file, network connection. In Java streams are typically byte based. When you have to write component that needs to read input from a stream you can use InputStream (or one of its subclasses e.g. FileInputStream). Whereas when you have to write component that needs to write output to a stream you can use OutputStream (or one of its subclasses e.g. FileOutputStream). 
    • I had the opportunity to use Java IO streams in small projects during my studies, when I had to read/write not large amount of data. But recently at work I have implemented solution consisted of saving all the data coming from trading system to a file. That data related to the current date only. I have tested solution based on the use of Java IO Streams and Java NIO Buffers and I have found that Java NIO Buffers can do the same job up to ten times faster.  
  2. What is Reader and Writer in Java IO
    • Briefly: Java IO's readers and writers work much like InputStrem and OutputStream with the exception that Readers and Writers are characted based. They are intended for reading and writing text. 
    • I used Readers and Writers only in small projects during my studies. 
  3. Which of them is byte base and which is char based
    • Streams are byte based whereas Readers and Writers are char based
  4. NIO and IO
  5. Reading and writing text file in Java
  6. Creating file and Directory in Java
  7. Memory Mapped File in Java

wtorek, 9 października 2012

Some examples from my daily tasks part 1


I have to design and implement mechanism which handle such situation:
There are two applications, let's say App1 and App2 and OpenMQ Broker between those applications. Furthermore there are two queues on this Broker - ControlQueue and DataQueue.
Under normal conditions (when both App1 and App2 are alive) App1 sends some real time data to DataQueue and App2 receives that data. App1 caches data and has a refresh functionality in case App2 need to update all data.


  1. App2 to maintain connection every ten seconds sends PING message to ControlQueue. 
  2. App1 receives PING messages from ControlQueue and saves the time of last PING message.
  3. Every time App1 receives PING message it checks if data is sending to DataQueue. If not, it launches refresh and send cached and real time data to DataQueue. 
  4. App1 (by QueueConectionMaintainer) checks every ten seconds if time of last PING message is later than 25 seconds and if yes then it stop sending data to DataQueue. 
App1 is created with Spring Integration and use jms:inbound-channel-adapter to receive messages from ControlQueue. 

Ad.1.
 PING message is a jms object message with Properties object inside
Ad.2, Ad.3
Connection with OpenMQ - Spring Integration configuration:


Connection factory decorator:


Queue listener - Spring Integration configuration:

ControlQueueListenerActivator implementation:

Ad.4 Queue connection maintainer - Spring Integration configuration: QueueConnectionMantainer implementation:

czwartek, 4 października 2012

Into the Effective Java part. 1

Using static factory methods instead of constructors. *
 Advantages:

  • Unlike constructors they have names. 
If the parameters to a constructor do not, in and of themselves, describe the object being returned, a static factory with a well-chosen name is easier to use and the resulting client code easier to read.
  • They are not required to create a new object each time they're invoked. 
The ability of static factory methods to return the same object from repeated invocations allows classes to maintain strict control over what instances exist at any time.
  • They can return an object of any subtype of their return type. 
This gives you great flexibility in choosing the class of the returned object.
  • They reduce the verbosity of creating parameterized type instances.  
Unfortunately, you must specify the type parameters when you invoke the constructor of a parameterized class even if they’re obvious from context.
With static factory methods instead of doing: 


You can implement:

Then you could replace the wordy declaration above with this succinct alternative:

Disadvantages:
  • The main disadvantage of providing only static factory methods is that classes without public or protected constructors cannot be subclassed.
  • A second disadvantage of static factory methods is that they are not readily distinguishable from other static methods.
They do not stand out in API documentation in the way that constructors do, so it can be difficult to figure out how to instantiate a class that provides static factory methods instead of constructors.


* Effective Java Second Edition, Joshua Bloch

poniedziałek, 1 października 2012

Into the Spring part 1

How does spring simplify Java development?
Key strategies:

    • Lightweight and minimally invasive development with plain old Java objects (POJOs)
    • Loose coupling through dependency injection and interface orientation
    • Declarative programming  through aspects and common conventions 
    • Boilerplate reduction through aspects and templates
Almost everything Spring does can be traced back to one or more of these four strategies*. 





*Spring in Action 3rd edition, Craig Walls

czwartek, 27 września 2012

My portfolio

1. Brokerage system for Bank A
 - Implementation of module to call remote, transactional system’s web-services using SOAP 1.1 protocol and WSDL based interfaces. Creating data contract between a service and a client.
 - Implementation of monitor core module to asynchronous communication with a transactional system.
 - Working with data access, business and presentation layers.
JMS 1.1, EJB 3.0, JAXB 2.0, JAXWS 2.1, Weblogic 10.0 SP1,SVN

2. Internet Investments system for Bank B.
 - Service, technical support and CR implementation
JDK 1.5, JAVA Servlet API, AJAX, viBank Templates, CVS

3. Client system for Bank A
- Working with presentation layer for brokerage part of the system. Client side development.
JDK 1.5, Spring Portlet MVC, jQuery,SVN

4. Brokerage system for Bank C
- Implementation of module to call remote, transactional system’s web-services using SOAP 1.1 protocol and WSDL based interfaces. Creating data contract between a service and a client.
JAXB 2.0, JAXWS 2.1,JBossWS

5. Central Brokerage system for Bank C
- Design, implementation of web-services
JDK 1.6, Gigaspace 7/8 XAP In-Memory Data Grid, Spring 3.0, Groovy, EJB 3.0, JMS 1.1, JAXWS 2.1, Hibernate 3.3,SVN,TestNG,

6. XDP protocol based, quotation system for rapid market data distribution (http://www.nyse.com) for Bank C
- Implementation of XDP adapter module.
Spring Integration, Spring Dynamic Modules,  OSGi R4.,  SVN,  XDP financial protocol

So let's get started...

First blog - first post.
I am a Java programmer with a pretty good experience and expertise in a many interesting projects.
So why still Java Layman?  Beacuse I think that I still don't have enough knowledge. In my job - I was always the man of everything. I mean I was doing everything with "yesterday" as a deadline witch unfortunately meant that I learned only this part of the technology that I needed. And now, I have 3 - year experience and huge gaps in my theoretical knowledge. Starting today - I am going to eliminate them.
My dream: Senior Java Developer in London
My problems to solve: Gaps in theoretical knowledge, poor English speaking.