Java Wrapper Classes are immutable?
Hi guys,
The one artichle i have read it says wrapper classes are immutable and once you assign a value to a variable(wrapper class type) you wont be able to change that value ,also ;
Integer myInt=new Integer(5);
myInt=10;//i change it no problem showed up.also why it says wrapper classes are immutable?
//how the java works at the background and change it for us what methods does it use to change the value?
//why java made wrapper classes as immutable?Thanks.
Garibanus wrote:
Hi guys,
The one artichle i have read it says wrapper classes are immutableAnd it was correct in saying that.
and once you assign a value to a variable(wrapper class type) you wont be able to change that valueThat has nothing to do with imutability. If the article said that, it's wrong. If it said that assigning a reference variable to point to an object has anything to do with that object's imutability, it was wrong.
Immutability has to do with the state of an object, not with references that point to it.
Similar Messages
-
Where are the Java API classes?
Hello All,
I understand that Oracle9i uses a Java API different than those older classes found in sdoapi.zip here on the OTN.
Problem is, I don't know where to find them in my newly-installed 9iR2.
Can anyone help me with this simple question or point me to appropriate documentation?
Thanks!
-- johnI believe the new Java API classes are slated for 10i.
-
What is the advantage of using Wrapper Classes ?
Hi friends,
I am happy to join Java/J2EE tech. My project is scaled over the network. MVC-II struts, EJB based architecture, we are using.
We are asked to use Wrapper Classes in in Java programs and not the primitive data types. I could not understand the reason.
Pls tell me what is the advantage of using Wrapper Classes over the primitive data types ?
means Integer instead of int, etc....Hi friends,
I am happy to join Java/J2EE tech. My project is
scaled over the network. MVC-II struts, EJB based
architecture, we are using.
We are asked to use Wrapper Classes in in Java
programs and not the primitive data types. I could
not understand the reason.
Pls tell me what is the advantage of using Wrapper
Classes over the primitive data types ?
means Integer instead of int, etc....I am not sure why use Integer over int; but Wrapper classes are used to remove coupling between classes and create one hand doesn't know what the other hand does effect.
for example:
when you have a SFTP java package but doesn't do everything that your application needs to do in one step and you need to do sftp stuff at many places in your application, it would be wise not to use SFTP java package directly from all the classes that need to do sftp stuff. Because if you were to change the SFTP package later due to say some bug fix or newer version or ... you would have to go and modify all the classes that had sftp stuff to update.
Instead you could write a custom sftp wrapper that handles all the sftp stuff for your application needs and that wrapper deals with the SFTP java package. So all the classes don't need to know which SFTP java package is being used only the custom-wrapper needs to know. -
What exactly is a wrapper class?
In so far as Integer, Byte, Double et al. are concerned I understand that those wrapper classes are a way to handle primitive types as objects. But I've come across references to wrapper classes in documentation and other technical articles and I don't think I really understand what they are really used for. Why do you need a wrapper class for an object?
Could someone shed me some light on this issue?
Thanks,
JohnAn instance of a wrapper class holds a pointer to and instance of some other class or interface and provides access to it, typically supplying methods equivalent to all the methods of the underlying type.
The basic wrapper class a functional replacement for the underlying object.
When you're passed an object from some code outside your control you often don't know what exact class it is, or have access to it's class definition.
A wrapper object allows you to modify the functionality of such an object. You can extend the wrapper class, for example, adding extra methods. Or you can modify the methods, for example to provide logging of calls made.
As a concrete example, I have a wrapper class LoggedConnection which wraps a java.sql.Connection object. It also implements java.sql.Connection. If you ask a LoggedConnection for a Statement or PreparedStatement it fetches the appropriate object and returns a wrapped version which logs the SQL and the execution times etc..
My "get me a connection" routine can return either a raw Connection or a LoggedConnection according to whether a SQL log file is provided.
The main program doesn't need to know if it's using a genuine Connection object or the wrapped version.
Part of the definition would look like:
public class LoggedConnection implements Connection {
private Connection wrappee;
public LoggedConnection(Connection con) {
wrapee = con;
public createStatement() throws SQLExeception {
return new LoggedStatement(wrappee.createStatement())
}(Of course this was tedious to write by hand because Connection has so many methods, all of which the wrapper must implement. Later I wrote a java program to generate Wrapper classes). -
Why to use wrapper class?
hello,
can anybody please tell me why wrapper class are used in JAVA and what are exactly wrapper class?
reply me soon....I want to give an example and then explain why it is for. Primitives will be good example for this situation.
Example:
Below are the primitive types and their wrapper classes...
Primitive to Wrapper Class
byte - Byte
short - Short
int - Integer
long - Long
char - Character
float - Float
double - Double
boolean - Boolean
USING OBJECT CREATION
Think a situation when you create an integer object using this code:
---> Integer intVar = new Integer();
you have the methods and constants:
1 MAX_VALUE ,
2 MIN_VALUE ,
3 byteValue() ,
4 compareTo(Integer anotherInteger) ,
5 compareTo(Object o) ,
6 decode(String nm) ,
7 doubleValue() ,
8 equals(Object obj) ,
9 floatValue() ,
10 getInteger(String nm) ,
11 getInteger(String nm, int val) ,
12 getInteger(String nm, Integer val) ,
13 hashCode() ,
14 intValue() ,
15 longValue() ,
16 parseInt(String s) ,
17 parseInt(String s, int radix) ,
18 shortValue() ,
19 toBinaryString(int i) ,
20 toHexString(int i) ,
21 toOctalString(int i) ,
22 toString(),
23 toString(int i) ,
24 toString(int i, int radix) ,
25 valueOf(String s) ,
26 valueOf(String s, int radix)
now you have an object with 2 constants and 24 methods.
USING WRAPPER CLASS
and think using wrapper class of Integer..
CODE ---> int intVar = Integer.parseInt((String)someStringData);
In this case your Integer object have the methods and constants
1 MAX_VALUE ,
2 MIN_VALUE ,
3 parseInt(String s) ,
4 parseInt(String s, int radix) ,
5 toBinaryString(int i) ,
6 toHexString(int i) ,
7 toOctalString(int i) ,
8 toString(int i) ,
9 toString(int i, int radix) ,
10 valueOf(String s) ,
11 valueOf(String s, int radix)
as you in this situation you have 2 constants and 9 methods.
AS YOU SEE THERE ARE 15 METHODS DIFFERENCE FROM THE OBJECT AND THE WRAPPER CLASS OF INTEGER OBJECT.
NOW TALKING ABOUT PRIMITIVE TYPES ALL PROGRAMMERS USED THIS TYPES FOR THEIR CODES AND THEY ALWAYS NEED SOME THIS KIND OF CASTING. IN MY EXAMPLE I TAKE THE VALUE OF AN STRING VARIABLE. AND THERE ARE LOTS OF THINGS SIMILIAR TO THIS EXAMPLE.
IDEA OF THIS WRAPPER CLASSES IS THAT USE AS YOU NEED NOTHING MORE. IN THE WRAPPER CLASS YOU DONT HAVE INTEGER OBJECT. YOU ONLY NEED THE PARSEINT METHOD OF INTEGER OBJECT INSTEAD OF CREATING THE INTEGER OBJECT YOU USE THE WRAPPER CLASS OF THIS TYPE...
OBJECTS ARE STORED IN A MEMORY PLACE CALLED HEAP WHICH IS PLACED ON RAM AND GARBAGING OF THIS OBJECTS TAKES MORE TIME TO ALLOCATE FROM HEAP STORAGE.
AND ANOTHER NOTE FOR THIS WRAPPER CLASSES if you want to store an int inside a container such as an ArrayList (which takes only Object references), you can wrap your int inside the standard library Integer class
EX:
import java.util.*;
public class ImmutableInteger {
public static void main(String[] args) {
List v = new ArrayList();
for(int i = 0; i < 10; i++)
v.add(new Integer(i));
// But how do you change the int inside the Integer?
} ///:~
GOOD LUCK...
REALKINGTA.... -
Hi,
I need one java wrapper class for html tags. If anyone is having such pls reply.
Thanks in advance
SisirLike java.lang.String?
You use it like this
String textTag = "text";
If that isn't what you had in mind then you might want to provide a bit more detail as to what you think it should do. -
Advantages and disadvantages of wrapper classes
Hi ,
will you please let me know what are the advantages and disadvantages of wrapper classes.
please do needful ASAP.
thanks in advanceHi Anil,
Wrapper classes are classes that allow primitive types to be accessed as objects.
Refer the foll Link:
http://www.cs.wustl.edu/~schmidt/PDF/Reactor1-93.pdf
http://whitepapers.silicon.com/0,39024759,60104914p,00.htm
Regards,
Sunil -
Advantages and disadvantages of wrapper class
Hi ,
will you please let me know what are the advantages and disadvantages of wrapper classes.
please do needful ASAP.
thanks in advanceHi Anil,
Wrapper classes are classes that allow primitive types to be accessed as objects.
Refer the foll Link:
http://www.cs.wustl.edu/~schmidt/PDF/Reactor1-93.pdf
http://whitepapers.silicon.com/0,39024759,60104914p,00.htm
Regards,
Sunil -
Hello,
we would like to trace an exception thrown by a wrapper class generated by the deployment of an entity bean. Where are these classes stored? Is there any possibility to keep the sources of the wrapper classes, or at least the class files to decompile them?
Regards
StefanStefan -- Wrapper classes are kept in the deployment.cache file under your specific application within the application-deployments directory. You can extract the files with either jar or winzip.
Thanks -- Jeff -
What are the uses of Void wrapper class?
Hi,
Similar to other Wrappers, Void is a wrapper class for the primitive ' void ' . We all know that Void is a final class , we can't instantiate it.
My Question is what are the uses of Void?
thanks,kajbj wrote:
I have at times used it in reflection and jmx.I have used them with SwingWorker if I didn't have anything interesting to return. There is also an example in the tutorial: [http://java.sun.com/docs/books/tutorial/uiswing/concurrency/simple.html] -
Could not load mediaLib accelerator wrapper classes. Continuing in pure Jav
Can anyone provide an explanation/solution to the following error message:
"Could not load mediaLib accelerator wrapper classes. Continuing in pure Java mode."This problem seems to occur if only the JAI JAR files are installed without the native DLL's. Is there some property that can be passed in to JAI so that it doesn't look for the DLL's? The lookup is causing quite a delay in initial server response time. We don't want to include the DLL's since they are a big pain for our customers to install and the performance issue is not a concern.
Thanks for any help!
-Matt -
What are Wrapper classes and what are they used for ?
What are Wrappter classes and what are they used for ?..Also, any examples would be great to understand this concept
Wrapper classes are used to enclose primitive data
types so that they can be used in instances where an
object is required. For example, if you want to add an
integer to an ArrayList, you can't use this:java.util.List al = new ArrayList();
int i=123;
al.add(i);because the ArrayList expects data of type object. In
order to all the integer to the ArrayList, you must wrap
it in the Integer wrapper class. This works:java.util.List al = new ArrayList();
int i=123;
al.add(new Integer(i));Hope that helps.
Mark -
Hi All,
I've created a java class to call a webservice. This has been developed and tested in JDeveloper and works ok (using JDev Wizards - so it's generated code). I've created the JAR from it, imported the classes into Forms Builder and have my package and imported the java exception_ class too.
So, everything compiles and looks good. When I run the application I can see in the console that my JAR is included in the loaded list. When I call the class (basing my code on the Forms Webservice example here on OTN) it doesn't work. I get the error ORA-6503 - function returns no value.
I can step through the code in debug and it's in the generated constructor "new" function when the JNI.NEW_OBJECT is executed. I can't see into that so I'm a bit stuck ... I don't whether it's my java that is now failing or the system is failing to call it :
FUNCTION new(
a0 VARCHAR2) RETURN ORA_JAVA.JOBJECT IS
BEGIN
args := JNI.CREATE_ARG_LIST(1);
JNI.ADD_STRING_ARG(args, a0);
RETURN (JNI.NEW_OBJECT('oracle/forms/atrium/wsexport/proxy/AtriumExportWSSoapHttpPortClient', '(Ljava/lang/String;)V', args));
END;Has anyone any experience or pointers for me ?
Are there any extra JAR files I need to include in the CLASSPATH ?
Forms Builder is 10.1.2.0.2, the Application Server is 10.1.2.3 and it JDeveloper 10 compiling Java 1.4. All on a Windows platform.
TIA
SteveNot sure if this is exact the document you are searching for, but this one works for me:
http://www.oracle.com/technetwork/developer-tools/forms/webservices-forms-11g-094111.html
It's for 11g, but I don't think there is much difference to 10g.
Did you add your Jar file also to the classpath in the environment file of your webconfig?
cheers
Edit: too slow somehow -.- heading for a cup of black coffee
Edited by: christian erlinger on 03.09.2010 01:18 -
How many classes are used in java versions?...
sun microsystems have released many java version...
how many build in classes are used java version 1.2 ,1.3 etc ...Arun02006 wrote:
sun microsystems have released many java version...
how many build in classes are used java version 1.2 ,1.3 etc ...No idea why you should want to know... Anyway, download them and look inside the zip file that holds the source codes.
You can download older Java versions here: [http://java.sun.com/products/archive/] -
Does Java load a class in caché ? New compiled class are not used .
I run my application (using java.exe + 'my class').
One 'Mybutton' launch a new class Frame based, with one button on it. I see this Frame and close it.Ok.
Now a put a new button in this Frame ( I have 2 buttons then), I save it (and Eclipse compile it).
If a do click on 'Mybutton' I see the old Frame (with one button) not the new Frame with 2 buttons.
What happens ? Is there something like cache class loader? How to avoid this?
My intention is to try to test the changes inmediatly, but in this situation I must to close Myapp and re-run it ?
Some solution?
Thamk youJava classes are loaded by an Object called a ClassLoader. Each classloader permanently caches all the classes it loads, and always uses an already loaded class in preference to loading a new one.
When a program starts there's already a ClassLoader, the one that loaded your main class. It loads classes from the class path. It exists all the time the program is running.
You can create your own classloaders in the program and if you load your changeable class through one then then you can get a new version by creating a new classloader.
Typically you create an instance of URLClassLoader.
However you need to know that classloaders "delegate" loadClass requests before loading the class themselves, which means that if the class you request is on the class path, your URLClassLoader will get the system class loader to load it and it won't work. You need a special directory (typically called a repsitory) for classes you wish to load multiple versions of.
Maybe you are looking for
-
I just downloaded the 8.1 version. It was a 30+mb file. Previously I ran 4.0. So I drag the new Firefox icon into the Apps folder. It does its merge thing with the old version. Problem is when I click to open FF now, it always throws up this window a
-
Hello all, I am working with a MacBook purchased in 2009, OSX 10.6.8, processor: 2.13 GHz Intel Core 2 Duo, Memory: 2 GB 800 MHz DDR2 SDRAM. I recently downloaded and tried to install a game I had previously successfully installed from Gamehouse.com.
-
Problem in RFC - File Scenario
hi all, I am doing scenario in rfc to file where , rfc is taken as sender communication channel. what is the way to configure sender communication channel. with thanks Deva
-
Form2mail how do I set up the form to sent to a recipient selected from a drop-down menu?
I am trying to configure dreamweaver form2mail to be able to send the information submitted to individual employees. I would like the form to be set up where as you choose the recipient form a drop down menu and the only that recipient would receive
-
WRT160N Online Gaming connection spikes
When i play games online such as Americas Army or other FPS games i get good pings to servers (sub 40ms) but i still get spikes of lag every minute or so. I first started getting this some time ago with my old WRV54G and could find no way to fix it s