Asterisk Triangle

April 21st, 2012 § Leave a Comment

How to make output like this?

*****
*****
*****
*****
*****

Surely I hate a technical test!! but that is very easy! 2 minutes I can write these code! :p


package org.paingan.labs.logic;

public class Asterisk {
public static void main(String[] args) {
int input = 5;

for (int row = 1; row <= input; row++) {
for (int col = 1; col <= input; col++) {
if (col > (input - row)) {
System.out.print("*");
} else
System.out.print(" ");
}
System.out.println("");
}
}
}

Prime Number

April 13th, 2012 § Leave a Comment

A natural number (i.e. 1, 2, 3, 4, 5, 6, etc.) is called a prime or a prime number if it is greater than 1 and has exactly two divisors, 1 and the number itself.Natural numbers greater than 1 that are not prime are called composite. ~ wikipedia

package org.paingan.labs.logic;

public class PrimeNumber {
public static void main(String[] args) {
int limit = 10;

// loop through the numbers one by one
for (int i = 1; i < limit; i++) {

boolean isPrime = true;

// check to see if the number is prime
for (int j = 2; j < i; j++) {

if (i % j == 0) {
isPrime = false;
break;
}
}
// print the number
if (isPrime) System.out.print(i + " ");
}
}
}

Fibonacci

April 12th, 2012 § Leave a Comment

In mathematics, the Fibonacci numbers are the numbers in the following integer sequence. By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two.

F(n)= \left\{\begin{matrix}0,\\1,\\F(n-1) +F(n-2)\end{matrix}\right.\begin{matrix}\rightarrow n = 0\\\rightarrow n = 1\\\rightarrow n > 1\end{matrix}

package org.paingan.labs.logic;

public class Fibonacci {
public static long fib(int n) {
if (n < = 1) return n;
else return fib(n-1) + fib(n-2);
}

public static void main(String[] args) {
for (int i = 1; i <= 5; i++)
System.out.println(i + ": " + fib(i));
}
}

Palindrome

April 12th, 2012 § Leave a Comment

A palindrome is a word, phrase, number, or other sequence of units that can be read the same way in either direction.

package org.paingan.labs.logic;

public class Palindrome {
 public static boolean isPalindrome(String word) {
 int left  = 0; // index of leftmost unchecked char
 int right = word.length() -1; // index of the rightmost

while (left < right) { // continue until they reach center
 if (word.charAt(left) != word.charAt(right)) {
 return false; // if chars are different, finished
 }
 left++; // move left index toward the center
 right--; // move right index toward the center
 }

return true; // if finished, all chars were same
 }

public static void main(String args[]) {
 if(isPalindrome("abccba"))
 System.out.println("it's Palindrome!");
 }
 }

Property File

March 21st, 2012 § Leave a Comment

Still confused where you have to put a property files in your java project? This code for loads a property file located anywhere in your classpath.

public Properties getPropertiesFromClasspath(String propFileName)
  throws IOException {
  // loading xmlProfileGen.properties from the classpath
  Properties props = new Properties();
  InputStream inputStream = this.getClass().getClassLoader()
    .getResourceAsStream(propFileName);

  if (inputStream == null) {
    throw new FileNotFoundException("property file not found "+
      "in the classpath");
  }

  props.load(inputStream);
  return props;
}

Embedded Video vs Popup

August 23rd, 2011 § Leave a Comment

Youtube embedded video keeps hiding your JavaScript popup dialogs?? This is my solutions:

<object width="640" height="385">
    <param name="movie" value="http://www.youtube.com/v/vx2u5uUu3DE"></param>
    <param name="allowFullScreen" value="true"></param>
    <param name="allowscriptaccess" value="always"></param>
    <param name="wmode" value="opaque"></param>
    <embed src="http://www.youtube.com/v/vx2u5uUu3DE" 
         type="application/x-shockwave-flash" allowscriptaccess="always"
         allowfullscreen="true" width="640" height="385" wmode="opaque"></embed>
</object>

Java Skills..

June 2nd, 2009 § 1 Comment

Belakangan ini gue sering cari lowongan kerja. Sebentar lagi kontrak gue mau habis. Gue cari lowongan Java Developer di Jobstreet en JobsDB. Banyak sih yang buka lowongan Programmer tapi kayanya jarang perusahaan yang cari programmer java.

Gue pernah lihat lowongan yang isinya membutuhkan Java yang dibagi dengan skill-skill tertentu. Di bawah ini pembagiannya:

Java Front End Architect

Mempunyai pengalaman di Portal, Spring MVC, JSF, Velocity, Site Mesh, Tiles, dll.
Pengalaman menggunakan client-side web development technique seperti: JQuery, YUI, dll.
Pengalaman menggunakan AJAX (YUI, DWR, JSON).

Data and Persistance Specialist

Mempunyai pengalaman menggunakan Persistence seperti JPA, Eclipse Link, Hibernate, iBatis, dll.
Pengalaman menggunakan RDBMS terutama Oracle.
Pengalaman menggunakan PL/SQL di Oracle.

Services and Integration Specialist

Mempunyai pengalaman membuat Web Services.
Mengerti Business Process Management di Java.

Sebenarnya gue mempunyai pengalaman di semua skill tersebut. Tapi hanya secuil aja. Itulah jeleknya kerja di perusahaan outsourcing.. kita harus siap terjun ke project apapun dengan kondisi tertentu. Malah kadang kala kita dipaksakan menggunakan bahasa pemrograman yang berbeda yang belum pernah kita pakai sebelumnya.

Build File Ant..

March 11th, 2009 § 1 Comment

Setelah beberapa hari gue berkutat untuk membuat build.xml akhirnya gue berhasil juga ;)

Di bawah ini contoh sederhana build file buat Ant.

<?xml version="1.0" encoding="UTF-8"?>
<project name="YansenLib" default="compile" basedir=".">
	<description>simple ant</description>
	
	<property name="src.dir"     value="src"/>
    <property name="build.dir"   value="build"/>
    <property name="classes.dir" value="${build.dir}/classes"/>
    <property name="jar.dir"     value="${build.dir}/jar"/>
	
	<target name="init">
	   <tstamp/>
	   <mkdir dir="${build.dir}"/>
	</target>

    <target name="clean">
        <delete dir="build"/>
    </target>

    <target name="compile" depends="init">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}" classpath="D:/data_yansen/Library/junit-4.5.jar"/>
    </target>

    <target name="jar" depends="compile">
        <mkdir dir="${jar.dir}"/>
        <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}"/>
    </target>

    <target name="run">
        <java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
    </target>
	
    <target name="clean-build" depends="clean,jar"/>

    <target name="main" depends="clean,run"/>
</project>

BTW sudah lama yah gue ga posting tentang pemrograman. Untuk selanjutnya gue akan memposting cara membuat struts – java framework.

Akhirnya Bisa Ngeblog Juga..

October 29th, 2008 § Leave a Comment

Akhirnya.. setelah berhari-hari kantor gue kaga ada internet yang cepet.. hari ini gue bisa ngeblog lagi haha..

Gue sekarang ada di client.. masuk project baru.. gue developed aplikasi menggunakan web service.. dengan tools Hibernate, JUnit, dll.. Editor yang gue pake BEA WorkSpace Studio.. yang merupakan bundle eclipse dengan weblogic..

Di bawah ini contoh code yang gue lagi buat sekarang..

	@Test
	public void testGetProvinceList() {
		int size = 10;

		Area[] result = new AreaWS().getProvinceList("KI", size, 0);

		assertNotNull(result);
		assertTrue(result.length <= size);
		for (Area area : result) {
			assertNotNull(area.getAreaId());
			assertNotNull(area.getName());
			assertNotNull(area.getLevel());

			assertTrue(area.getLevel() == Area.PROVINCE);
			assertTrue(area.getName().length() > 0);
			assertTrue(area.getAreaId().length() > 0);
		}
	}

Potongan code diatas gue ambil dari unit test aplikasi yang dibuat untuk mengetes apakah method pada web servicenya benar atau ga..

Kantor gue sekarang di daerah Tebet.. so tiap berangkat en tebet gue harus naek dua kali bus metromini.. plus jalan kaki juga hehe.. itulah perjuangan demi sesuap nasi haha..

Karena di perusahaan gue sekarang sering ganti-ganti project.. dan gue dah lelah keluar masuk project.. kemungkinan besar habis kontrak gue bakalan cabut.. gue nyari perusahaan yang tetap.. kalau bisa deket sama kost-kostan gue sekarang hehe..

Develop..

August 11th, 2008 § Leave a Comment

Kalau gue ditanya enakan mana fixing bugs atau development.. gue lebih milih develop soalnya menurut gue kalau develop kita bisa leluasa memakai logika dan style kita saat coding sedangkan kalau fixing bugs gue harus memahami dulu logika yang buat code.. apalagi yang buat programmer expert trus yang fixing gue yang junior programmer.. ya mampus lah.. haha..

Where Am I?

You are currently browsing the Java category at Catatan si CUi...

Follow

Get every new post delivered to your Inbox.