Category Archives: Java

JavaMail, sending emails from your Java application

The JavaMail API provides a platform-independent and protocol-independent framework to build mail and messaging applications. The JavaMail API is available as an optional package for use with Java SE platform and is also included in the Java EE platform. Download JavaMail jar files from here. Full JavaMail API. For a full example with source code of JavaMail, click on “more” link down here. Continue reading

RxTx / Serial Communication on Windows

Serial communication through COM ports are very common both in prototyping and industry. To be able to read / listen to COM ports on Java, Arudino or Processing you need to install the RxTx library. Follow the instruction to install Serial and Parallel communication installed on your Windows.
  1. unzip rxtx-*-win32.zip
  2. copy rxtxSerial.dll / rxtxParallel.dll to %JAVA_HOME%bin
    (e.g. c:Program FilesJavaj2re1.4.1_01)
  3. copy RXTXcomm.jar to %JAVA_HOME%libext

Download RxTx

Processing, the key for Arduino board independent programming

When it comes to Arduino, there are several ways to do things. Using simple Arduino IDE to communicate with the board through serial port. Write a Java program to do it, or maybe do send orders to Arduino through your program that is not uploaded on Arduino card and can be changed anytime without even updating the pde file on the board. The tool that gives you  the power to do this is called Processing & the library used exactly for Arduino is called StandardFirmdata. The very good thing about Processing is that it is based on Java and all Java codes works right out of the box on it. You can also import processing libraries into your Java framwork and enjoy the power of processing right in the middle of your Java project(in Eclipse).

The instruction to get Processing & Arduino talk together :

  1. Download this file.
  2. Unzip the library and copy the “arduino” folder into the “libraries” sub-folder of your Processing Sketchbook. (You can find the location of your Sketchbook by opening the Processing Preferences. If you haven’t made a “libraries” sub-folder, create one.)
  3. Run Arduino, open the Examples > Firmata > StandardFirmata sketch, and upload it to the Arduino board.
  4. Configure Processing for serial:http://processing.org/reference/libraries/serial/
  5. In Processing, open one of the examples that comes with with the Arduino library(in the same folder that we just unzipped).
  6. Edit the example code to select the correct serial port.
  7. Run the example.

Android development tricks

This is a summay of the tricks I have learned making an application called courseApp project.  This application was developed in the Mobile Information Systems that I took at University of Oslo. Eclipse is a very good tool to use for Android development. To start with you need to download Andriod SDK. After installing both of these(and ofcourse Java Development Kit, JDK which is a pre-requirement for both of these), you need to make Eclipse and Android SDK talk together. This is done by a plugin called “ADT plugin for Eclipse” from Google. You can read more about how to install this plugin by clicking hereIn case of Android SDK installation(the exe file) doesn’t recognize JDK on your computer, you can simply download the zip file and extract it. Don’t forget appending that folder to the %PATH% environment variable. Now some more tips follows :

Continue reading

Dashed line at Java/Processing

This code is a little bit edited and re-posted again from a post I found on Processing forum. Check the source at the bottom of the post for the original post.
[java]
import java.awt.*;

float[] dashes = { 16.0f, 8.0f, 4.0f, 8.0f };
BasicStroke pen;

void setup(){
size(400, 400);
noLoop();
pen = new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 4.0f, dashes, 0.0f);
Graphics2D g2 = ((PGraphicsJava2D) g).g2;
g2.setStroke(pen);
}

void draw(){
line(0, 0, width, height);
line(0, height, width, 0);
}
[/java]
source : http://processing.org/discourse/yabb2/YaBB.pl?board=Syntax;action=display;num=1217445670

Processing & Arrow keys

Although in the Processing API it is mentioned that key returns the value of the pressed key, but when it comes to arrows it just returns question mark !!! The magic is to use keyCode :-)

[java]
void keyPressed(){
//print(keyCode);
if (keyCode == RIGHT){
//GO RIGHT
}
else if (keyCode == LEFT){
//GO LEFT
}
<div>else if (keyCode == UP){</div>
<div>//GO UP</div>
<div>}</div>
<div>else if (keyCode == DOWN){</div>
<div>//GO DOWN</div>
<div>}</div>
}//end of keyPressed

[/java]