How many Objects created??
Hi Friends,
I am really confused with this question,can someone please tell me how many objects would be created by the following code??My answer is two("java" on the heap and the normal new String() Object),am i right???
public class Objects{
public static void main(String[] args) {
String one = "Java";
String two = "Java";
String three = "J" + "a" + "v" + "a";
String four = new String("Test");
}Thanks
Probably not, since all the operands are string
literals. The compiler probably sees that and instead
generates the same bytecode that it would have if it
had been coded as: "Java" in the first place. But
again, still stupid and pointless.just what i wanted to say but was a bit slow. maybe it's stupid and pointless,
but for grins, i am attaching the constants pool from the class file that was
obtained by compiling the code in post 1 with Sun's compiler. I don't see any
"J" or "a" or .........
pool index: 1 type: 10 class index: 7 name index: 16 value: null
pool index: 2 type: 8 class index: -1 name index: 17 value: null
pool index: 3 type: 7 class index: -1 name index: 18 value: null
pool index: 4 type: 8 class index: -1 name index: 19 value: null
pool index: 5 type: 10 class index: 3 name index: 20 value: null
pool index: 6 type: 7 class index: -1 name index: 21 value: null
pool index: 7 type: 7 class index: -1 name index: 22 value: null
pool index: 8 type: 1 class index: -1 name index: -1 value: <init>
pool index: 9 type: 1 class index: -1 name index: -1 value: ()V
pool index: 10 type: 1 class index: -1 name index: -1 value: Code
pool index: 11 type: 1 class index: -1 name index: -1 value: LineNumberTable
pool index: 12 type: 1 class index: -1 name index: -1 value: main
pool index: 13 type: 1 class index: -1 name index: -1 value: ([Ljava/lang/String;)V
pool index: 14 type: 1 class index: -1 name index: -1 value: SourceFile
pool index: 15 type: 1 class index: -1 name index: -1 value: Objects.java
pool index: 16 type: 12 class index: 9 name index: 8 value: null
pool index: 17 type: 1 class index: -1 name index: -1 value: Java
pool index: 18 type: 1 class index: -1 name index: -1 value: java/lang/String
pool index: 19 type: 1 class index: -1 name index: -1 value: Test
pool index: 20 type: 12 class index: 23 name index: 8 value: null
pool index: 21 type: 1 class index: -1 name index: -1 value: Objects
pool index: 22 type: 1 class index: -1 name index: -1 value: java/lang/Object
pool index: 23 type: 1 class index: -1 name index: -1 value: (Ljava/lang/String;)Vwalker
Similar Messages
-
How many Objects are created in this?
Hi,
How many objects are created in the flwg code:
String str = new String("Hello");
String str2 = "Hey there";
str = str + str2;Depends if you're counting objects created at compile time.
"Hello" is created at compile time. That's 1.
new String("Hello") creates a new String object at runtime, pointing its backing array at the "Hello" in the constant pool. That's 2.
"Hey there" is created at compile time. 3.
str + str2 I might do everything at compile time, or it might do some at runtime. I don't know if str is considered a compile time literal here. I think not, but I'm not sure. You can check by using javap. If I'm correct, then at runtime you'll create a StringBuffer (4) and another String (5).
So I'd say 5 objects. But if the compiler treats str as a literal and therefore can do the str+str2 at compile time, then it might do so without creating the StringBuffer. Or it might still create it at compile time, use it, and throw it out. -
How many objects are created?
I have this question which some one posted to me.
He asked me how many objects are created when an object of a simple class is created for example
class A{
public static void main(String args[])
A a1 = new A();
Now how many objects are created? I think only one. Can anyone tell me if any other objects are also created.
Plz tell me .No, the answer is indeed 1. All the other objects
(including the String[] in the main method
parameters) are created outside of the A
class, either by the JVM itself or by some other
class that calls the A.main() method. You can try
this out for yourself by adding a constructor such as
A()
System.out.println("Creating class A");
} and see what prints out.Take a closer look at the question:
how many objects are created when an object of a
simple class is created for exampleIt doesn't say "how many objects of type A are created".
I.e. The VM has to load class A before you can create an object from it, and thus an object of type Class is created. There are also a bunch of other objects which needs to be created before you can instantiate A.
Kaj -
How many objects will be created due to constructor chaining
Consider this case
ChildClass obj = new ParentClass();
I would like to know how many objects will be created in this process.Consider this case
ChildClass obj = new ParentClass();
I would like to know how many objects will be created
in this processThe simple answer is one.
The complex answer is many.
In terms only of the classes that your code represents conceptually there will be one.
The reality is that the the object itself might create objects. And loading the classes, if it has not already occurred will also create objects. -
In query, how many objects can include in structure
Hi expert,
In BEX query coloum, How many objects can include in structure.Hi Sunil,
We can include maximum of 999 fields in one structure.
http://help.sap.com/saphelp_nw04/helpdata/en/4d/e2bebb41da1d42917100471b364efa/frameset.htm
Regards,
Venkatesh -
I need to know how many objects i got selected
Hi all,
I need to know how many objects i got selected for a particular issue and ussualy are too many to count one by one. I know that this information is provided in other software like Corel or Freehand, but I didn't find out how to get this info in Illustrator.
Any idea?
ThanksOpen the Document Info palette.
From its flyout menu, turn on Selection Only and Objects.
The palette will not remember those settings. You have to re-select them every time you relaunch Illustrator.
The Document Info palette is a half-baked hack, tagged-on to display a subset of the information in the normally-hidden programmer's window, instead of incorporating the data properly into the program's interface. So it's another completely unintuitive grab-bag of important information that everyone needs, but no one would expect to look for there.
JET -
How can I tell how many objects are selected when I draw a selection marque around multiple objects?
Open the Document Info Palette.
Find its secret little flyout menu.
Select from that menu "Objects".
Let go.
Then go to that same menu all over again and select "Selection Only".
Scroll through the list and sum the quantities shown. Except be careful not to include the count of "All Text Objects" with the counts of "Point Type Objects", "Area Type Objects", and "Type On A Path Objects".
Repeat those steps every time you start a new work session in AI, because AI's palettes can't remember the way you set them between launches.
How could you have overlooked that intuitive and straightforward routine?
JET -
Seing how many objects are selected.
Hi! I'm having a problem seing how many objects are selected when I navigate in Finder's windows. In Snow Leopard, there used to be a grey bar at the bottom telling you these infos, but this seems to be gone in Lion. Anyone knows how to get it back?
Thank you!Open the Document Info Palette.
Find its secret little flyout menu.
Select from that menu "Objects".
Let go.
Then go to that same menu all over again and select "Selection Only".
Scroll through the list and sum the quantities shown. Except be careful not to include the count of "All Text Objects" with the counts of "Point Type Objects", "Area Type Objects", and "Type On A Path Objects".
Repeat those steps every time you start a new work session in AI, because AI's palettes can't remember the way you set them between launches.
How could you have overlooked that intuitive and straightforward routine?
JET -
How many instance created for 100 request in servlet?
Let me know the answer
STM12 wrote:
Subject: how many instance created for 100 request in servlet?
Let me know the answerInstances of what? -
Trying to keep track of how many objects I create
Hello everyone I'm trying to keep track of how many message objects I created and Assign them to a data member.
Right now it assigns all the Message objects the same number at the end which is 3. I wanted it to assign 1 to the first object it create, 2 for the 2nd, and 3 for the 3rd.
here's a small version of my code:
package ss;
import java.util.ArrayList;
import java.util.Iterator;
public class MainTest {
public static void main(String [] args)
Message msg = null;
ArrayList<Message> msgList = new ArrayList<Message>();
for(int i = 0; i < 3; i++)
msg = new Message();
msgList.add(msg);
System.out.println(msgList);
package ss;
//this class will hold the Event/Message
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.Set;
import java.util.Iterator;
public class Message {
//these are datamembers that will be used during
//the sending of the message to the reciever
//PacketID should be incremented each time a new message is created
static int PacketID = 0;
Message()
PacketID +=1;
public String toString() {
return("PacketID: " + this.PacketID
+ "\n");
}output:
[PacketID: 3
, PacketID: 3
, PacketID: 3
Any ideas what I'm doing wrong?
Thanks!Thanks BigDaddyLovehandles,
Well there's the problem, I just posted a simpler problem to a bigger one. So I am keeping them in a collection as you can see below.
I'm keeping these message stored in a multi map, and it is multi-threaded. Everytime a user connects to my server I create a new thread, and start adding the "messages" to the database.
But I must have a packetID, meaning every new message created I need to assign that number to the message object.
I also see a problem with this like you said, its not thread safe, if 2 clients connect to the server, and both send me events, there are going to be 2 different maps, copying events from the client and storing them in their own seperate databases.
This might not be a problem because after I get the events on each thread, i send them to another server for processing.
Here's an example of what my database looks like that stores the messages:
//this class should store all the Messages or "Events" and
//you can access them based on their Serial key.
public class MessageDB {
//database to hold the information
// holds the Alerts/messages
Map<String, List<Message>> AlertMap;
//Constructor
MessageDB() {
AlertMap = new HashMap<String, List<Message>>();
//print, outputs the contents of the hashMap
public void print() {
//want to print out the Key and all the Messages
//associated with that key
//print, outputs the contents of the hashMap
for (String key : AlertMap.keySet())
System.out.println("\n\nSerial (key): " + key
+ "\nValues in Map: \n" + AlertMap.get(key));
void add(Message msg) {
//getting the position of the List by EntityID if avaiable
List<Message> AlertList = AlertMap.get(msg.Serial);
//checking to see if there is a unique Key already in the Map.
if (AlertList == null) {
//if there isnt a key in the map, add a new key, and a new List mapping
//to the key EntityID;
AlertList = new ArrayList<Message>();
AlertMap.put(msg.Serial, AlertList);
AlertList.add(msg);
} else {
//adding message to List
AlertList.add(msg);
}Any suggestions on what I can to number all these messages and it will be thread safe? -
Garbage Collection: how many objects are created after for loop?
Please see the fallowing java code
1 public class Test1 {
2
3 public static void main(String[] args) {
4
5 MyObj obj = null;
6 for(int i=0;i<5;i++){
7 obj = new MyObj();
8 }
9 // do something
10
11 }
12 }
so my question is How may objects are eligible for garbage collection at line no: 9 (// do something)?so my question is How may objects are eligible for
garbage collection at line no: 9 (// do something)?It's impossible to answer that question since we don't know how MyObj is implemented.
Kaj -
How many objects are in my map?
hi all
I nead help in a question about maps in java:
In one map could be stored various references with diferent keys to just one real object. How can i count all objects referenced by my map? (not all references with map.size())
Is it wise to use a set parallel to the map who contains just unique objects? Or is there an other, more beautiful solution?
many thanx for your help
benjaminIf you want a more general solution you can use an interface. Now you can store any class in MyMap as long as it implements RefCount.
interface RefCount {
int getRef();
void incRef();
void decRef();
class MyValue implements RefCount {
private int ref;
public int getRef() {return ref;}
public void incRef() {ref++;}
public void decRef() {ref--;}
class MyMap extends HashMap {
int objects = 0;
public Object put(Object key, Object value) {
RefCount v = (RefCount) value;
if (v.getRef() == 0)
objects++; // first time inserted
v.incRef();
return super.put(key,value); // call superclass put
public Object remove(Object key) {
RefCount v = (RefCount) super.remove(key); // super class remove
if (v != null) {
v.decRef();
if (v.getRef() == 0)
objects--; // last time removed
return v;
public int objectSize() { // returns number of objects.
return objects; -
How Many Connections Created???
We have a customer running WLS 5.1 on Solaris vs. Oracle 8.1.6. Here is the configuration
for the connection pool:
weblogic.jdbc.connectionPool.ewDBConnectionPool=\
url=jdbc:weblogic:oracle,\
driver=com.manu.es.db.ESWeblogicDriver,\
loginDelaySecs=1,\
initialCapacity=4,\
maxCapacity=10,\
capacityIncrement=2,\
allowShrinking=true,\
shrinkPeriodMins=15,\
refreshMinutes=10,\
testTable=dual,\
Note that com.manu.es.db.ESWeblogicDriver just extends weblogic.jdbc.oci.Driver
with some static properties to allow the driver to find our license.
Given the small maximum number of connections, how do we explain this excerpt
from the weblogic log:
Wed Feb 27 19:39:32 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:33 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:34 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:35 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:36 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:37 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:38 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:39 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:40 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:41 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:42 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:43 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:45 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:46 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:47 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:48 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:49 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:50 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:51 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:52 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:53 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:54 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:55 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:56 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:58 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:59 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:40:00 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:40:01 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:40:02 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:40:03 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:51:05 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:51:06 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
..and it continues on from there...
Thanks in advance for any enlightenment.
MarkMark Shaffer wrote:
We have a customer running WLS 5.1 on Solaris vs. Oracle 8.1.6. Here is the configuration
for the connection pool:Hi. Odd. My guess is that multiple user threads all hit the pool at the same time when it had none
available, so each thread simultaneously created 2 more connections. In other words, it may be a
synchronization bug in the pool to allow this. Another factor may be that if the refresh testing
is going on at that time, it may have temporarily reserved all the unused connections, causing the
need for more. For stability and performance I recommend having the pool make all it's connections
at startup (init=max), and not shrink, and to have testConnsOnReserve true, and to effectively turn
off refresh by setting the time to 9999999.
Joe
>
>
weblogic.jdbc.connectionPool.ewDBConnectionPool=\
url=jdbc:weblogic:oracle,\
driver=com.manu.es.db.ESWeblogicDriver,\
loginDelaySecs=1,\
initialCapacity=4,\
maxCapacity=10,\
capacityIncrement=2,\
allowShrinking=true,\
shrinkPeriodMins=15,\
refreshMinutes=10,\
testTable=dual,\
Note that com.manu.es.db.ESWeblogicDriver just extends weblogic.jdbc.oci.Driver
with some static properties to allow the driver to find our license.
Given the small maximum number of connections, how do we explain this excerpt
from the weblogic log:
Wed Feb 27 19:39:32 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:33 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:34 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:35 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:36 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:37 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:38 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:39 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:40 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:41 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:42 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:43 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:45 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:46 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:47 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:48 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:49 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:50 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:51 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:52 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:53 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:54 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:55 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:56 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:58 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:39:59 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:40:00 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:40:01 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:40:02 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:40:03 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:51:05 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
Wed Feb 27 19:51:06 CET 2002:<I> <JDBC Pool> Connection for pool "ewDBConnectionPool"
created.
..and it continues on from there...
Thanks in advance for any enlightenment.
Mark -
How can I see how many objects will be syncronized to Windows Azure
Hi
How can I count the number of objects DirSync will syncronize to Windows Azure Active Directory (Office365)
I wan't to know this number before installing DirSync so I can decide if we can use SQL express og we need the full SQL server install ?The Office365 Deployment Readiness Tool will tell you this.
Mike Crowley | MVP
My Blog --
Planet Technologies -
How many objects exist in this situation?
class A {
class B {
public A getA() {
return new A();
public static void main(String[] args) {
B blah = new B();
}I guess what I'm really asking is does an object A exist even if I haven't called the method getA()?You create a new object each time you call new (or clone).
Maybe you are looking for
-
RA data only updated in Controlling Area currency..
Hi Guys, When we run the Results Analysis for WBS Elements, we are getting the message " RA data only updated in Controlling Area Currency ". How can we make this message gone or why is the system updating only in CO Area Currency. Thanks Srik.
-
Do I still need to use the old mobile me backup system for backing up all my data and having it able to get at in case of a crash, or can the icloud reset everything? Because I can not find any structured refrence, as to how it would be done. I am up
-
Hellow. I created BW Reports using level up/down. It's appeared user ID and Password popup window when excel file opened after export as ms excel in the web reports. Thers is no problem without level up/down. Would you help how pass ID/password popup
-
Error Code Add On annoying notification
How can I get rid of this annoying notification, popping up since two weeks. I' ve already tried what Adobe suggested. I installed the old CS 6, I installed the add on but sit this notification is popping up after every restart. Error Code: -403, -41
-
ToArray error: cannot resolve symbol
Hi ther, I am getting errors on the line: newArray = (char[]) newArrayList.toArray(new char[newArrayList.size()]); I am getting the following error: vowelProcess.java:176: cannot resolve sybmol Symbol : method toArray (char[]) Location : class java.u