Tuesday, February 14, 2012

Getting IP address in java

try
{
InetAddress[] addresses = InetAddress.getAllByName( "http://wwwroboticsforall.blogspot.com/" /* Ip assress or Domain name */ );


for ( int i=0; i String hostname = addresses[i].getHostName();
               System.out.println(addresses[i].getHostAddress());
               System.out.println( hostname );

}
}


catch (UnknownHostException e)
{
System.out.println("unknown host");
}

Thursday, February 9, 2012

How to read file attibutes

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
*
* @author Saman
*/
//http://wwwroboticsforall.blogspot.com/


//Use following source file to test and lean java file attributes.


public class Attrib {


void print(String fileName)throws IOException,FileNotFoundException{
//Prints attributes in console.
//http://wwwroboticsforall.blogspot.com/

File file=new File(fileName);
System.out.println("\n"+file.getAbsoluteFile()+" file attributes..\n");
System.out.println(file.canExecute()?"Excutable\n":"Not a Excutable\n");
System.out.println(file.canRead()?"Readable\n":"Unreadable\n");
System.out.println(file.exists()?"File already exits\n":"File not Found\n");
System.out.println(file.canWrite()?"Writable\n":"Unwritable\n");
System.out.println(file.isDirectory()?"Directory\n":"Not a derectory\n");
System.out.println(file.isFile()?"File\n":"Not a file\n");
System.out.println(file.isHidden()?"Hidden File\n":"Visible File\n");


}

public static void main(String[] args) {
//http://wwwroboticsforall.blogspot.com/
try {

//Replace fileNameWithPath to created file on your computer.

//C:\boot.inf is a system files in windows operating systems and boot informations included

String fileNameWithPath="c:/boot.ini";
Attrib attrib=new Attrib();
attrib.print(fileNameWithPath);

} catch (Exception e) {
e.printStackTrace();
//if an error found prints in the console, so you can find out error easily.
}
}

}

Tuesday, May 17, 2011

List of Tutorials

Saving values of object in the Hard Disk Drive (Serialization) http://wwwroboticsforall.blogspot.com/p/java-lessons-tutorial-helper.html
Writing text file in java   http://wwwroboticsforall.blogspot.com/p/java-lessons-tutorial-helper.html 




    



          

Sunday, May 8, 2011

Making a Simple Java File.

1 Open text editor like notepad and type..
* java is a case sensitive language. (type in notepad as shown as bellow(Capital Simple Letters))





Then save your java file in hard disk named myFristJava.java  (Ex: c:\java\myFristJava.java)


2 Open Command Prompt in your computer by (start->run  and typing cmd) or (start->all programs accessories->Command Prompt)






Type in cmd .....


                         path=c:\program files\jdk1.7\bin  (this path must be the path of jdk installed on  your computer. )






Now compiler is ready to compile your java file.


then type on cmd...


                                                               
your java file's saved file path (Ex: cd java)for c:\java
                       javac myFristJava.java                 


This command line arg tells java compiler to compile the myFristJava.java file in c:\java folder.


                        java myFristJava            


This line tells to jvm(Java Virtual Machine) to run your java program.




         If correctly compiled and run, prints  Hellow. My name is saman. in the command prompt.

Java Lessons.

Java is a high-level and powerful Computer programming language.


* Java is used by  many websites, business softwares and other application softwares.
* Java is not a platform independent computer programming language.


Ex:- There is a java .class file compiled on windows operating system. that .class file run on all widows operating systems and also run on java supported any other operating systems like linux, ubuntu OSs.