How to read a parameter from properties file by shell script ?

I used ‘source’ syntax to called the parameter from property file.

1. create your directory on your linux OS environment.
– this <mydir> you need to change.

/<mydir>/call_dir/
call_dir.sh
/<mydir>/call_dir/config/
config.properties

/<mydir>/call_dir/logs/
log.txt

2. source bash file – ‘ call_dir.sh ‘

base_dir=/mydir/call_dir
config_dir=${base_dir}/config

# use source command to read the parameter key in properties
if [ -f ${config_dir}/config.properties ];then
source ${config_dir}/config.properties
else
MESSAGE=”Script END”
echo “$MESSAGE”
fi
echo “Log directory $LOG_DIR”

3. properties file config.properties
– values:
LOG_DIR=<mydir>/logs/logs.txt
Terima kasih,
Tubek blog ti…

Thread in Java.

1. What is Thread?
 1.a. Thread is a Light-weight ,its allow multiple activities within a single process.
 1.b. All treads of a process share the common memory space, The process of execution multiple threads simultaneously is known as multi-threading.

2. Non-Thread Program vs Thread Program

2.a. Example Non-Thread Program.

public class WithoutThread {

 // main method
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  String str = “banana”;
  String str2 = “papaya”;
  
  ProcessClass proStr = new ProcessClass();
  proStr.IterateRandomValue(str);
  proStr.IterateRandomValue(str2);
}
}
class ProcessClass{
 public void IterateRandomValue(String itr){
  for (int i = 0; i < 5; i++) {
    System.out.println(i + ” ” + itr );
  }
   }
 }

OUTPUT in Console:
0 banana
1 banana
2 banana
3 banana
4 banana
0 papaya
1 papaya
2 papaya
3 papaya
4 papaya

Descriptions on without Thread class : without added thread class, it will execute the process one by one ( check the output program above, program banana will run first until its finish, and then, papaya program will be run ) – sequentially. the Process will taking longer time to finish the processing compare than extends Thread class or implements Runnable class.

2.b. Thread Program.

  • the Functions of Java Threads is to allow multiple activities within a single process.
  • To implement The Threads function we need to extends Thread Class or Implements Interface Runnable Class.

Example Program extend Thread class.

public class ThreadExample {
 //Main Thread
    public static void main(String[] args)
    {
     // TODO Auto-generated method stub
     String str = “banana”;
     String str2 = “papaya”;
     
     // First Thread
     ExtendThread firstThread = new ExtendThread(str);
     firstThread.start();
     
        //Second Tread
     ExtendThread secondThread = new ExtendThread(str2);
     secondThread.start();
    }

}

class ExtendThread extends Thread
{
 private String strNew;

 ExtendThread(String str) {
  strNew = new String(str);
 }

 @Override
 public void run() {
  for (int i = 0; i < 5; i++) {
   System.out.println(i + ” ” + strNew);
  }

 }
}

Output:
Starting Banana
Creating ..Papaya
Starting Papaya
Running..Banana
Thread : Banana,4
Running..Papaya
Thread : Papaya,4
Thread : Banana,3
Thread : Papaya,3
Thread : Banana,2
Thread : Papaya,2
Thread : Banana,1
Thread : Papaya,1

  • If we see the results for (papaya,1) and (Banana, 1) its actually run simultaneously
  • How to Use ServletOutputStream – for Servlet Download zip file into response Client?

    Good Day!

    How to Use ServletOutputStream – for Servlet Download zip file into response Client?

    Description / Answer:

    • from the tomcat.apache.org lib descriptions – Provides an output stream for sending binary data to the client.
    • is an abstract class that the servlet container implements. Subclasses of this class must implement the java.io.OutputStream.write(int) method.
    • method that are regularly used are : .write() – writing what the client request and paste to servlet response client.
    • Its use to attached the Output Stream to download on browser.

    example program – Servlet Class :

    ServletOutputStream servletOutputStream = null;
    FileInputStream fileInputStream = null;
    filename = “documentInput.Zip“;

    try {
    File file = new File(“C://documents/temp/tempfile.zip“);
    fileInputStream = new FileInputStream(file);
    servletOutputStream = response.getOutputStream();

    // download using browser client – change to byte
    response.setContentType(“application/zip“);
    response.setContentLength((int)f.length());
    response.addHeader(“Content-Disposition“,”attachment;filename=\“” + filename + “\””);
    byte[] arBytes = new byte[32768];

    int count;
    while ((count = fileInputStream.read(arBytes)) > 0)
    {
    servletOutputStream.write(arBytes, 0, count);
    }

    }catch (IException e) {
    // TODO: handle exception
    } finally{
    servletOutputStream.flush();
    fileInputStream.close();
    }

    How to add compare function in Notepad++

    Hi Good Day , 你好! , Anih Agah , Nama rita Nuan,

    How to add compare function in Notepad++

    1. Open your Notepad++ , then go to menu Tab on the Top, Plugin Manager > Show Plugin Manager , Search for compare.

    1

    2. Tick the compare option, click Install – & Yes if you want to Update , or No if you don’t want to update your Notepad++.

    2

    3. After done Installed the plugin, then you can open your two files you want to compare, then at the first file – go to Tab and click Plugins > Compare > Compare (click it) or shorcut key – CTRL+ALT + C,

    3.jpg

    4. Above image show comparison between two files source codes. with + green show there are new line , and – minus is empty. 

    5. If you guys using notepad ++ v.7.3.3 , its doesn’t have any top tab plugins, so what you must do is, install manually.

    on your Directory installer : Notepad++\plugins

    create your folder such as \config

    then download this notepad compare plugin from Github. add this downloaded files to Notepad++\plugins\config\

    fndong_notepadplus_1

    After that, go to notepad++ application, click on ( Settings > import > import Plugin(s).. ) the go plugin directory and get the comparePlugin.dll.

    Then you can use the comparator plugin. 

    Selamat Mencuba , Good Luck !

     

     

     

     

    Create a Provider Web Service and Web Service Client (JAX-WS) + Apache Tomcat

    Create a Provider Web Service and Web Service Client (JAX-WS) + Apache Tomcat

    1). Open Eclipse, Create Dynamic Project ( WebServiceWSDL ), choose server tomcat, Next and Finish.

    4webServices.jpg

    2). Set the package – com.fndong.ws – in the /src. Create java Class – CalculateAdditional.java

    package com.fndong.ws;
    
    public class CalculateAdditional {
        public double addtheValues(double firstnumber, double secondnumber ) {
           double plus = firstnumber + secondnumber;
           return plus;
    
        }
     
    }

    3). Right Click on file CalculateAdditional.java -> Web Services -> Create Web Service

    6webServices.jpg

    • First configuration : select start service
    • Second Configuration : select Test Client
    • Tick the Checkbox true (Publish the Web Service & Monitor the web Service)

    Click Finish.

    4). Then it will created the sub project folder for web service client testing “WebServicesWSDLClient“.

    calculate.jpg

    5). Run on Tomcat – for run web service client test .

    webserviceclienttest.jpg

    SELAMAT MENCUBA!

    Adding the IBM MobilFirst SDK to Android Application – Hello World

    Good Day! & Happy New Year 2017 Gregorian Calendar

    1.) Create New Project in Android Studio. Select File > New Project.

    2.) Enter new Project, add the name for the project with the name of the package, example:

    New Project name : MyApp

    company domain : com.fndong.myApp

    3.) Then After created, adding the SDK into android MyApp Application.

    3.1) Add the sdk plugin mobilefirst android in build.gradle (Module:App).

    apply plugin: 'com.android.application'
    repositories{
        jcenter()
    }
    android {
        compileSdkVersion 23
        buildToolsVersion "25.0.2"
    
        packagingOptions {
            pickFirst 'META-INF/ASL2.0'
            pickFirst 'META-INF/LICENSE'
            pickFirst 'META-INF/NOTICE'
        }
    
        defaultConfig {
            applicationId "myapp.com.fndong.myapp"
            minSdkVersion 22
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile 'com.ibm.mobile.foundation:ibmmobilefirstplatformfoundation:8.0.+'
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.4.0'
    }

    4.) Add the Permission and the Mobilefist UI activity in the AndroidManifest.xml.

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    • add inside tag <application…>
    <activity android:name="com.worklight.wlclient.ui.UIActivity" />

    5.) Running emulator – just go here android_page

    6.) Go to Run – app / (Shift+ F10) – then it will show your first Mobile App with Mobilefist SDK for Android.

    android_mobilefist.jpg

    7. Add the registration of the application with mobilefirst server – and add the mfpclient.properties

    • using node.js prompt – set this command : mfpdev app register (must run the mobilefirst Foundation server 8.0 – for console first)

    Android App – android studio – Create my Hello World!

    Good Day!

    Android App – android studio – Create my Hello World!

    Today – 21/12/2016, after a long time doing web development , its time to learn new thing , here is my experience starting create Hello World Android App using Android studio.

    1). Download the Android studio bundle

    2) Installed it, and please follow the right prerequisites.

    3). Open Android studio, select File > New Project.

    • application name: MyFirstAndroid
    • company domain: com.fndong.myapp

    1.jpg

    4.) Click Next > In the Target Android Devices screen, i Choose SDK “API 22: Android 5.1(lolipop)” and click Next.

    2.jpg

    5) create the activity, choose Empty Activity and Next.

    6). Then , just leave as default MainActivity (Class Name), Click Finnish

    4

    7) Run the Application. Run on Emulator.

    • Just selecting Tools > Android > AVD Manager , In the Your Virtual Devices screen, click Create Virtual Device. Then you can choose any hardware you want. I choose Nexus 6.
    • On the Run image, click and select deployment target, then click Ok.

    5.jpg

    Create the adapter application for MobileFirst Project

    Create the adapter application for MobileFirst Project :

    1.) For my Testing purpose, I’ll using example Helloworld Adapter from localhost console.

    adapter1.jpg

    3.) Then get the zip file and unzip it to your project workspace. To build it using Maven command:  mvn install

    4) To deploy on Console Mobilefirst just upload using Console mobileFirst. ( Select the adapter from /target , and get file *.adapter)

    deployadapter1.jpg

    5.) Testing Adapter

    https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/adapters/testing-and-debugging-adapters/

    6) using Swagger for testing adapter.

    swagger.jpg

    swagger2.jpg

     

    7) Using Existing Source Code Adapter, To import the source code using Eclipse Mars 2, inside eclipse , right click > import > Maven > Existing Maven Projects > Root directory > Browse your location project.

    eclipse_adapter1.jpg

    eclipse_adapter2.jpg

     

     

    Create Cordova Application Project (Client) using MobileFirst CLI

    Create Cordova Project using MobileFirst CLI (IBM Site)

    1.) First , open node.js command prompt ( for windows OS), in the workspace Start create Project > (cmd) – cordova create myFirstCordova com.fndong.HelloWorld –template cordova-template-mfp

    cordovaCL1.jpg

    2.) After Created, add the Android platform, I’ll using android version android@5.1.1. Go to directory project myFirstCordova > run command : cordova platform add android@5.1.1.

    cordovaCL2.jpg

    3) set the config.xml which will added elements such as mfp, server, locale and Extensions. Command : mfpdev app config

    cordovaCL3.jpg

    4.) Register Project Cordova to MobileFirst Console Server. command : mfpdev app register.

    run the cordova prepare:

    cordova prepare

     5) To run the App in IBM Simulator. command : mfpdev app preview.

    7) Creating Adapter