Odoo Integration to Android

Odoo Integration to Android

Ada kesempatan lampu hijau dari pengusaha IT Consultant yang productnya bergerak di bidang open ERP Odoo.com

Setidaknya jika kerjasama ini akan terjadi merupakan goal target team saya kedepan.

Saya tidak begitu paham bahasa pemrograman Phyton, saya juga belum pernah ngoprek Android. Akan tetapi kalau ada peluang di depan mata alam bawah sadar saya mendongkrak itu semua.

Ini hasil prototype sementara

Android
 

JDK : 1.8
SDK : 2.3 ( Marsmallow )
Gradle :3.0.1
Framework : Apache WS XML RPC 3.1.3
IDE: Android Studio
Test Client Java IDE : Netbeans

Web Odoo Module Employee

Setidaknya postingan ini memberikan inspirasi buat kawan developer dan sekaligus jika ada pengusaha IT yang productnya sama seperti odoo dan belum mempunyai resources di Android atau Java, team kami siap membantu dan siap di kontrak (Legalitas on Progress).

Salam.

Spring Android RestRemplate

Spring Android RestRemplate

Salah satu rekomendasi untuk di develop, selain framework spring masih update dan bahasa perograman java juga masih up to date.

System Analyst merancang mock up seperti dibawah ini

 
Dan hasil jadi, Developer mendevelop seperti dibawah ini

 

 

 

Test with postman


Deskripsi Simple Project

IDE : Android Studio, Netbeans
JDK : 1.8
SDK : 23 Marshmallow

Methode : MVC
Backend : Native Android, Springboot
Framework: Spring Resttemplate, Spring, ect
System build : Gradle, Maven
DB : Dummy ArrayList Java

Test Client : Postman 

Simulasi Server API run di Server or Cloud > Client Android Akses dari mana saja selagi APK terinstall di device.





Contoh Spring Boot

Contoh Spring Boot Application

IDE : Netbeans 8.0
JDK : 1.8

Sturuktur Project

 



pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>co.id</groupId>
    <artifactId>Spring-Boot-Server</artifactId>
    <version>1.0-SNAPHOT</version>
    <packaging>jar</packaging>
    
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
    </parent>
    
    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>http://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>http://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
    
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Application.java
package co.id;

import javax.servlet.MultipartConfigElement;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 *
 * @author teko.sulaiman@gmail.com
 */
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
    
    MultipartConfigElement multipartConfigElement(){
        MultipartConfigFactory multipartConfigFactory = new MultipartConfigFactory();
        multipartConfigFactory.setMaxFileSize("128kb");
        multipartConfigFactory.setMaxRequestSize("128kb");
        
        return multipartConfigFactory.createMultipartConfig();
    }
    
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

HomeController.java
package co.id;

import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 *
 * @author teko.sulaiman@gmail.com
 */
@Controller
@RequestMapping("/*")
public class HomeController {
    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
    private static List<State> states;
    
    @RequestMapping(method = RequestMethod.GET)
    public String home(){
        logger.info("Spring Android Showcase");
        return "home";
    }
}

home.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head> 
    <title>Spring for Android Showcase</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    <p>Spring Boot Server it's Running ... !</p>
</body>
</html>

Output


Service Angular 2

Membuat Service di Angular 2

messages.component.ts
import { Component, OnInit } from '@angular/core';
import { MessageService } from '../message.service';

@Component({
  selector: 'app-messages',
  templateUrl: './messages.component.html',
  styleUrls: ['./messages.component.css']
})
export class MessagesComponent implements OnInit {

  constructor(public messageService: MessageService) {}

  ngOnInit() {
  }

}

messages.component.css
/* MessagesComponent's private CSSS styles */
h2 {
 color: red;
 fot-family: Arial, Helvetica, sans-serif;
 font-weight: lighter;
}

body {
 margin: 2em;
}

body, input[text], button {
 color: crimson;
 font-family: Cambria, Georgia;
}

button.clear {
  font-family: Arial;
  background-color: #eee;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  cursor: hand;
}
button:hover {
  background-color: #cfd8dc;
}
button:disabled {
  background-color: #eee;
  color: #aaa;
  cursor: auto;
}
button.clear {
  color: #888;
  margin-bottom: 12px;
}

messages.component.css
<div *ngIf="messageService.messages.length">

  <h2>Messages</h2>
  <button class="clear"
          (click)="messageService.clear()">clear</button>
  <div *ngFor='let message of messageService.messages'> {{message}} </div>

</div>

Output

Contoh Angular 2

Contoh Angular 2, kali ini saya lagi mencoba framework javascript, terbiasa Web Component, apakah kali ini bisa membuat Web Base, tentu saja pasti bisa, itu hanya masalah kebiasaan saja, yang terpenting do it.

Struktur Project : stackblitz.com/@tekosulaiman


 

index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Angular Tour Of Heroes</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>


main.ts
import './polyfills';

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';

platformBrowserDynamic().bootstrapModule(AppModule).then(ref => {
// Ensure Angular destroys itself on hot reloads.
if (window['ngRef']) {
window['ngRef'].destroy();
}
window['ngRef'] = ref;

// Otherise, log the boot error
}).catch(err => console.error(err));



polyfills.ts
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
*/

/***************************************************************************************************
* BROWSER POLYFILLS
*/

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
// import 'core-js/es6/symbol';
// import 'core-js/es6/object';
// import 'core-js/es6/function';
// import 'core-js/es6/parse-int';
// import 'core-js/es6/parse-float';
// import 'core-js/es6/number';
// import 'core-js/es6/math';
// import 'core-js/es6/string';
// import 'core-js/es6/date';
// import 'core-js/es6/array';
// import 'core-js/es6/regexp';
// import 'core-js/es6/map';
// import 'core-js/es6/weak-map';
// import 'core-js/es6/set';

/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.

/** IE10 and IE11 requires the following for the Reflect API. */
// import 'core-js/es6/reflect';


/** Evergreen browsers require these. **/
// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
import 'core-js/es7/reflect';


/**
* Required to support Web Animations `@angular/platform-browser/animations`.
* Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
**/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.



/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.



/***************************************************************************************************
* APPLICATION IMPORTS
*/


style.css
/* Add application styles & imports to this file! */

Output di Local 

 

Contoh Hello World JSF

Contoh membuat Hello World di JSF 2.

Kali ini saya akan memberikan contoh bahasa pemrograman java berbasis web dengan menggunakan web framework JSF.

Step by stepnya sebagai berikut.

Langkah pertama :
Buatlah sebuah project dengan menggunakan maven, anda bisa membuat project maven dari CMD (Windows)  atau langsung dari IDE (Netbeans, Eclipse, etc). Di tuorial ini saya menggunakan CMD. Arahkan path ke directory biasa anda membuat project java di Netbeans.


Kemudian tekan enter, jika berhasil printoutnya seperti ini


Langkah berikutnya :
Buka project maven terserbut di IDE Netbeans, maka otomatis netbeans akan mengenalinya sebagai project maven.


Langkah berikutnya:
Tambahkan syntax xml di pom.xml


<project xmlns="http://maven.apache.org/POM/4.0.0" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>co.id</groupId>
    <artifactId>Aplikasi-JSF</artifactId>
    <version>1.0-SNAPHOT</version>
    <packaging>war</packaging>
    
    <properties>
        <java.version>1.8</java.version>
        <servlet.version>3.1.0</servlet.version>
        <jsf.version>2.2.15</jsf.version>
        <primefaces.version>6.1</primefaces.version>
        <themeprimefaces.version>1.0.10</themeprimefaces.version>

        <!--appassembler-maven-plugin.version>2.0.0</appassembler-maven-plugin.version>
        <jetty-maven-plugin.version>9.4.8.v20171121</jetty-maven-plugin.version-->

        <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
        <tomcat7-maven-plugin.version>2.2</tomcat7-maven-plugin.version>
    </properties>

    <dependencies>
        <!-- Servlet -->
        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>${servlet.version}</version>
          <scope>provided</scope>
        </dependency>
        <!-- JSF -->
        <dependency>
          <groupId>com.sun.faces</groupId>
          <artifactId>jsf-api</artifactId>
          <version>${jsf.version}</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>com.sun.faces</groupId>
          <artifactId>jsf-impl</artifactId>
          <version>${jsf.version}</version>
          <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <!-- Compile java -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>           
            <!-- Run with Jetty  -->
            <!--plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <version>${appassembler-maven-plugin.version}</version>
            </plugin>    
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty-maven-plugin.version}</version>
                <configuration>
                    <webAppConfig>
                        <contextPath>/${project.artifactId}</contextPath>
                        <allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
                    </webAppConfig>
                    <scanIntervalSeconds>0</scanIntervalSeconds>
                </configuration>
            </plugin-->
            <!-- Run with Tomcat  -->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>${tomcat7-maven-plugin.version}</version>
                <configuration>
                    <path>/${project.artifactId}</path>
                </configuration>
            </plugin>     
        </plugins>
    </build>
</project>

Langkah selanjutnya tambahkan syntax di web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <!-- Define the JSF servlet (manages the request processing life cycle for JavaServer Faces) -->
    <servlet>
        <servlet-name>faces-servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Map following files to the JSF servlet -->
    <servlet-mapping>
        <servlet-name>faces-servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
  
    <!-- File(s) appended to a request for a URL that is not mapped to a web component -->
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

Langkah selanjutnya membuat index.xhtml >  Web Pages

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://xmlns.jcp.org/jsf/core">
    <head>
        <title>Hello JSF 2!</title>
    </head>
    <body>
       #{index.stringLabel}
    </body>
</html>

Langkah selanjutnya membuat Index.java > src

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class Index {
    
    private String stringLabel;

    public Index() {
        System.out.println("WelcomeBean instantiated");
        stringLabel ="Hello JSF 2";
    }

    public String getStringLabel() {
        return stringLabel;
    }

    public void setStringLabel(String stringLabel) {
        this.stringLabel = stringLabel;
    }
}

Langkah terakhir ketik perintah mvn clean install jetty:run

Outputnya

Contoh Prime Faces

Prime faces adalah web framework yang support bahasa pemrograman java, karena basis prime faces adalah JSF ( JavaServer Faces ), maka tidak akan sulit kalau anda mempelajarinya lebih lanjut.

Java 1.8
Maven 3.7.0
Tomcat 7
Prime Faces 6.1

Stuktur Program


pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>co.id</groupId>
    <artifactId>Aplikasi-Prime-Faces</artifactId>
    <version>1.0-SNAPHOT</version>
    <packaging>war</packaging>
    
    <properties>
        <java.version>1.8</java.version>
        <servlet.version>3.1.0</servlet.version>
        <jsf.version>2.2.15</jsf.version>
        <primefaces.version>6.1</primefaces.version>

        <!--appassembler-maven-plugin.version>2.0.0</appassembler-maven-plugin.version>
        <jetty-maven-plugin.version>9.4.8.v20171121</jetty-maven-plugin.version-->

        <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
        <tomcat7-maven-plugin.version>2.2</tomcat7-maven-plugin.version>
    </properties>
    
    <dependencies>
        <!-- Servlet -->
        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>${servlet.version}</version>
          <scope>provided</scope>
        </dependency>
        <!-- JSF -->
        <dependency>
          <groupId>com.sun.faces</groupId>
          <artifactId>jsf-api</artifactId>
          <version>${jsf.version}</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>com.sun.faces</groupId>
          <artifactId>jsf-impl</artifactId>
          <version>${jsf.version}</version>
          <scope>compile</scope>
        </dependency>
        <!-- PrimeFaces -->
        <dependency>
          <groupId>org.primefaces</groupId>
          <artifactId>primefaces</artifactId>
          <version>${primefaces.version}</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <!-- Compile java -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>           
            <!-- Run with Jetty  -->
            <!--plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <version>${appassembler-maven-plugin.version}</version>
            </plugin>    
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty-maven-plugin.version}</version>
                <configuration>
                    <webAppConfig>
                        <contextPath>/${project.artifactId}</contextPath>
                        <allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
                    </webAppConfig>
                    <scanIntervalSeconds>0</scanIntervalSeconds>
                </configuration>
            </plugin-->
            <!-- Run with Tomcat  -->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>${tomcat7-maven-plugin.version}</version>
                <configuration>
                    <path>/${project.artifactId}</path>
                </configuration>
            </plugin>     
        </plugins>
    </build>
</project>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <!-- Define the JSF servlet (manages the request processing life cycle for JavaServer Faces) -->
    <servlet>
        <servlet-name>faces-servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Map following files to the JSF servlet -->
    <servlet-mapping>
        <servlet-name>faces-servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
  
    <!-- File(s) appended to a request for a URL that is not mapped to a web component -->
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>


Index.java
package co.id.teko.sulaiman;

import javax.faces.bean.ManagedBean;

/**
 *
 * @author teko.sulaiman@gmail.com
 */
@ManagedBean
public class Index {
    private String string;
    
    public Index(){
        string = "Hello Prime Faces";
    }

    public String getString() {
        return string;
    }

    public void setString(String string) {
        this.string = string;
    }
}

index.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.org/ui">

    <h:head>
      <title>Contoh Prime Faces</title>
    </h:head>

    <h:body>
        <h:outputText id="display" value="#{index.string}" />
    </h:body>
</html>

Output

Contoh Array CRUD

Contoh Array Crud di Java

Stuktur Project


Main.java
import co.id.teko.sulaiman.ArrayListInit;
import co.id.teko.sulaiman.domain.Analyst;

/**
 *
 * @author teko.sulaiman@gmail.com
 */
public class Main {
     public static void main(String[] Args){
        ArrayListInit arrayListInit = new ArrayListInit();
        
        arrayListInit.getAnalysts();
        System.out.println("List");
        for(Analyst analyst : arrayListInit.getAnalysts()){
            System.out.println("ID : "+analyst.getId()+" Name : "+analyst.getName());
        }
        
        //Un-Remark salah 1 jika ingin mencoba fungsi CRUD di Array
        
        /*System.out.println();
        arrayListInit.save();
        System.out.println("After Save");
        for(Analyst analyst : arrayListInit.getAnalysts()){
            System.out.println("ID : "+analyst.getId()+" Name : "+analyst.getName());
        }*/
        
        /*System.out.println();
        arrayListInit.update();
        System.out.println("After Update");
        for(Analyst analyst : arrayListInit.getAnalysts()){
            System.out.println("ID : "+analyst.getId()+" Name : "+analyst.getName());
        }*/
        
        /*System.out.println();
        arrayListInit.delete();
        System.out.println("After Delete");
        for(Analyst analyst : arrayListInit.getAnalysts()){
            System.out.println("ID : "+analyst.getId()+" Name : "+analyst.getName());
        }*/
    }    
}

Analyst.java
package co.id.teko.sulaiman.domain;

/**
 *
 * @author teko.sulaiman@gmail.com
 */
public class Analyst {
    private int id;
    private String name;

    public Analyst(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

ArrayListInit.java
package co.id.teko.sulaiman;

import co.id.teko.sulaiman.domain.Analyst;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author teko.sulaiman@gmail.com
 */
public class ArrayListInit {
    private List<Analyst> analysts;
    
    public ArrayListInit(){
        analysts = getAllAnalysts();
    }    
    
    public void save(){
        analysts.add(new Analyst(3, "System"));
        analysts.add(new Analyst(4, "Analyst"));
    }
    
    public void update(){
        analysts.get(0).setName("Teko Analyst");
    }
    
    public void delete(){
        analysts.remove(0);
    }
    
    private List<Analyst> getAllAnalysts(){
        List<Analyst> list = new ArrayList<Analyst>();
        list.add(new Analyst(1, "Teko"));
        list.add(new Analyst(2, "Sulaiman"));
        
        return list;
    }

    //Gettter dan Setter
    public List<Analyst> getAnalysts() {
        return analysts;
    }

    public void setAnalysts(List<Analyst> analysts) {
        this.analysts = analysts;
    }
}

Output
run:
List
ID : 1 Name : Teko
ID : 2 Name : Sulaiman
Picked up _JAVA_OPTIONS: -Xmx512M
BUILD SUCCESSFUL (total time: 0 seconds)

Contoh Lambda

Contoh Lambda menggunakan java 8

Struktur Coding



 Analyst.java
 package co.id.domain.tekosulaiman;

/**
 *
 * @author teko.sulaiman@gmail.com
 */
public class Analyst {

    private int id;
    private String name;
    private int age;

    public Analyst(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

 Contoh_Sorting.java
 package co.id.tekosulaiman;

import co.id.domain.tekosulaiman.Analyst;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 *
 * @author teko.sulaiman@gmail.com
 */
public class Contoh_Sorting {
    
    private List<Analyst> analysts;
    
    public Contoh_Sorting(){
        analysts = getAllAnalysts();
        
        //Sebelum di Sorting
        System.out.println("Sebelum disorting");
        for(Analyst analyst : analysts){
            System.out.println("Umur : "+analyst.getAge()+" Nama : "+analyst.getName());
        }
        
        //Sorting
        Collections.sort(analysts, new Comparator<Analyst>(){
            @Override
            public int compare(Analyst o1, Analyst o2) {
                return o1.getAge() - o2.getAge();
            }
        });
        
        //Sesudah di Sorting
        System.out.println("Sesudah disorting");
        for(Analyst analyst : analysts){
            System.out.println("Umur : "+analyst.getAge()+" Nama : "+analyst.getName());
        }
    }
    
    private static List<Analyst> getAllAnalysts(){
        List<Analyst> list = new ArrayList<Analyst>();

        list.add(new Analyst(1, "Teko", 33));
        list.add(new Analyst(2, "Sulaiman", 20));
        list.add(new Analyst(3, "System", 10));
        list.add(new Analyst(4, "Analyst", 55));
        return list;
    }

    public static void main(String[] Args){
        new Contoh_Sorting();
    }    

    public List<Analyst> getAnalysts() {
        return analysts;
    }

    public void setAnalysts(List<Analyst> analysts) {
        this.analysts = analysts;
    }
}

 Output
 run:
 Sebelum disorting
 Umur : 33 Nama : Teko
 Umur : 20 Nama : Sulaiman
 Umur : 10 Nama : System
 Umur : 55 Nama : Analyst
 Sesudah disorting
 Umur : 10 Nama : System
 Umur : 20 Nama : Sulaiman
 Umur : 33 Nama : Teko
 Umur : 55 Nama : Analyst
 Picked up _JAVA_OPTIONS: -Xmx512M
 BUILD SUCCESSFUL (total time: 0 seconds)

Tutorial Java 8

Contoh Java 8
  1. Contoh Lambda