Java Programming Tutorials

Java Programming Tutorials And Articles
  Title / Author Replies
Views Reverse Sort Order
A thread can be created in Java programs in two ways – by extending Thread class and by implementing Runnable interface. In case, where the class extends a Tread class, it must override run() method of the Thread class. The program may override the other methods also. If the program uses Runnable...
Introduction Buffers can be very useful in Java since they speed up I/O operations considerably. Basically a buffer is a space allocated in memory for Bytes, Chars, and other data types to be stored. Buffers are really useful while writing Client/ Server applications. Creating a Buffer A...
Here is a file splitter made in java . try it with files. Don't try it with directory. It will not respond in the way u want. Splitter class import*; class Splitter { public static void main(String args) throws IOException { takeInput(args);
Java defines several built-in classes for exception handling. All these classes are a part of the java.lang package which is automatically imported. That is why, while throwing an exception you did not specifically include any package for exception classes. Apart from the built-in exception...
Introduction The code bound by the try block need not always throw a single exception. If in a try block multiple and varied exceptions are thrown, then you can place multiple catch blocks for the same try block in order to handle all those exceptions. When an exception is thrown it traverses...
How do I instantiate a bean whose constructor accepts parameters using the useBean tag? Replacing Characters in a String? Searching a String? Connecting to a Database and Strings Handling? What is a transient variable?
In the previous article we discussed three examples, each of which demonstrates how to track user sessions programmatically, using URL rewriting, cookies, and hidden form fields respectively. Each of these techniques required some unique string to be exchanged between the client and the server, so...
Introduction Java environment has been built around the multithreading model. In fact all Java class libraries have been designed keeping multithreading in mind. If a thread goes off to sleep for some time, the rest of the program does not get affected by this. Similarly, an animation loop can...
Here is a simple implementation of client-server using Java. There are two java files, one for client code and one for server code. The code is quite self-explanatory. /* ** A TCP based client that will send the number entered by the user for factorial ** ...
Growing an Array in Java Suppose you have an array of some type that is full, and you want to grow it. Employee a = new Employee; // array is full int newLength = a.length * 11 / 10 + 10; Employee newArray = new Employee; System.arraycopy(a, 0, newArray, 0, a.length); a = newArray;That...
Introduction A pattern of special characters is used to specify the format of the date. The example below demonstrates some of the characters. For a complete listing, see the javadoc documentation for the SimpleDateFormat class. Note: This example formats dates using the default locale...
Here we go. This example is used to illustrate that “how we can use color class in java?” We several time need to color our panel, label, or form. For this java provide us Color class in awt package i.e “”. This class has seven - number of constructor. But the widely used...
Introduction Assertion facility is added in J2SE 1.4. In order to support this facility J2SE 1.4 added the keyword assert to the language, and AssertionError class. An assertion checks a boolean-typed expression that must be true during program runtime execution. The assertion facility can be...
You have seen that an exception is thrown either implicitly in the try block and there is a catch block ready to handle it. But, there are methods, which throw the exception, but do not catch it within the method body. In this case the method which is throwing the exception must use a throws clause...
Introduction Have you ever searched for files and folders in Windows operating system? Generally most of the users try to search various .doc files, .pdf files etc. We generally search by giving *.doc or *.pdf in the text box of the search window of the windows OS. Of course windows OS provides...
Comparing Strings To compare strings function equals() is used. String str1 = "XYZ"; String str2 = "xyz"; boolean result = str1.equals(str2); boolean result2 = str1.equalsIgnoreCase(str2);Output
Just like the multiple catch blocks, we can also have multiple try blocks. These try blocks may be written independently or we can nest the try blocks within each other, i.e., keep one try-catch block within another try-block. The program structure for nested try statement is: try { //...
There are four types of JSP tags, which are important and often required. 1. Directives These types of tags are used primarily to import packages. Altenatively you can also use these tags to define error handling pages and for session information of JSP page. <%@page language="java" %> ...
When many items of data of the same class or type have to be stored, it is more efficient to use an array than separate variables or objects. For example, if the temperature on each day of the (non-leap) year had to be stored, rather than set up tempjan1, tempjan2... tempdec31 (365 variables)...
This article continues our exploration of the Abstract Window Toolkit (AWT). It examines the standard controls defined by Java. Controls are components that allow a user to interact with your application in various ways—for example; a commonly used control is the push button. The AWT supports...