Sunday, June 5, 2011

Operations on stream (Stream)

Operations on stream (Stream)

Basic class I / O Reader, Writer, InputStream, and OutputStream provide only operations I / O is very basic. For example, InputStream class has instance methods
public int read () throws IOException

to read one byte of data from the input stream. If until the end of the input stream, the method read () will return the value -1. If there are errors that occur when taking input, then an exception IOException will be thrown. Because IOException is a class exemption that must be dealt with, meaning we must use the method read () inside the try statement or set subroutine throws IOException. (See again the discussion of exceptions in the previous chapter)

InputStream class also has methods to read a few bytes of data in a single step into an array of bytes. However, InputStream does not have a method to read the other data types, like int or double from the stream. This is not a problem because in practice we will not use object of type InputStream directly. We will use is a subclass of InputStream that have multiple input methods are more diverse than the InputStream itself.

So is the OutputStream class has a primitive output method for writing one byte of data to the output stream, the method
public void write (int b) throws IOException

But, we almost certainly will use derivatives class capable of handling more complex operations.

Reader and Writer classes have almost the same basic operations, namely read and write, but this class-oriented character (because it is used to read and write data to human readable). This means that read and write operations will take and write char values ​​rather than bytes. In practice we will use a class derived from these base classes.

One interesting thing from the package I / O in Java is a possibility to increase the complexity of a flow stream by wrapping it in another stream object. This wrapper object is also a stream, so that we can also read and write from the same object with additional capabilities in the object wrapper.

For example, PrintWriter is a subclass of Writer that has additional methods for writing Java data type in characters that can be read of Human. If we have an object of type Writer or their derivatives, and we want to use the method on the PrintWriter to write data, then we can wrap the object in the object Writer PrintWriter.

Example if baskomKarakter of type Writer, then we can make
PrintWriter printableBaskomKarakter = new PrintWriter (baskomKarakter);

When we write data to printableBaskomKarakter PrintWriter method on more sophisticated, then the data will be placed in the same place as when we write directly on baskomKarakter. That means we only need to create a better interface for the same output stream. Or in other words for example we could use a PrintWriter to write the file or send data on the network.

For details, methods of PrintWriter class has the following methods:
/ / Method to write data in
/ / Human readable form
public void print (String s)
public void print (char c)
public void print (int i)
public void print (long l)
public void print (float f)
public void print (double d)
public void print (boolean b)

/ / Write a new line to flow
public void println ()

/ / This method is the same as above
/ / But the output is always
/ / Plus the new row
public void println (String s)
public void println (char c)
public void println (int i)
public void println (long l)
public void println (float f)
public void println (double d
public void println (boolean b)

Note that the above methods do not ever throw an exception IOException. However, the PrintWriter class has a method
public boolean checkError ()

which will return true if there are errors that occur when writing into the stream. PrintWriter Class IOException catch exceptions internally, and set a specific value in this class if an error has occurred. So that we can use the PrintWriter methods without worrying should catch exceptions that may occur. However, if we want to make the program a tough course, we must always call checkError () to see if an error has occurred when we use one method of PrintWriter.

When we use PrintWriter methods to write data to a stream, the data is converted into a series of characters that can be read by humans. How do if we want to make the data in the form of machine language?

Java.io package has a byte stream classes, namely DataOutputStream can be used to write a data into a stream in binary format. DataOutputStream closely related to the OutputStream as the relationship between PrintWriter and Writer.

That is, OutputStream only contains basic methods for writing bytes, DataOutputStream has methods while writeDouble (double x) to write a double value, writeInt (int x) to write the value of int, and so on. And also we can wrap an object of type OutputStream or its derivatives into the stream DataOutputStream so that we can use more complex methods.

For example, if baskomByte is a variable of type OutputStream, then
BaskomData = new DataOutputStream DataOutputStream (baskomByte);

to wrap baskomByte in baskomData.

To retrieve data from the stream, has java.io DataInputStream class. We can wrap an object of type InputStream or their derivatives into an object of type DataInputStream. Methods in the DataInputStream for reading binary data can be used readDouble (), readInt () and so on. Data written by DataOutputStream is guaranteed to be read back by the DataInputStream, although we write data on one computer and read data on other types of computers with different operating systems. Compatibility binary data in Java is one of the benefits to be dijalakan Java on a variety of platforms.

One sad fact about Java is that the Java does not have the class to read data in a form that can be read by humans. In this case, Java does not have the class PrintWriter as opposed to DataOutputStream and DataInputStream. However, we still can make the class itself and use it in a way that exactly the same as classes above.

PrintWriter Class, DataInputStream and DataOutputStream allows us to input and output of all primitive data types in Java. The question is how we read and write an object?

Maybe we would traditionally make their own function to format our object into a certain shape, such as the sequence of primitive types in binary or character is then stored in a file or sent over the network. This process is called serialization (serializing) the object.

On input, we should be able to read serialized data are consistent with the format used at the time of this object serialized. For small objects, this kind of work may not be a big problem. However, for large object sizes, this is not easy.

However, Java has a way to input and output of content objects automatically, ie by using ObjectInputStream and ObjectOutputStream. These classes are subclasses of InputStream and OutputStream that can be used to read and write objects that are serialized.

ObjectInputStream and ObjectOutputStream is a class that can be covered by other classes InputStream and OutputStream. This means we can do input and output byte stream object on anything.

Metde to the object I / O is the readObject () which is available on the ObjectInputStream and writeObject (Object obj) available in ObjectOutputStream. Both can throw IOException. Remember that the readObject () returns a value of type Object, which means must be type cast to type real.

ObjectInputStream and ObjectOutputStream only work for objects that implement the interface named Serializable. Lbih far all the instance variables of the object must be serialized, because the methods of Serializable interface does not have anything. This interface exists only as a marker for the compiler so the compiler knows that this object is used to read and write to the media.

What we need to do is add "implements Serializable" to the class definition. Many of the Java standard class that has been declared to be serializable, including all components of Swing and AWT classes. This means that GUI components can be stored and read from the device I / O using ObjectInputStream and ObjectOutputStream.
READ MORE - Operations on stream (Stream)

Stream, Reader, dan Writer

Stream, Reader, dan Writer

Computer programs can be useful if he could interact with other worlds. Interaction here means input / output or I / O. In this chapter, we will see the input / output on files and network connections (network). In Java, the input / output on the file and the network is based on the flow (stream), where all objects can do the I / O is the same. Standard output (System.out) and standard input (System.in) is an example of the flow.

To work with files and networks, we need knowledge about the exception, which has been discussed previously. Many subroutines are used to working with I / O throw an exception that must be addressed. This means that the subroutine must be called within the try statement ... so catch exceptions that occur can be handled properly.

Without being able to interact with the other world, a program is useless. Interaction of a program with other world is often called input / output or I / O. From the first, one of the biggest challenges for designing a new programming language is to prepare the facility to input and output. Computers can connect with various types of input and output of various devices. If the programming language must be created specifically for each type of device, the complexity will no longer be handled.

One of the biggest advances in the history of programming is the concept (or abstraction) to model the device I / O. In Java, abstraction is called the flow (stream). This section will introduce the flow, but does not explain the complete. For more details, please refer to official documents Java.

When dealing with input / output, we must remember that there are two general categories of data: data created by the machine and human readable data. The data that made the engine written with the same model with how data is stored in the computer, namely a series of zeros and ones. Human-readable data is data in the form of a series of letters. When we read a number is 3.13159, we read it as a series of letters which we translate as numbers. This number will be written in a computer as a series of bits that we do not understand.

To deal with both types of data, Java has two broad categories for streams: byte streams for machine data (byte stream), and flow character (character stream) for human-readable data. There are many classes derived from both these categories.

Any object that issued the data to a stream of bytes into a class derived from abstract class OutputStream. Objects that read data from a byte stream derived from the abstract class InputStream. If we write numbers to an OutputStream, we will not be able to read the data because it is written in machine language. However, these data can be read back by the InputStream. The process of reading and writing data will be very efficient, since there is no translation to be done: bits used to store data in computer memory is only copied from and to the flow.

To read and write character data that can be understood by humans, the main classes are Reader and Writer. All character stream classes are subclasses of one of these abstract classes. If a number Writer will be written in the stream, the computer must be able to translate it into a series of characters that can be read maunsia.

Read numbers from the Reader stream into a numeric variable must also be translated, from the sequence of characters into a series of bits that computers understand. (Although for data consisting of characters, like the text editor, there will be some translation done. Characters are stored in a computer in 16-bit Unicode value. For people who use the ordinary alphabet, character data is usually stored in files in ASCII code, that only uses 8-bit. Class Reader and Writer will handle the change from 16-bit to 8-bit and vice versa, and also handle other alphabets used in other countries.)

It is easy to determine whether we should use a byte stream or character stream. If we want the data we read / write for the human readable, so we use the character stream. If not, use a byte stream. System.in and System.out is actually a stream of bytes and not a character stream, hence can handle inputs in addition to the alphabet, for example the enter key, arrows, escape, etc..

Standard flow class that will be discussed later defined in the java.io package along with several other auxiliary classes. We have to import classes from this package if you want to use them in our program. This means that by using the "import java.io. *" at the beginning of our source code.

The flow is not used in the GUI, because the GUI has a flow of I / O itself. However, these classes are used also for the files or communications in the network. Or it could also be used for communication between the threads that work simultaneously. And there is also a flow class that is used to read and write data to and from computer memory.
READ MORE - Stream, Reader, dan Writer

example, we're connecting to a local Interbase server

JDBC connection to an Interbase database. In this example, we're connecting to a local Interbase server using the JDBC ODBC bridge driver after setting up Interbase as an ODBC datasource on the local system.
// Establish a connection to an Interbase database using JDBC and ODBC.
import java.sql.*;

class JdbcTest1
{
public static void main (String[] args)
{
try
{
// Step 1: Load the JDBC ODBC driver.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Step 2: Establish the connection to the database.
String url = "jdbc:odbc:contact_mgr";
Connection conn = DriverManager.getConnection(url,"user1","password");
}
catch (Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}
READ MORE - example, we're connecting to a local Interbase server

Now all we have to do is close the connection

Now all we have to do is close the connection. Actually we should close all of the instances of Connection, Statement and ResultSet and
it's done in reverse order from which they were created:


if (rs != null)
rs.close();
if (statement != null)
statement.close();
if (con != null)
con.close();


For many of the code statements above it is required to handle an SQLException in case anything goes wrong.
Thus you'll have to enclose much of the code in a try / catch block which were excluded in the example to make it more readable.


// Declare the variables outside the try block to be able to call them
// in a finally block where the closing should take place.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;


try {

//all code here

} catch (SQLException ex) {

ex.printStackTrace();

} finally {

//the code for closing here
}
READ MORE - Now all we have to do is close the connection

what other tools exists to capture database level data

Both SQL Server and Windows offer a lot of data to help troubleshoot and monitor overall usage and performance for your SQL Server databases. Within SQL Server there are several DBCC commands as well as a lot newly exposed data from the Dynamic Management Views in SQL Server 2005.

One way of monitoring your individual database usage is to view the data from the dbo.sysprocesses table or sys.sysprocesses in SQL 2005. This data is also exposed by either using the GUI tools or by running sp_who2. From this you can tell who is currently connected to each database and the activity that is occurring, but it is not very easy to create a baseline or a trend from this data. Another approach is to run a server side trace or use Profiler to capture the data. This may be helpful, but this may give you too much information as well as still having the need to extract the data to figure out what is going on within each database. So what other tools exists to capture database level data?

Solution
Most DBAs and developers probably use Profiler, trace, review query plans, run sp_who2, run DBCCs, etc... to capture data to figure out what is currently running on the database server. These tools are great, but don't give you the entire picture in an easy to use way.

Another tool that all DBAs and developers should use is Performance Monitor. This OS level tool provides great insight into Windows counters, but also into specific SQL Server counters. There are hundreds of counters that are exposed within this tool and there are several that are specific to SQL Server.

To launch Performance Monitor, click Start, Run... and type in "perfmon" and the following should open. This application can also be found under the Administrative Tools.

To add a counter, click on the + icon or use Ctrl + I and the following will open.
Most of the counters are server specific and do not give you insight into each individual database, but the following list of counters are at the database level, so this means you can collect this data for each database that is on the server as well as an overall count for all databases.
READ MORE - what other tools exists to capture database level data

To setup dual monitors in Ubuntu

 
To setup dual monitors in Ubuntu, we need to modify the file called xorg.conf inside of /etc/X11

1. After finished installing Ubuntu, go to your Terminal Window in Applications-Accessories-Terminal, then type the following:

sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf-old


This is to backup the original setting in case we need to reset the display.

2. Edit the xorg.conf by typing the following in the Terminal:

sudo gedit /etc/X11/xorg.conf

Make sure “glx” is under module section, if not replaced “nv” with “glx”

3. Edit Screen setting by insert these codes under the Screen

Option “RenderAccel” “true”

Option “TwinView”


Option “MetaModes” “1280×1024 1280×1024″ <—YOUR ACTUAL LCD’S RESOLUTIONS

Option “TwinViewOrientation” “RightOf”

You can use “LeftOf” or “BelowOf” if you’d like to

Save xorg.conf, and close it.

Now logout of your section. When you log back in, you should have your twinview working.

Troublshooting: If you cannot access login screen after restart/logout, enter username/password at command line, then type the following to restore your display:

sudo cp /etc/X11/xorg.conf-old /etc/X11/xorg.conf

Restart your system, your login screen should be back.
READ MORE - To setup dual monitors in Ubuntu

Oracle database consists of a collection

An Oracle database consists of a collection of data managed by an Oracle database management system. You can download Oracle Database XE server for Debian, Mandriva, Novell, Red Hat and Ubuntu Linux distributions. First you need to get databases up and running in order to use Oracle. The Oracle database has had a reputation among new Linux users as difficult to install on Linux systems. Now Oracle Corporation has packaged recent versions for several popular Linux distributions in an attempt to minimize installation challenges beyond the level of technical expertise required to install a database server.

Make sure you have enough disk space and memory

If you have less than 1GB memory run the following commands to create swap space:
$ sudo dd if=/dev/zero of=/swpfs1 bs=1M count=1000
$ sudo mkswap /swpfs1
$ sudo swapon /swpfs1
Debian / Ubuntu Oracle installation

First modify /etc/apt/sources.list file:
$ sudo vi /etc/apt/sources.list

Append following line:
deb http://oss.oracle.com/debian unstable main non-free

Save and close the file. Next import GPG key:
$ wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle -O- | sudo apt-key add -

Update package database:
$ sudo apt-get update

Finally install Oracle:
$ sudo apt-get install oracle-xe

Output:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-headers-2.6.20-15-generic linux-headers-2.6.20-15
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
libaio
The following NEW packages will be installed:
libaio oracle-xe
0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.
Need to get 221MB/221MB of archives.
After unpacking 405MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://oss.oracle.com unstable/non-free oracle-xe 10.2.0.1-1.1 [221MB]
....
....
Post-install configuration

You must configure Oracle TCP/IP port and other parameters. Simply type the following command:
$ sudo /etc/init.d/oracle-xe configure

Output:
Oracle Database 10g Express Edition Configuration
-------------------------------------------------
This will configure on-boot properties of Oracle Database 10g Express
Edition. The following questions will determine whether the database should
be starting upon system boot, the ports it will use, and the passwords that
will be used for database accounts. Press to accept the defaults.
Ctrl-C will abort.

Specify the HTTP port that will be used for Oracle Application Express [8080]: [Enter key]

Specify a port that will be used for the database listener [1521]:[Enter key]

Specify a password to be used for database accounts. Note that the same
password will be used for SYS and SYSTEM. Oracle recommends the use of
different passwords for each database account. This can be done after
initial configuration:secret
Confirm the password:secret

Do you want Oracle Database 10g Express Edition to be started on boot (y/n) [y]:y

Starting Oracle Net Listener...Done
Configuring Database...Done
Starting Oracle Database 10g Express Edition Instance...Done
Installation Completed Successfully.
To access the Database Home Page go to "http://127.0.0.1:8080/apex"

To access the Database Home Page go to http://127.0.0.1:8080/apex. Open a web browser and type url (you need to use username "system" and password setup earlier)
READ MORE - Oracle database consists of a collection
 
THANK YOU FOR VISITING