Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  SearchSearch  Latest imagesLatest images  RegisterRegister  Log in  

 

 Beginners

Go down 
2 posters
AuthorMessage
sojan

sojan


Number of posts : 29
Age : 40
Registration date : 2007-03-04

Beginners Empty
PostSubject: Beginners   Beginners EmptySun Mar 04, 2007 3:42 am

Difference??

System.out.print("Hello world");

System.out.println("Hello world");

//"println" makes a new line.


Last edited by on Mon Mar 05, 2007 5:13 pm; edited 1 time in total
Back to top Go down
http://sojanctherakom.googlepages.com
sojan

sojan


Number of posts : 29
Age : 40
Registration date : 2007-03-04

Beginners Empty
PostSubject: Re: Beginners   Beginners EmptyMon Mar 05, 2007 3:09 pm

'\n' will also work for making new lines

so it will look like..
System.out.print("Hello world \n"); bom


Last edited by on Mon Mar 05, 2007 4:44 pm; edited 1 time in total
Back to top Go down
http://sojanctherakom.googlepages.com
sojan

sojan


Number of posts : 29
Age : 40
Registration date : 2007-03-04

Beginners Empty
PostSubject: Re: Beginners   Beginners EmptyMon Mar 05, 2007 4:15 pm

Tired of typing :-“System.out.println()”


out” in “System.out” is a static PrintStream object, you can do this easily by creating a PrintStream variable, assign “System.out” to it, and reference that object from the new variable.

example:-

import java.io.*;

class Helloworld
{
private static PrintStream out = System.out;

public static void main(String args[])
{
out.println("Hello world");

}
}
Back to top Go down
http://sojanctherakom.googlepages.com
sojan

sojan


Number of posts : 29
Age : 40
Registration date : 2007-03-04

Beginners Empty
PostSubject: Re: Beginners   Beginners EmptyMon Mar 05, 2007 4:40 pm

So now you may also be eager to know what public static void main(String[] args) is for...?


public
The keyword public indicates that the method can be called by any object

static
The keyword static indicates that the method is a class method, which can be called without the requirement to instantiate an object of the class

void
The keyword void indicates that the method doesn't return any value.

args
The formal parameter args is an array of type String, which contains arguments entered at the command line.

Remember that the args parameter is mandetory.

The length Property
In Java, args is a true array object. Array objects have a property named length.

The runtime system monitors for the entry of command-line arguments by the user and constructs the String array containing those arguments.

Processing Command-Line Arguments
The args.length property can be used by the code in the program to determine the number of arguments actually entered by the user.

If the array of strings contains data, the first string in the array corresponds to the first argument


Last edited by on Mon Mar 05, 2007 5:28 pm; edited 1 time in total
Back to top Go down
http://sojanctherakom.googlepages.com
John




Number of posts : 7
Registration date : 2007-03-03

Beginners Empty
PostSubject: Re: Beginners   Beginners EmptyMon Mar 05, 2007 4:44 pm

Can i get help for java packages. If there is any website please send reply soon.
i got some websites, but its not giving me the basics.
Back to top Go down
sojan

sojan


Number of posts : 29
Age : 40
Registration date : 2007-03-04

Beginners Empty
PostSubject: Re: Beginners   Beginners EmptyMon Mar 05, 2007 4:52 pm

Back to top Go down
http://sojanctherakom.googlepages.com
sojan

sojan


Number of posts : 29
Age : 40
Registration date : 2007-03-04

Beginners Empty
PostSubject: Re: Beginners   Beginners EmptyMon Mar 05, 2007 5:03 pm

Refer...JAVA.. Complete Reference Book
Back to top Go down
http://sojanctherakom.googlepages.com
John




Number of posts : 7
Registration date : 2007-03-03

Beginners Empty
PostSubject: Re: Beginners   Beginners EmptyMon Mar 05, 2007 5:42 pm

Mr.Sojan thanks for ur reply. hope u are here always for helping me.
Back to top Go down
John




Number of posts : 7
Registration date : 2007-03-03

Beginners Empty
PostSubject: Re: Beginners   Beginners EmptyMon Mar 05, 2007 6:45 pm

please help me

public void createConnection(){
try {
initCtx = new InitialContext();
envCtx = (Context)initCtx.lookup("java:comp/env");
}catch (Exception e) {
e.printStackTrace();
System.out.println("Context not established");
}

//Look up the data source
try{
ds = (DataSource)envCtx.lookup("jdbc/mydatabase");
conn = ds.getConnection();
} catch(Exception e){
e.printStackTrace();
System.out.println("DataSource not allocated");
}

after querying the database I close the connection using conn.close()

Any help regarding this will be very useful.
Back to top Go down
sojan

sojan


Number of posts : 29
Age : 40
Registration date : 2007-03-04

Beginners Empty
PostSubject: Re: Beginners   Beginners EmptyMon Mar 05, 2007 10:59 pm

actually wat u wanna kno?
Back to top Go down
http://sojanctherakom.googlepages.com
John




Number of posts : 7
Registration date : 2007-03-03

Beginners Empty
PostSubject: Re: Beginners   Beginners EmptyTue Mar 06, 2007 10:30 am

I want to know how to close the database while using try catch. I close the database connection using conn.close(). but its giving some fatal error. And if i didnt close the database connection its asking for it.

please see to this.
Back to top Go down
sojan

sojan


Number of posts : 29
Age : 40
Registration date : 2007-03-04

Beginners Empty
PostSubject: Re: Beginners   Beginners EmptyTue Mar 06, 2007 1:55 pm

put your catch exception after closing your connection.
Back to top Go down
http://sojanctherakom.googlepages.com
Sponsored content





Beginners Empty
PostSubject: Re: Beginners   Beginners Empty

Back to top Go down
 
Beginners
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
 :: Programming Languages :: JAVA-
Jump to: