Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Thursday

Getting Started with Eclipse IDE 64-bit Neon and Java 8 Programming

Download and install Java SE JDK 8 64-bit
of filename jdk-8u121-windows-x64.exe
from

Download Eclipse IDE 64-bit Neon
of filename eclipse-java-neon-3-win32-x86_64.zip
from
Note: Download Eclipse in zip file format because no installation is required. Do not download the eclipse-inst-win64.exe executable file.

Copy the downloaded zip file eclipse-java-neon-3-win32-x86_64.zip to C drive

Extract the zip file to C drive. You do not need to install this file. The zip file is not the executable file.

Right-click at
C:\eclipse-java-neon-3-win32-x86_64\eclipse\eclipse.exe
Select “Send to” > select “Desktop (create shortcut)”
Rename the shortcut file as “eclipse-java-neon-3-win32-x86_64”

On the desktop, double-click the eclipse desktop icon shortcut
of shortcut name “eclipse-java-neon-3-win32-x86_64”

Create and Select a directory as workspace at
Workspace: D:\workspace_eclipse

Close the Welcome screen

Eclipse IDE Menu  > File > New > Java Project
Project Name: projectTest1
Click the button Finish

Go to Package Explorer window
Right-click on the “src” folder > select New > select Class
On the Java Class window: Java filename: Name: Class1
Click the button Finish

Filename: Class1.java
Type the following file content:
///// ///// ///// /////  
package projectTest1;
public class Class1 {
     
      public static void main(String[] args) {
             System.out.println("hello world");
      }
}
///// ///// ///// /////

Toolbar > Play button

See the program output in the console window.
///// ///// ///// /////
hello world
///// ///// ///// /////

Wednesday

Java Database Programming Visually using NetBeans

Java DB (Derby) Database Tutorial using NetBeans IDE, Create Database Table Visually, Write Code to View Table Data

Download and install Java SE 7 from

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Download and install NetBeans IDE 7 from
https://netbeans.org/downloads/7.4/

Open NetBeans IDE

Go to the Projects window. Tab on Services

Expand the Databases tree node

Right-click on Java DB and select Start Server

Right-click on Java DB and select Create Database. Key-in the following text:
Database Name: db1
User Name: db1username
Password: db1password
Confirm Password: db1password
Database Location: C:\Users\yourname\.netbeans-derby
Click OK button

Right-click on jdbc:derby://localhost:1527/db1 [db1username on DB1USERNAME]
and select Properties. You will see the following information:
Database URL: jdbc:derby://localhost:1527/db1
Driver: org.apache.derby.jdbc.ClientDriver
Schema: DB1USERNAME
User: db1username
Click Close button to close the database Properties window

Right-click on jdbc:derby://localhost:1527/db1 and select Connect

Expand the “jdbc:derby://localhost:1527/db1” tree node

Expand the DB1USERNAME tree node

Right-click on Tables and select Create Table. Key-in the following information using the Create Table Dialog:
Table name: customer
Add the following columns to the customer table:
customer_id, type: INTEGER, contraints: Primary key & Unique & Index
customer_name, type: VARCHAR, size: 1000, contraints: Null
customer_home_address, type: VARCHAR, size: 1000, contraints: Null
customer_mobile_phone_number, type: VARCHAR, size: 1000, contraints: Null
customer_email_address, type: VARCHAR, size: 1000, contraints: Null
Click OK button to close Create Table window

Expand the Tables tree node

Right-click on CUSTOMER tree node, select “View Data” to add table data using the SQL editor

Go to the CUSTOMER table middle window toolbar, click on “Insert Record(s) (Alt+I)” icon
Insert the following Customer table data:
customer_id, customer_name, customer_home_address, customer_mobile_phone_number, customer_email_address
1, name1, address1, mpnum1, email1
2, name2, address2, mpnum2, email2
3, name3, address3, mpnum3, email3
Click OK button to close Insert Record(s) window

Create a Java Application project. Name the project as prjJavaDBDerby1

Create a Java package. Name the package as test. Create a new Java Class under test package. Name the Java Class as ReadDbTableData.java

The code for the ReadDbTableData.java file content is as follows:
--
package test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ReadDbTableData {

    public static void main(String[] args) {
       
        try {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        } catch (ClassNotFoundException e) {
            System.out.println(e);
        }

        try {
            Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/db1", "db1username", "db1password");
            Statement stmt = con.createStatement();

            ResultSet rs = stmt.executeQuery("SELECT * FROM db1username.customer");

            while (rs.next()) {
                int customer_id = rs.getInt("customer_id");
                String customer_name = rs.getString("customer_name");
                String customer_home_address = rs.getString("customer_home_address");
                String customer_mobile_phone_number = rs.getString("customer_mobile_phone_number");
                String customer_email_address = rs.getString("customer_email_address");
                System.out.println(customer_id + ", " +
                                  customer_name + ", " +
                                  customer_home_address + ", " +
                                  customer_mobile_phone_number + ", " +
                                  customer_email_address
                                  );
            }
        } catch (SQLException e) {
            System.err.println(e);
        }

    }
}
--

Right-click on the project, select Properties.
On the left window, select Libraries.
Click on “Add Library…” button.
Select “Java DB Driver” library. Click on Add Library button to add this JAR library.
Click OK to close Project Properties window

Right-click on the ReadDbTableData.java file window and select Run File

You should be getting the following output:
--
1, name1, address1, mpnum1, email1
2, name2, address2, mpnum2, email2
3, name3, address3, mpnum3, email3
BUILD SUCCESSFUL (total time: 0 seconds)
--

Sunday

Android Programming using NetBeans IDE

Download and install Java SE 7 from http://www.oracle.com/technetwork/java/javase/downloads/index.html

Download and install NetBeans IDE 7 from https://netbeans.org/downloads/7.4/

Download and unzip stand-alone Android SDK Tools (android-sdk_r23.0.2-windows.zip) for an existing IDE from http://developer.android.com/sdk/index.html to the C drive. The extracted folder name should be "android-sdk-windows"

Open the "SDK Manager.exe" at C:\android-sdk-windows\SDK Manager.exe
Tick the box beside the package name "Android 4.1.2 (API 16)"
Tick also "Intel x86 Emulator Accelerator (HAXM) installer" package under Extras node
HAXM = Android Hardware Accelerated eXecution Manager for Intel processor
Click on the "Install anInteger packages..." button
Wait until all the ticked packages are finished installing

Restart PC. Press F10 or delete key to enter BIOS to enable Virtualization Technology which is normally under System Configuration section
Double-click on
"C:\android-sdk-windows\extras\intel\Hardware_Accelerated_Execution_Manager\intelhaxm.exe" file to install Intel HAXM
HAXM speeds up the slow Android emulator on Intel machine

On the Android SDK Manager window:
- click on SDK Manager Menu > Tool > Manage AVDs...
- create a new Android Virtual Device Manager (AVD)
--- AVD Name: avdAndroid_4_1_2
--- Device: Nexus 4 (4.7", 768 x 1280: xhdpi)
--- Target: Android 4.1.2 – API Level 16
--- CPU/ABI: ARM (armeabi-v7a)
--- By default, let the box beside the "Hardware keyboard present" ticked
--- Skin: Skin with dynamic hardware controls
--- Click the OK button
--- At top right corner, click 'x' icon to close "Manage AVDs..." window
- At top right corner, click 'x' icon to close the Android SDK Manager window

Open NetBeans IDE
Click on Menu > Tools > Plugins > Settings tab
Click Add button to add new url to the Update Center
Type: Provider Name: nbandroid
Type: URL: http://nbandroid.org/updates/updates.xml
Click OK button
Select "Available Plugins" tab
Tick the "Android" box
Click on Install button to install this nbandroid plugin
After "Android" plugin installed, click Close button

NetBeans IDE Menu > Tools > Options > Miscellaneous toolbar icon > Android tab
SDK Location: C:\android-sdk-windows (use Browse button)
Click OK button

NetBeans IDE Menu > File > New Project > Android > Android Project
Click "Next >" button
Project Name: AndroidApplication1
Package Name: com.mycompanyname
Activity Name: MainActivity
Target Platform: select: Target Name: Android 4.1.2
Click Finish button

Clean and build the Android project

Run the Android project
Wait for some minutes until you get the "MainActivity" app icon on the emulator menu screen

Note that, you do not need to close the avdAndroid_4_1_2 Android Emulator window once it is opened

Edit the Android source code to meet your requirements
If you don't have any clue, try to edit the file text in the "AndroidApplication1\Resources\layout\main.xml"

Right-click on the AndroidApplication1 project name, select Run again to execute this app

Multiple Languages in Spoken Words

Lax lah. - English, Malay.   Sik Zo Mei, Chi1, Simi Lay. = Chinese1, Chinese2, Chinese3. This barang is cikai one lah. = English, Malay, Chi...