Friday, July 8, 2011

Basic Java Class

Hi! Today I'm going to talk some thing about the basic java source file
We know all programming languages has to compile before they execute to change the platform.
Java source file can be write in notepad or any other IDEs like NetBeans and what ever the IDE or notepad we are using we have to follow some restrictions to make compile our code.
In our source file the first part that is the top part of the source file must be the package declaration part which declare our source file to a particular place where some other source files also can be included.

The second part will be the import statement part which tell the compiler some source file we have to attached from other packages to our package because we are using the source code of that particular package.

The third thing i the class declaration where our favourite java class going to be declared.

If we don't have the first part and second part we talked above. The class declaration will be the first part

for example :

class Test{

The above code just compile fine and can't run the file because the JVM looks for the main method for starting the execution our above code don't have main method so at the runtime JVM pass an exception.

If we make the class as public we have to have the sourcefile name as same to the public class name. One java file can contain more than one class but only one class can declare as public and if a class declared public the source file must be named as the public class name

Full Example

package myPackage;//package declaration

import java.util.*;//import statement
import*; //import statement

public class A{
B b = new B();

class B{
Random random = new Random();

the above class must be named as

Sunday, June 26, 2011

Getting the Method Information of a given class

Hello guys After some time,
All Java Programmers and Developers Know java is a Object Oriented Programming language. Java can be explain with few words, which is "classes and make objects using the class and interact between objects" so every object have the template as their classes.
Here we are going to show how can we get the information of a given class at the run time. To overcome the problem we have to use the Reflection API which is inbuilt with jdk. Reflection is a very useful tool for developers because if we would like to make some changes to our class at runtime it is the most suitable way.
I would like to show a small program which will provide the all methods of a given class at runtime.
import java.lang.reflect.*;
public class MethodsFinder {
  public static void main(String args[]){
         try {
            Class classes = Class.forName(args[0]);
            Method[] methods = classes.getDeclaredMethods(); 
            for (int i = 0; i < methods.length; i++)
         catch (Exception e) {
            System.err.println("Your error is " + e);
   }Save the above code in a notepad, name the notepad as ""
Compile the source file as     "javac"
and run the file by giving your class as argument as java MethodsFinder java.lang.String
the above underline class is my argument therefor It will provide the output as


 The above output shows all the methods of String class which is an inbuilt class in java. We can get the method details of any given classes just by changing the argument at runtime. Ok guys I thing you have got my point and do it yourself.

Wednesday, June 1, 2011

Renew IP Adress

We all facing the problem which occurs when we are browsing internet. The problem is at the browsing time our browser displays a message which is "Page not found" error message. After showing this message we check our modem and other all connections with the internet but the problem is not in that devices. This type of problem occurs because to renew your IP address, which stands for Internet Protocol Address.
We can renew the IP address by doing the process given below.
1. Go to run dialog box by pressing window key and r key (window + r)
2. Type the word cmd on the run dialog box
3. Click ok button on run dialog box
4. Then comand prompt will appear
5. In command prompt type ipconfig /release and press enter key
6. You can see the IP address of your machine in command prompt
7. Type the words ipconfig /renew in the next line and press enter key
8. Ok you change your IP address and exit from command prompt

The picture demo shown below

Tuesday, May 31, 2011

Differences between JRE and JVM

We all know that the java program is the most popular program in the world for a long period of time. If any one think java is not the most popular language you can just Google it the word “Which is the most popular programming language”. The java programmers use the word JVM and JRE most of the time but most of the programmers might not know the difference between those two terms.
I would like to give some of the basic differences of JVM and JRE. The JVM stands for ‘Java Virtual Machine’ and JRE stands for ‘Java Runtime Environment’.
The JRE includes a lot of libraries and also it includes JVM. There for JRE is the container of JVM both are not same.

The JVM understands the corresponding byte code of a java class and make it ready for run and then JRE run the JVM provided code with the help of other libraries if necessary.

We can see the differences clearly from the picture given below