Enable Assertions in Netbeans 7

Hello All,
Some people were asking how they can enable assertions in Netbeans.Here is the simple answer.In the command line execution you can add the argument -ea (enable assertions) to the run command like  : java -ea myApp.javaIn netbeans,
Right click on your project name and select properties,
Click Run in the leftside panel
Then, in the right, write -ea in the input box beside VM Options, Then you are done.

This is the same way you can add any runtime parameters to netbeans

Installing tomcat6 Ubuntu 10.10

Hello all,

The following are the direct steps for installing tomcat 6 under Ubuntu and get started using it:
open a terminal and write the following commands while you are a root ( su ).
NOTE: Do not forget to restart the service after each change to get the effects applied.
apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-user tomcat6-docs tomcat6-examples

The previous command installs the necessary files and libraries to run tomcat.

To insure the server has been installed, write the following in your browser:
localhost:8080 (this port can be seen and changed. look at section changing port number to know the step. )

You will get a message indicates every thing is ok. I recommend you to read it carefully, It gives you the next steps to start.

As you will read you will mostly need to do the following steps:

Add user with a manager role to be able to use the web administration tool. To do this you will need to edit /etc/tomcat6/tomcat-user.xml file

Add the following under the tag names tomcat-users

Common Used Commands:

Also There is some commands you will need frequently to start, stop, restart the service:

sudo /etc/init.d/tomcat6 start

sudo /etc/init.d/tomcat6 stop

sudo /etc/init.d/tomcat6 restart

sudo /etc/init.d/tomcat6 status

Changing Port Number

if you are running multiple web services, you may be in need to change the tomcat port (default 8080) to another UN-USED port number.

This can be done by editing the /etc/tomcat6/server.xml

Search for the following :
8080” protocol=”HTTP/1.1″
redirectPort=”8443″ />

change the 8080 to any number you want.

Running your web applications:

your applications should be placed in /var/lib/tomcat6/webapps/
to be recognized and run though web browser. After that, you can access it directly from your web browser

I guess this all what you need to get started.

Good luck.

Mohammed Saudi

Understanding Streams in Java

Understanding Streams in Java


By: Mohammed Saudi.

Download examples :

A Data Stream is a flow of data between data source and data sink (the data goes to it).

Data source or sink could be for example disk file, device or network socket.

Two types of streams available in java ; Byte streams and Character streams. They differ in the level they are dealing with data; either data is read/written in 8-bit fashion ( byte stream) or in 16-bit unicode character fashion (character based).

If you are not working with images or sounds, it would be easier and better to use character-based streams; they handle the conversion and encoding stuff.

There is also a helpful classes ( java.io.InputStreamReader and java.io.OutputStreamWriter) that handle the gap between those two types. They convert byte data into character-based.

Also there is a Data stream classes that reads data directly by type (int, string, float ,… ). They relay on a stream objects.

DataInputStream and DataOutputStream. are typical examples.

DataOutputStream(OutputStream out)

DataInputStream(InputStream in)

Examples of Byte Stream classes are

InputStreamReader, OutputStreamWriter, BufferedReader and BufferedWriter.

Examples of character Stream classes ( data sink streams) are

FileReader and FileWriter

===== Reading Files using byte-based streams ====


This Program reads “myInputFile.txt” file byte by byte and write the data into the file “myOutputFile.txt”

you should have myInputFile.txt in the same path of this java file

By: Mohammed Saudi.



import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

public class ReadBytes {

public static void main(String[] args) throws IOException {

FileInputStream inStream = null;

FileOutputStream outStream = null;

try {

inStream = new FileInputStream(“myInputFile.txt”);

outStream = new FileOutputStream(“myOutputFile.txt”);

int c; //I use int here because I use the read function blow which returns an integer.

while ((c = inStream.read()) != -1) {




catch (Exception fe){



finally {

if (inStream != null) {



if (outStream != null) {






===== Reading Files using character-based streams ====


This Program is the same as “ReadBytes” except it uses filereader and filewritter classes

you should have myInputFile.txt in the same path of this java file

* note: you may have a problem in character encoding when using filewritter class.

If so, use the OutputStreamWriter on a FileOutputStream instead.

By: Mohammed Saudi.



import java.io.*;

// Displays contents of a file

//(e.g. java Type app.ini)

public class ReadChars


public static void main(

String args[]) throws Exception


// Open input/output and setup variables

FileReader fr = new FileReader(“myInputFile.txt”);

FileWriter fw = new FileWriter(“myOutputFile.txt”);

char cToReadIn[] = new char[1000];

int read = 0;

// Read (and print) till end of file

while ((read = fr.read(cToReadIn)) != -1)




// Close shop





Download examples :