A software specification is a fundamental work product that represents user’s requirements and developers can use it to further develop a software system. A software specification can be expressed by using an informal, a semi-formal, or a formal specification. Existing methodologies and tools can transform semi-formal specifications to code or programs but they have not addressed a transformation of formal specification languages. In this paper, we propose an automatic approach to transform CafeOBJ specifications to Java template code. The proposed approach consists of steps and transformation rules. We have implemented a tool called Cafe2Java to illustrate our proposed approach. We also validate the approach and experience the tool with some CafeOBJ specifications.