HomeHome  FAQFAQ  SearchSearch  RegisterRegister  MemberlistMemberlist  UsergroupsUsergroups  Log in  

Share | 
 

 Beginners

Go down 
AuthorMessage
sojan

avatar

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

PostSubject: Beginners   Sun 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
View user profile http://sojanctherakom.googlepages.com
sojan

avatar

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

PostSubject: Re: Beginners   Mon 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
View user profile http://sojanctherakom.googlepages.com
sojan

avatar

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

PostSubject: Re: Beginners   Mon 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
View user profile http://sojanctherakom.googlepages.com
sojan

avatar

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

PostSubject: Re: Beginners   Mon 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
View user profile http://sojanctherakom.googlepages.com
John



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

PostSubject: Re: Beginners   Mon 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
View user profile
sojan

avatar

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

PostSubject: Re: Beginners   Mon Mar 05, 2007 4:52 pm

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

avatar

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

PostSubject: Re: Beginners   Mon Mar 05, 2007 5:03 pm

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



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

PostSubject: Re: Beginners   Mon 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
View user profile
John



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

PostSubject: Re: Beginners   Mon 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
View user profile
sojan

avatar

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

PostSubject: Re: Beginners   Mon Mar 05, 2007 10:59 pm

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



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

PostSubject: Re: Beginners   Tue 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
View user profile
sojan

avatar

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

PostSubject: Re: Beginners   Tue Mar 06, 2007 1:55 pm

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




PostSubject: Re: Beginners   

Back to top Go down
 
Beginners
Back to top 
Page 1 of 1
 Similar topics
-
» Selenium tutorials for beginners/newbie
» Selenium Videos
» Beginner Selinium Webdriver
» Social Engineering Tutorial

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