Categories
java

JAVA: Tutorials List and Resources

1) Very Comprehensive Tutorials by the official java developers. No need for any book. Just learn all you want to know about java with ample example for each concept.

Download Them
View These Tutorials Online

2) This is a huge list of comprehensive tutorials
http://www.java2s.com/Tutorial/Java/CatalogJava.htm

3)IF you don’t like ads n all go here. It just plain list of tutorials on a single page
http://www.cafeaulait.org/javatutorial.html

4)Lee point’s Java Notes. This notes is useful in practical problems and you will need to refer this at least once in your project work
http://www.leepoint.net/notes-java/index.html

5)Java Boot Camp
http://www.javapassion.com/javaintro/
NO programming experience required to read this tutorials. Really good ones

6) Java Swing Tutorials.
http://java.sun.com/developer/onlineTraining/GUI/Swing1/shortcourse.html

Very Simple and Straight forward. Easy to understand with lots of examples

Categories
java

JAVA: The values boolean can be assigned

Boolean is one of the data type in java.

I has only two values true and false.
True & False or TRUE and FALSE are different from true and false.

the boolean values are defined constants in java language

Categories
functions java

JAVA:Renaming Files

To rename a file in java you first declare the file variable with oldname and next one with newname and
file1.rename2(file2);
[java]
public static void renamedirectory(String oldname,String newname){
// File (or directory) with old name

File file = new File(oldname);

// File (or directory) with new name
File file2 = new File(newname);

// Rename file (or directory)
boolean success =false;
if(file.isDirectory()){
success = file.renameTo(file2);
} else {
System.out.println(“The file is not a directory “+oldname) ;
}
if (!success) {
System.out.println(“File was not successfully renamed”);
} else {
System.out.println(“File Renamed from “+oldname+” to “+newname);
}
}
[/java]
The above function prints out if it doesnot rename succesfully.

Categories
functions java

JAVA: Deleting File

This function is to delete files in java. It first checks whether it exists or not next check for write access rights or permissions and then check if the directory is empty if the given file is a directory.


public static void delfile(String fname){
File f = new File(fname);
//Check whether file exists or not
if (!f.exists()){
System.out.print("file doesnot exists");
} else if (!f.canWrite()){
System.out.print("write prtected");
} else if (f.isDirectory()) {
String[] files = f.list();
if (files.length > 0){
System.out.print("this is a directory");
}
}
boolean success = f.delete();
}
Categories
functions java

JAVA:Splitting a String

In java you can split a string into two strings based on the delimeter using function split().
Example Given below

String s1 = “You are a dog”;
String[] pieces = s1.split(” “);

here we are splitting the string with ” ” (single space) as delimiter. The result will be a array of strings.. like

pieces[0] = You
pieces[1] = are
pieces[2] = a
pieces[3] = dog

Categories
java

JAVA:What is Difference between Swing and Awt?

Awt is old.
Swing is new.
Awt is heavy and slow.
Swing is Light and fast and has a lot of options.
Awt is limited in options.
Swing high performance..
So its always better to use swing than AWT

Categories
java

How to run an Exe from Java program

There sometimes we get a need to run a exe file from the java program. Now to run an exe type this
[java]
try
{
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(“notepad.exe”);
} catch(Exception e)
{
System.out.println(e);
}
[/java]
Here wer are running notepad.exe from the program. If you want to run another file you have to enter the program name as your_program.exe . If the exe is not in the current directory you need to give the absolute path.
You can also get the error value of the program using p.exitValue();

if you need to run another java program or a jar file use
[java]
java -jar path_to_java_file/file.jar
[/java]

Categories
java

How to read a file in JAVA

Ok here is the syntax to open a file in java


import java.io.*;

public static void main(String[] args){
String fname = "filename.txt";
try {
BufferedReader br = new BufferedReader(new FileReader(fname));

String line = br.readline(); //Reads a single line from file. Return null if end of file is reached
br.read();//read single character from file.
br.close(); //closes the file

} catch (IOException e) {
System.out.println(e);
}
}
}

Categories
java

Java

Java is one of the most complex languages. It has many modules and many classes and packages which would help in development of programs. The main use of java is that one can produce or develop software fast. There is a lot of packages available for you to use. You can use these modules to write programs quickly and hence develop can be done quickly with less errors due to exception handling system of java. But Java does have some drawbacks like slow performance and large memory usage.