HELP on object duplication!
Hi, I'm having some troubles when I try to make some local modifications while keeping the main array intact. My code looks like this
classname [] P = new classname [constant]
classname temp = P[2];
.I noticed that whenever I change temp P[2] is also changed, so I tried this
classname [] P = new classname [constant]
classname [] Pcopy = P.clone();
classname temp = Pcopy[2]
.But even in this case P[2] was modified whenever an operation on temp is applied? How do I get around this nasty problem?
Thanks a lot!!!
abrli wrote:
Hi, I'm having some troubles when I try to make some local modifications while keeping the main array intact. My code looks like this
classname [] P = new classname [constant]
classname temp = P[2];
.I noticed that whenever I change temp P[2] is also changed, so I tried thisYes. Because P[2] and temp both hold references to the same object. A variable's value is never an object in Java, just a reference to an object. When you do x = y you're copying a reference, not an object, so now two references point to the same object.
classname [] P = new classname [constant]
classname [] Pcopy = P.clone();
classname temp = Pcopy[2]
.But even in this case P[2] was modified whenever an operation on temp is applied?Right. Because you've not copied the array, which contains references. You now have two arrays of references pointing to the same objects. P[0] points to the same object as Pcopy[0], etc.
How do I get around this nasty problem?
temp = P[2].clone();
// OR
temp = new WhateverThatClassIs(P[2]);Note that this will copy the object that P[2] points to, but if it has member variables that point to mutable objects, and if you might be changing those objects' states, and if you don't want that change to be reflected in both P[2] and temp, you'll need to clone or copy-construct those as well.
Finally, as a side note, class names should start with uppercase and variables with lowercase. Constants should be all upper
classname [] P = new classname [constant]
// should be
Classname [] p = new Classname [CONSTANT]
Thanks a lot!!!
Similar Messages
-
Guidelines to help center objects and text in pages
Where are the guidelines to help centre objects and text in the new pages?
well YMMV. https://discussions.apple.com/thread/5472111?tstart=0
You have to do it manually. Also can be in the accomplished in the right hand column Format>Select your image>Arrange -
Hi all,
can any body tell to get F4 help for object attributes in table controls.
actually i got f4 help for object using SWO_DIALOG_OBJTYPE_VAL_REQUEST.
like this i want function module to get f4 help for attributes.Hello,
Please check the roles related to the below authorization object.
Authorization Object
S_WFAR_OBJ
Value
NV
Value
VBRK
Value
YP3INVOICE
Value
03
archiving Related role will give you access to View the billing document in PDF.
Thank you
Regards
Bala -
PCH: Value help for Object ID
Hi Experts,
I have a question regarding Logical Database PCH.
We know LDB PCH is OM based and we have default "Object ID field " and "Reporting period field " at the selection screen.
I have kept "Reporting period" as "Key date" 31.12.2010. I wanted to select an Org unit from the "Org. Structure Search" at the ""Object ID field " value help . But I can see the "Org. Structure" corresponding to "Today's date" all the time.
For eg: Org unit 1111111 was delimited on 01.01.2011. I wanted to se the Org. structure for 31.12.2010. So I put the key date as 31.12.2010. Since the above org. unit is delimited on 01.01.2011, it was expected to see in the Org. Structure at the "Object ID" value help . But unfortunately, it is not displayed, since the Org. Structure is shown based on Toda's date.
If anybody comes across such a scenario, please provide your inputs .
Thanks in advance,There is a search component that can be used for this purpose.
This is one function out of several. I don't have the complete implementation at hand but this will give you the first idea.
CALL METHOD cl_crm_uiu_prod_tools_search=>eh_onclosepopup_return_product
EXPORTING
ir_search_popup = search_popup
CHANGING
cr_context_node = lv_target_node
cv_index = gv_tableindex. -
WebDynpro Methods help for objects in ABAP editor
Hi,
is there a possibility to see the methods that can be used by an specific object?
For example which methods I can use with the object wd_this.
Thank You!You will need to drill into the underlying class to view its methods.
http://help.sap.com/saphelp_nw04s/helpdata/en/35/447741b0d6157de10000000a155106/frameset.htm
Regards,
Rich Heilman -
Need Help converting objects in a TreeMap to String
This app counts the number of times a word occurs in a document. I used a HashMap to store the key and value. The I sorted them using TreeMap. Now I need to return the key (String) and value (Integer Object) so they may be print like this -- 'key: value'.
Example:
that: 3
This mean the word 'that' appeared 3 times in the document. Below is my toString() method. TreeMap sorts everything for me but I cant return 'map' because it is not a String. So I iterated through each key and value in the map. But now I dont know how to put all the iterations into 1 String value. I would greatly appreciate any help. Code below.
Thanks in advance.
public String toString() {
Object key = null;
Object value = null;
map = new TreeMap(map);
Set getKeys = map.keySet();
Iterator iterKeys = getKeys.iterator();
while (iterKeys.hasNext()) {
key = (String)iterKeys.next();
value = map.get(key))
return; // i need to return a String here
} // end toString()
} // end classI dont remember posting to the "new Java forum", but I might have. My browser locked up on me so I am not sure what happened. If I did please excuse my double post.
Are you familar with a way to solve my problem? -
Help - draw objects doesn't appear on JFrame
i got this code from a book...
import javax.swing.*;
import java.awt.*;
class Ch5SampleGraphics {
public static void main( String[] args ) {
JFrame win;
Container contentPane;
Graphics g;
win = new JFrame("My First Rectangle");
win.setSize(300, 200);
win.setLocation(100,100);
win.setVisible(true);
contentPane = win.getContentPane();
g = contentPane.getGraphics();
g.drawRect(50,50,100,30);
the problem is when i run the app, the frame doesn't always show the rect drawn. sometimes it shows it, but usualy not. if it does show the rect, once i click on minimize, then reopen it from the taskbar, the rect will disappear again and will never show up.
can anyone help me? i've been searching for answers but to no avail. thanks 4 reading, hope someone will offer some help.an intoduction to oop with java
Jesus wept. The code's about as un-object-oriented as you could possibly make it.
Looking at his sample chapter on the book's web page all I see is main() methods with linear code in and just simple number crunching with primitive types. No objects to speak of at all.
I'm sticking with my "throw the book away" advice :o) -
Search help for OBJECT ID with Text Description for a query
I need to create search help for the field object text in HRP1000 - P1000-STEXT table in an infoset based on LDB PCH. Can anyone help me? I want it to appear on the adhoc query screen.
Thanks,look at search help FC_RFCDEST. that problem has already been solved with this search help.
-
CAF-GP: Need help restoring objects from trash
Hi All,
I've accidentally deleted a whole lot of development objects from GP Design Time (most of them from Life and Work Events - US folder), unaware of copying as copies and references. I spent hours restoring almost all of them to their original folders except for a few.
Could someone please help me identify, with the help of a reference portal, the original location of the following objects - as to where they belong in Public Folders?
Please find a screenshot of my trash here.
http://www.sendspace.com/file/omdo3o
I greatly appreciate any help. Please let me know if more info is required.
Cheers,
RajitI could restore most of the objects to their locations except some of them I believe to be copies.
-
Need help on object array, please.
Hello. I'm trying to write a program that stores student id numbers and their names into an array, and then prints them in numerical order. What I did was create an object called DSCC and put it in an array, but I'm having problems. Everytime I run this I get a null pointer exception, here is my code.
public class Main {
public Main() {
public void getStudenInfo(String Number1, String Name, int Number){
Number1 = JOptionPane.showInputDialog("Enter student number, 999 to quit");
Number = Integer.parseInt(Number1);
if(Number != 999){
Name = JOptionPane.showInputDialog("Enter student name");
public void putInArray(DSCC ded[], String na, int nu){
ded[0].studentname = na;
ded[0].studentnumber = nu;
System.out.println(ded[0]);
public void printList(){
public static void main(String[] args) {
String name = "";
String number1 = "";
int number = 0;
DSCC[] array = new DSCC[10];
Main main1 = new Main();
DSCC d = new DSCC();
main1.getStudenInfo(number1, name, number);
while(number != 999){
main1.putInArray(array, name, number);
main1.printList();
main1.getStudenInfo(number1, name, number);
public class DSCC {
String studentname;
String number1;
int studentnumber;
public DSCC() {
}There are a couple things i don't get about the code here but let me point out some thing that definately don't work.
The function getStudentInfo(...) does not change the value of its parameters Number1, Name and Number. You will need to redesign this method to get the entered values. I suggest breaking it up into three functions that return the value that the JOptionPane, like :
public String getStudentName(){
return JOptionPane.showInputDialog("Enter Student Name :");
}And then replace the calls to getStudenInfo() with the three calls.
Also the array you make is not populated, which is probably the reason for the for the NPE. For example,
DSCC[] array = new DSCC[10];
//here come an NullPointerException
array[0].studentName = "Joe";
//can't do this... array[0] == null, studentName does not exist!This happens in your code, though it is split up into different methods. If you trace through you will see that when you call the method putInArray(...) , the array's values are still null. For a fully intialized array, it should be:
DSCC[] array = new DSCC[10];
for(int i = 0; i < 10; i++) {
array[0] = new DSCC();
array[0].studentName = "Joe";So at some point you need to initialize the values of the array.
Hope that helps.... -
Need help regarding Objects ...
hi All,
I am new in SAP so kinda struggling however i've been learning alot with your posts & replies.. hope my query will help someone else too. My issue is
I've created an Object class using SU21, say name of the object class: Z_12 & in that i've created an object called Z_Test. Now i wanna know how do i put transactions in this particular Object.
Eagerly waiting for ur response !!
regards,
ManjiHi Sham,
Transaction can be secured in two ways.
--> using the default s_tcode check
--> By assigning an auth.object to the transaction.
Goto Se93--> enter the transaction code and click on the change button and assign the auth.object in the auth.object field.
Regards,
Ashok -
Help! Object Arrays...
Hi,
I'm a novice programmer trying to learn Java. I'm trying to solve a problem in a book I'm learning from - I can use arrays of primitive types with no problem, but I'm having some trouble with arrays of objects. To illustrate what I'm trying to do I'll write a very simple piece of code...I know this is cheesy but it's is only an example:
class Cat
public String name;
public int age;
public static void main( String[] args )
Cat fluffy = new Cat();
fluffy.name = "fluffy";
fluffy.age = 2;
}In the above example, I've created a class called Cat. It has two fields, 'name' and 'age'. In the main() method I create the object 'fluffy' and set his age to '2'.
That's fine and dandy, but lets say I own more than one cat and I dont want to explicitly create each one like that, so I'll create an array that references objects of the type 'Cat':
class Cat
public String name;
public int age;
public static void main( String[] args )
Cat[] myPets = new Cat[3];
myPets[0].name = "fluffy";
myPets[0].age = 2;
myPets[1].name = "garfield";
myPets[1].age = 4;
myPets[2].name = "heathcliff";
myPets[2].age = 3;
}In the main() method I create an array called myPets that references three Cat objects. Afterwards, I try to set the fields of each Cat object in the array (the 'name' and 'age'). This is where I'm having problems...when this code is run it produces a NullPointerException. So my question is...how do I set objects' individual fields when the objects are in an array?You are having an array of Cats. Which means that the array can act as container for cats, and it contains three fields.
Cat pets[] = new Cat[3];
What you need to do now, is to put cats into the container. Only if there are cats in there, you can give those cats name. This means :
//make a new cat
Cat cat1 = new Cat();
// put cat into array
pets[0] = cat1;
// name cat within the array
pets[0].name = "Garfield";
pets[0].age = 3;
Hope this helps,
rh -
Hi,
I need some help with the use of the DSM-CC object carousel.
In my Xlet, I need to read a file (previsioni.TXT), that is in the package testo; this is the structure of my folder:
\\mio; the first package
\\ MyXlet.java
\\ testo; package with the text
\\ previsioni.TXT
1. so I create un object carousel and then access the file with the java.io.File :
try {
System.out.println("Requesting file");
DSMCCObject carouselFile = new DSMCCObject("testo/previsioni.TXT");
carouselFile.synchronousLoad();
FileInputStream inFile = new FileInputStream(carouselFile);
//Construct a DataInputStream by using the
//FileInputStream in the constructor method.
DataInputStream inData = new DataInputStream (inFile);
//Invoke methods of DataInputStream to read data from the data source.
String s = inData.readUTF();
System.out.println(s);
//Close the FilterInputStream.
inData.close ();
catch (InvalidPathNameException e) {
System.out.println("Invalid path name!");
catch (IOException e){
System.out.println("Problem reading previsioni.txt ");
but when I run this code Xletview write
[XleTView]-INFO->loading Xlet... [mio.StatiXlet]
[XleTView]-INFO->XLET started... [mio.StatiXlet]
mio.StatiXlet : Inizializzazione avvenuta!
mio.StatiXlet : Hello TV World
Requesting file
xjava.io.File -
Problem reading previsioni.txt
and so there is an IO execption. Can someone help me?
2. then, when the file is in the string s, i would display this file; I try with the Htext:
texts = new HText( s, 20, 20, 200, 300, new Font("Tiresias", Font.BOLD, 26), Color.black, Color.white, new HDefaultTextLayoutManager());
but when I compile the code appear:
StatiXlet.java:173: cannot resolve symbol
symbol : variable s
location: class mio.StatiXlet
texts = new HText( s, 20, 20, 200, 300, new Font("Tiresi
as", Font.BOLD, 26), Color.black, Color.white, new HDefaultTextLayoutManager());
^
1 error
Do you know how can I display this file?
Thank you very muchHi beker,
thank you so much for your help, but I have another question.
I use your code and when I compile is OK, but when I run it in XletView it doesn't find the file previsioni.TXT and write this:
[XleTView]-INFO->loading Xlet... [mio.StatiXlet]
[XleTView]-INFO->XLET started... [mio.StatiXlet]
mio.StatiXlet : Inizializzazione avvenuta!
mio.StatiXlet : Hello TV World
xjava.io.File - testo/previsioni.TXT
java.io.FileNotFoundException: E:\Documenti\tirocinio\xlet esempi\testo\previsio
ni.TXT (Impossibile trovare il percorso specificato)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:103)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at xjava.io.FileInputStream.<init>(Unknown Source)
at xjava.io.FileInputStream.<init>(Unknown Source)
at mio.StatiXlet.startXlet(StatiXlet.java:97)
at net.beiker.xletview.xlet.XletManager.resumeRequest(Unknown Source)
at net.beiker.xletview.xlet.XletManager.run(Unknown Source)
at java.lang.Thread.run(Thread.java:536)
s=not read
What does it mean? I'm sure that the path is right, what do you think?
Thank you very much beiker for your help -
Help with object oriented concepts
I am a senior highschool student and although I know Java syntax, I learned with Pascal and other procedural languages so I have a difficult time thinking in OOP concepts (which I will have to learn for college classes). So for practice I went to my college's website and found an assignment on the intro course to programming: [Here are the assignment instructions.|http://www.cs.gsu.edu/knguyen/teaching/2009/spring/csc2010/proj.pdf]
My question is, how can I make my program illustrate more object oriented concepts?
Links:
ode-help.110mb.com/javaproject.java_Just a few comments (not necessarily about OO and in no particular order):
It's probably not worth it to make constants for the letter A or the plus sign. Make constants for values people would not understand:
// Ok
public static final int ANSWER_TO_THE_UNIVERSE = 42;'
// Probably overkill
public static final int FORTY_TWO = 42;
Good job on having DecimalFormat as a regular instance variable rather than static (since it is not thread-safe)
Good job initializing your object in a consistent state (via the ctor). Now, make as many variables final as you can. Immutable objects are good:[www.javapractices.com/topic/TopicAction.do?Id=29]
Not sure why you declared repeat() to return the boxed version of boolean, just use a primitive
You have a run() method but are not implementing Runnable. Not that it is required, but usually when I see run(), I think of threading
This is a matter of style, but you don't need to name the arguments in the ctor differently than the instance variables that get assigned. You can very easily say:
// Note that it is final. Make things immutable when you can.
private final String bar;
public Foo(final String bar) {
// Note: I don't need a different name here. This is purely a matter of personal style.
this.bar = bar;
Consider a while loop in run() rather than a do-loop. What happens if you get no input the first time around?
Java naming conventions dictate that classes start with a capital letter. Generally, an underscore is not used, camel-case is. So, your class should be JavaProject.
Consider making an object for the arguments that are passed into input. Maybe call it GradeCategory, or whatever.
That new object GradeCategory can have the output() method.
For method names, also follow conventions using camel case. So get_double should be getDouble().
Consider reworking such that you use an array or a collection of GradeCategory. You might want to then have an add method in your JavaProject. The add method should ensure the total weight of grades does not exceed 100%.
You can rework the output method of JavaProject to iterate over your GradeCategory objects, calling their own output() methods. Perhaps it also first checks that the weight of all grades equals 100%.Just a few thoughts.
- Saish -
Hi,
Can you please help on the usage of the table() function in oracle 10g
I have created a nested table as below
create or replace type testtype is table of varchar2(40);
created and object as below to accomodate the nested table in the object
create or replace type simpleobj is
object
name varchar2(30),
age number(3),
mobile number(6),
chk testtype
Can you please check this function below
create or replace procedure testtab(num in simpleobj)
is
peak testtype;
begin
select e.* into peak
from table(num.chk) e;
end;
I am unable to use the table() function in this context.
Can you please help on how can I return the nested table which is inside and object
Thnxyou mean like this?
create type obj_typ is object(
ename varchar2(20),
esal number);
create type nest_typ is table of obj_typ;
create or replace function nest_func(p_deptno number) return nest_typ is
nest_var nest_typ;
begin
select obj_typ(ename,sal) bulk collect into nest_var from emp where deptno=p_deptno;
return nest_var;
end;
select * from table(nest_func(30));
ENAME ESAL
ALLEN 1600
WARD 1250
MARTIN 1250
BLAKE 2850
TURNER 1500
JAMES 950
6 rows selected.
Elapsed: 00:00:00.00Regards,
Prazy
Maybe you are looking for
-
Connect MacBook to LG LCD TV?
Hi! I am trying to figure out what cables I need to connect my MacBook (about 2 yrs old) to my new LG 42" LCD TV (I think the model # is 42LD450?) Not sure if an HDMI cable would work or if I need an adapter for the laptop. I had also had a recommend
-
Disable a button under certain circumstances and disable input fields
Scenario: My user receives a PDF (dymanic XML) where they fill in fields and click a Submit button to send the data to the server. They receive a confirmation copy of the form back. In our older version of Livecycle, the confirmation form was locked
-
Selection screen stmt for LDB PNPCE
hi Like we have GET PERNR. for the Logical databse PNP wat is the statement GET ? for LDB PNPCE.
-
OK, maybe a simple question, maybe not, but I've been unable to find a clear answer. The queation is easy: is there a way that I can access my iPhoto library from iPads/iPhones on the same network (MAC is wired). I'm not looking to edit or store ph
-
Screen enhancement in FI-CA IS-MEDIA
Hello guys, My scenario is that i need to extend account posting screen in FI-CA for IS-MEDIA in ECC 6.0.my requirement is that i need to add tab strip which on clicking should display two fields .in one of the field if we press f4 it should diplay p