aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes use of new keyword.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "use of new keyword.." Watch "use of new keyword.." New topic
Author

use of new keyword..

deepesh mathur
Ranch Hand

Joined: Aug 13, 2007
Posts: 39
guys i want to know that where the new keyword can be used (if possible kindly let me know all of its uses)
abhishek pendkay
Ranch Hand

Joined: Jan 01, 2007
Posts: 184
new keyword is used when you want to create an object of any class ie to call the constructor of that class for eg to create an object of the Thread class you would use the new keyword like this
Thread myThread = new Thread()


The significant problems we face cannot be solved by the same level of thinking which created them – Einstein
SCJP 1.5, SCWCD, SCBCD in the making
deepesh mathur
Ranch Hand

Joined: Aug 13, 2007
Posts: 39
Hey abhishek,
i think new keyword is also used for instating
1. arrays
2. string
(kindly tell any more if you know)
abhishek pendkay
Ranch Hand

Joined: Jan 01, 2007
Posts: 184
yes new is also used for creating arrays and strings because in JAVA arrays and strings are objects.... everything in java (except for primitive data types) is an object and that is why to make an array or string you use the new keyword.... although JAVA does allow you to create strings without using the new keyword but even then strings in JAVA are objects
Vidhya Ramaswamy
Ranch Hand

Joined: Oct 10, 2007
Posts: 65
--------------------------------------------------------------------------------
guys i want to know that where the new keyword can be used (if possible kindly let me know all of its uses)
--------------------------------------------------------------------------------
The 'new' keyword can be used in conjunction with an object reference, or without

eg. String s = new String("new String");
or
new String("another String");

Note that both ways of using the new keyword to instantiate an object are legal, but in the second case, you will not be able to access the String object later since there is no reference.
deepesh mathur
Ranch Hand

Joined: Aug 13, 2007
Posts: 39
hey ,
abhishek and vidhya thanks a lot..
Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
Note that new may also be used with slightly different syntax to instantiate an inner class:

[ November 05, 2007: Message edited by: Kelvin Lim ]

SCJP 5.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: use of new keyword..
 
Similar Threads
Is "false" a keyword in java
System.out.println
regarding protected scope
constructor
modifiers