Self reference This in java
Hi all
Does any one know, how the self reference variable "this" works. That is how and when "this" variable is instantiated.
How value of "this" keeps on changing???
Is "This" static, final, private??
Any help will be appreciated.
regards
prince.k
Well lets assume it is a keyword. What i want to know
is how it is made to refer to the current object. I
guess the compiler adds some code for "this", so what
is that code??What makes you think the compiler adds code? Do you mean Java code?
U said it isn't static; No I didn't. I said that if you insist on thinking about it as a variable, then consider it non-static.
but it is static as u can
access it from ur class by saying "classname.this".That is just a syntax. As this is not a variable, classname.this does not imply it is static. There is one value per instance of any class (namely, the value for any given instance is a reference to that instance). If it were static, there would be one value shared by all instances of the class. Either way, this is a moot point.
But had it been final, it should be able to to refer
to only one object.It does. The current object.
but it keeps on changing....as it refer to the object
which called a particuler method of that class.No it doesn't - can you give an example of what you believe is the value of this changing?
Similar Messages
-
Create two one-to-one self-reference mappings
We need help on the following problem with Toplink:
We have a table massnahme with several attributes.
table massnahme
massnahmeID
prevMassnahme
nextMassnahme
prevMassnahme, nextMassnahme are self-references on massnahme. We take prevMassnahme and nextMassnahme as a one-to-one mapping to massnahme. The target reference on prevMassnahme and nextMassnahme is massnahmeID.
If we create a new Object massnahme_B and set prevMassnahme on this massnahme_B to an existing massnahme_A and set the nextMassnahme on the existing massnahme_A to the new massnahme_B, then it seems that toplink tries to make the update on the existing massnahme_A before the insert of the new massnahme_B. That causes an exception, because toplink tries to insert an empty massnahme into the database.
Any help on this topic would be appreciated.
The Toplink Mapping Workbench we use has the version 9.0.4.2.
ThomasHere the Java-Code and Descriptor Snippets, where Anamnese and Aufnahmevorgang are both derived classes of Massnahme and cloneAufnahmevorgang is registered earlier in the code (same UnitOfWork).
<mapping>
<inherited>false</inherited>
<instance-variable-name>prevMassnahme</instance-variable-name>
<uses-method-accessing>false</uses-method-accessing>
<read-only>false</read-only>
<get-method-handle>
<method-handle empty-aggregate="true"/>
</get-method-handle>
<set-method-handle>
<method-handle empty-aggregate="true"/>
</set-method-handle>
<reference-descriptor>de.kvwl.masc.se.model.Massnahme.ClassDescriptor</reference-descriptor>
<private-owned>false</private-owned>
<uses-batch-reading>false</uses-batch-reading>
<table-reference-mapping-reference-handle>
<reference-handle>
<reference-table>MASSNAHME</reference-table>
<reference-name>MASSNAHME_C05</reference-name>
</reference-handle>
</table-reference-mapping-reference-handle>
<uses-joining>false</uses-joining>
<one-to-one-mapping-indirection-policy>
<indirection-policy>
<uses-indirection>true</uses-indirection>
</indirection-policy>
</one-to-one-mapping-indirection-policy>
<mapping-class>MWOneToOneMapping</mapping-class>
</mapping>
<mapping>
<inherited>false</inherited>
<instance-variable-name>nextMassnahme</instance-variable-name>
<uses-method-accessing>false</uses-method-accessing>
<read-only>false</read-only>
<get-method-handle>
<method-handle empty-aggregate="true"/>
</get-method-handle>
<set-method-handle>
<method-handle empty-aggregate="true"/>
</set-method-handle>
<reference-descriptor>de.kvwl.masc.se.model.Massnahme.ClassDescriptor</reference-descriptor>
<private-owned>false</private-owned>
<uses-batch-reading>false</uses-batch-reading>
<table-reference-mapping-reference-handle>
<reference-handle>
<reference-table>MASSNAHME</reference-table>
<reference-name>MASSNAHME_C07</reference-name>
</reference-handle>
</table-reference-mapping-reference-handle>
<uses-joining>false</uses-joining>
<one-to-one-mapping-indirection-policy>
<indirection-policy>
<uses-indirection>true</uses-indirection>
</indirection-policy>
</one-to-one-mapping-indirection-policy>
<mapping-class>MWOneToOneMapping</mapping-class>
</mapping>
Anamnese cloneAnamnese = (Anamnese) getUow().registerExistingObject(anamnese);
cloneAufnahmevorgang.setPrevMassnahme(cloneAnamnese);
cloneAnamnese.setNextMassnahme(cloneAufnahmevorgang);
getUow().commit();
Any further Information needed?
Thomas -
Why do we need a Self Reference "me" to use the components of a class
Hi
I am not clear why do we need a self reference variable "me" to call the components of its own class? when it can be accessed directly as in the following examples?
In my first example below i can call the method display_name directly without creating a reference object or instance of the class within the class.
In the second example i am using the self refernce Write me->name to access the component of a class.
My question is why do we need "me" when i can use the components directly as shown in my first example.
CLASS egocentric DEFINITION.
PUBLIC SECTION.
DATA:
name(10) TYPE c READ-ONLY.
METHODS set_name.
METHODS display_name.
ENDCLASS. "egocentric DEFINITION
* CLASS egocentric IMPLEMENTATION
CLASS egocentric IMPLEMENTATION.
METHOD set_name.
MOVE 'Abap Objects' TO name.
CALL method display_name.
ENDMETHOD. "write_name
METHOD display_name.
write: name.
ENDMETHOD. "display_name
ENDCLASS. "egocentric IMPLEMENTATION
*Global Data
DATA oref TYPE REF TO egocentric.
START-OF-SELECTION.
CREATE OBJECT oref.
CALL METHOD oref->set_name.
CLASS egocentric DEFINITION.
PUBLIC SECTION.
DATA:
name(10) TYPE c VALUE u2018Instructoru2019
READ-ONLY.
METHODS write_name.
ENDCLASS.
CLASS egocentric IMPLEMENTATION.
METHOD write_name.
WRITE me->name.
ENDMETHOD.
ENDCLASS.
*Global Data
DATA oref TYPE REF TO egocentric.
START-OF-SELECTION.
CREATE OBJECT oref.
CALL METHOD oref->write_name.You can go WIKI and search with ABAP Objects.
Or do the same in 'advanced search' and select a search area. You are bound to find something.
Or this link perhaps:
[abap objects|http://help.sap.com/saphelp_nw70/helpdata/EN/ce/b518b6513611d194a50000e8353423/content.htm] -
Cannot reference this before supertype constructor has been called
I'm confused. I would like it easier for a user to use a class where one item can be determined from another, but I'm having a problem with the constructors.
First, one constructor that works fine:
public UndirectedGraph(List nodes, List edges) {
this(nodes, edges, 100, 100, true, false);
}which then calls the ultimate constructor that accepts all those other parameters.
The problem is with this one:
public UndirectedGraph(List nodes) {
this(nodes, collectEdges(nodes), 100, 100, true, false);
}collectEdges returns a List of Edges, so technically all should be fine. However, this won't compile, with the message:
UndirectedGraph.java [37:1] cannot reference this before supertype constructor has been called
this(nodes, collectEdges(nodes));
^
1 error
Errors compiling UndirectedGraph.Is there a workaround for what I'm trying to do? It'd be a lot easier to have this collectEdges() method in this single place than in any class that's using this one.You HAVE to call the super constructor before you do anything else in the constructor. You can make calls to this but the final constructor to be executed has to make the super call. I am assuming you are subclassing something here because this should not show up as an error if there is a default constuctor. The reson for this is that a subclass is built on top of its parent classes meaning it can access information in them methods in them etc. Even in the constrcutor it can do this so the super class MUST be created before the subclass.
-
Resolve self-reference table by alias tables in detail
Hello Gurus,
can you tell me how to resolve self-reference table by alias tables in detail?
Many thanks.Hello, for the following step 3, I don't understand, will you please give me some explanation for step 3?
Save your Staff universe, and test the results in Web Intelligence Rich Client as follows:
1. Run a query using Manager and Employee. Add a count on both columns.
2. Add a query with only the Manager object. Add a count. Is this the correct value?
3. Open your Staff universe in Universe Designer and edit the Manager object. To ensure
that the data is restricted to only manager data, use the Tables button. Select the
EMPLOYEE table, to force the object to use the join between the table and restrict the
data.
4. Test the result, creating a new query with only the Manager object. It returns the correct
number of managers.
5. Edit the query and add Employee. Run and display the count. There are 26 rows. Why?
The join restricts the data to look only for employees that have managers. However, there
is a manager that does not have a manager, and is now excluded.
6. Open your Staff universe in Universe Designer and add an outer join on the MANAGER
table side.
7. Save the changes and test the results in Web Intelligence Rich Client. -
How do we create self-signed certificate using java packages
Hi All,
I require some information on creating self-signed certificate using java packages.
The java.security.cert.* package allows you to read Certificates from an existing store or a file etc. but there is no way to generate one afresh. See CertificateFactory and Certificate classes. Even after loading a certificate you cannot regenerate some of its fields to embed the new public key – and hence regenerate the fingerprints etc. – and mention a new DN. Essentially, I see no way from java to self-sign a certificate that embeds a public key that I have already generated.
I want to do the equivalent of ‘keytool –selfcert’ from java code. Please note that I am not trying to do this by using the keytool command line option – it is always a bad choice to execute external process from the java code – but if no other ways are found then I have to fall back on it.
Regards,
ChandraI require some information on creating self-signed certificate using java packages. Its not possible because JCE/JCA doesn't have implementation of X509Certificate. For that you have to use any other JCE Provider e.g. BouncyCastle, IAIK, Assembla and etc.
I'm giving you sample code for producing self-signed certificate using IAIK JCE. Note that IAIK JCE is not free. But you can use BouncyCastle its open source and free.
**Generating and Initialising the Public and Private Keys*/
public KeyPair generateKeys() throws Exception
//1 - Key Pair Generated [Public and Private Key]
m_objkeypairgen = KeyPairGenerator.getInstance("RSA");
m_objkeypair = m_objkeypairgen.generateKeyPair();
System.out.println("Key Pair Generated....");
//Returns Both Keys [Public and Private]*/
return m_objkeypair;
/**Generating and Initialising the Self Signed Certificate*/
public X509Certificate generateSSCert() throws Exception
//Creates Instance of X509 Certificate
m_objX509 = new X509Certificate();
//Creatting Calender Instance
GregorianCalendar obj_date = new GregorianCalendar();
Name obj_issuer = new Name();
obj_issuer.addRDN(ObjectID.country, "CountryName");
obj_issuer.addRDN(ObjectID.organization ,"CompanyName");
obj_issuer.addRDN(ObjectID.organizationalUnit ,"Deptt");
obj_issuer.addRDN(ObjectID.commonName ,"Valid CA Name");
//Self Signed Certificate
m_objX509.setIssuerDN(obj_issuer); // Sets Issuer Info:
m_objX509.setSubjectDN(obj_issuer); // Sets Subjects Info:
m_objX509.setSerialNumber(BigInteger.valueOf(0x1234L));
m_objX509.setPublicKey(m_objkeypair.getPublic());// Sets Public Key
m_objX509.setValidNotBefore(obj_date.getTime()); //Sets Starting Date
obj_date.add(Calendar.MONTH, 6); //Extending the Date [Cert Validation Period (6-Months)]
m_objX509.setValidNotAfter(obj_date.getTime()); //Sets Ending Date [Expiration Date]
//Signing Certificate With SHA-1 and RSA
m_objX509.sign(AlgorithmID.sha1WithRSAEncryption, m_objkeypair.getPrivate()); // JCE doesn't have that specific implementation so that why we need any //other provider e.g. BouncyCastle, IAIK and etc.
System.out.println("Start Certificate....................................");
System.out.println(m_objX509.toString());
System.out.println("End Certificate......................................");
//Returns Self Signed Certificate.
return m_objX509;
//**************************************************************** -
Hello experts,
I am totally new to ABAP Objects and was going through a book for the same to learn the concepts.
There is a section of Self Reference in this book. I could not understand this concept by myself. Could you please help me out to explain this thing.
PFB the code that is given in this book to explain Self Reference.
REPORT z_self_reference.
* CLASS client DEFINITION
CLASS client DEFINITION.
PUBLIC SECTION.
DATA name(10) TYPE c VALUE 'Master' READ-ONLY.
METHODS create_server.
ENDCLASS. "client DEFINITION
* CLASS server DEFINITION
CLASS server DEFINITION.
PUBLIC SECTION.
METHODS acknowledge
IMPORTING creator TYPE REF TO client.
PRIVATE SECTION.
DATA name(10) TYPE c VALUE 'Servant'.
ENDCLASS. "server DEFINITION
* CLASS client IMPLEMENTATION
CLASS client IMPLEMENTATION.
METHOD create_server.
DATA server_ref TYPE REF TO server.
CREATE OBJECT server_ref.
CALL METHOD server_ref->acknowledge
EXPORTING
creator = me.
ENDMETHOD. "create_server
ENDCLASS. "client IMPLEMENTATION
* CLASS server IMPLEMENTATION
CLASS server IMPLEMENTATION.
METHOD acknowledge.
DATA name TYPE string.
name = creator->name.
WRITE: me->name, 'create by', name.
ENDMETHOD. "acknowledge
ENDCLASS. "server IMPLEMENTATION
DATA client_ref TYPE REF TO client.
START-OF-SELECTION.
CREATE OBJECT client_ref.
CALL METHOD client_ref->create_server.
Thanks,
Mohit Goel.
Edited by: Matt on Apr 8, 2009 10:50 AMHi Mohit,
me is used to self reference the attributes and methods of a class within that class.In your program,
within client class implementation, you can use me->name and me->create_server to call the name variable and create_server method in the same class if required.Here me represents "client class".Similarly ,in Server class, you can use me->name and me->acknowledge to call the name variable and acknowledge method in the same class if required.
In your program ,
CALL METHOD server_ref->acknowledge
EXPORTING
creator = me.
is not correct.me is not used as variable . Its only a reference variable.it shoud used me->class attribute(name)/method.
I hope , you could understand the above explanation.
by
Prasad GVK. -
Self Reference Model Class - How to populate using Entity Framework
Hi,i have table in SQL Server named Employees as follows:
EmployeeId lastName FirstName reportsTo
1 Davolio Nancy 2
2 Fuller Andrew NULL
3 Leverling Janet 2
4 Peacock Margaret 2
5 Buchanan Steven 2
6 Suyama Michael 5
7 King Robert 5
8 Callahan Laura 2
9 Dodsworth Anne 5
I would like to use Entity Framework to populate my Model Class .My model class looks as follows:
public class Employees
readonly List<Employees> _children = new List<Employees>();
public IList<Employees> Children
get { return _children; }
public string FirstName { get; set; }
public string LastName {get; set;}
I want to use this class in ViewModel to populate my TreeView control. Can anyone help me in order to define Linq to Entities in order to populate my model class Employees from table in SQL Server as defined. Thanks in advance.
AlmirHello Fred,
unfortunately it does not work, maybe I can be more specific about what I'm trying to get. I'm following Josh Smith's article on CodeProject related to WFP TreeView
Josh Smith article. He has Class named Person with the following structure
public class Person
readonly List<Person> _children = new List<Person>();
public List<Person> Children
get
return _children;
public string Name { get; set; }
The same is populated from Database class using method named GetFamilyTree() which look as follows:
public static Person GetFamilyTree()
// In a real app this method would access a database.
return new Person
Name = "David Weatherbeam",
Children =
new Person
Name="Alberto Weatherbeam",
Children=
new Person
Name="Zena Hairmonger",
Children=
new Person
Name="Sarah Applifunk",
new Person
Name="Jenny van Machoqueen",
Children=
new Person
Name="Nick van Machoqueen",
new Person
Name="Matilda Porcupinicus",
new Person
Name="Bronco van Machoqueen",
new Person
Name="Komrade Winkleford",
Children=
new Person
Name="Maurice Winkleford",
Children=
new Person
Name="Divinity W. Llamafoot",
new Person
Name="Komrade Winkleford, Jr.",
Children=
new Person
Name="Saratoga Z. Crankentoe",
new Person
Name="Excaliber Winkleford",
I'm trying to figure out how should I write
GetFamilyTree() method using Entity Framework in order to connect to my SQL Server database and populate this Person class as it was populated manually in Joshs Example. The table I'm using in SQL Server is described in
my first post named Employees (it's self reference table) -
Data Modeler: How to create a self reference in ER?
e.g. I create the entity EMP in a logical Subview. Two attributes are here essential for a self-reference: EMPNO and MGR. So each Employee has a reference to his boss. And this information is stored in MGR.
Now I create the entity EMP with the 8 columns from the SCOTT/TIGER schema. After that I define a 1:N-Relation between EMP and EMP. but it looks like I cannot define, which attributes are starting point of the relation and destination.
Who can help me here?
GerdGerd,
you cannot select destination (as you said) attribute - they are automatically generated. However you can achieve what you want - it depends on your starting point:
1) start from logical model (analysis first)
- you create 1:n recursive relationship -
- change the name of created FK attribute to MGR or what ever you want - this is controlled by "FK Attribute name synchronization" setting at "General options>Model>Logical" page
2) start from relational model (reverse engineering of existing status)
- create self reference foreign key - select MGR as FK column;
- reverse engineer to logical model - you'll have FK attribute named MGR
Philip -
What's the reference of the java?
what's the reference of the java?
Please tell me exactually!Please read this thread
http://forum.java.sun.com/thread.jsp?forum=4&thread=174952
If it applicable and you still have a question, come back and ask that question. If it is not applicable, come back and ask your real question. -
Cannot reference this before supertype constrcutor has been called
I have a class in the following. When I compiled it, I had the error message: cannot reference this before supertype constrcutor has been called
super(new Model());
Does anyone know how to fix it?
Thanks a lot.
Jian
public class TreeViewApplet extends JApplet {
class DOMTree extends JTree
public DOMTree() {
this(null);
public DOMTree(Document document) {
super(new Model());
}You are right. If I used them seperately, everything is fine. However, I need to get the slected node out of DOMTree class so that I may pass the selected node to TreeViewApplet.java class. As you know, JSObject is only allowed to use getMember() and setMember() in TreeViewApplet.java class. That's why I put two classes together.
Do you have any solution to fix my problem?
Thanks.
Jian -
Hi,
I am trying to do a recursive self reference. Is this the best way of doing it as I keep getting errors?
SQL> CREATE OR REPLACE TYPE type_objtyp AS OBJECT (
2 type_id NUMBER (10),
3 type_name VARCHAR2 (100),
4 sub_type REF type_objtyp
5 )
6 NOT FINAL
7 /
Type created.
SQL> CREATE OR REPLACE TYPE data_objtyp
2 /
Type created.
SQL> CREATE OR REPLACE TYPE data_list_objtyp AS TABLE OF data_objtyp
2 /
Warning: Type created with compilation errors.
SQL> CREATE OR REPLACE TYPE data_objtyp AS OBJECT (
2 data_id NUMBER (10),
3 type_ref REF type_objtyp,
4 creation_date DATE,
5 child_list_ref REF data_list_objtyp
6 )
7 NOT FINAL
8 /
Warning: Type created with compilation errors.
SQL>
SQL> COMMIT
2 /
Commit complete.
SQL> show errors
Errors for TYPE DATA_OBJTYP:
LINE/COL ERROR
0/0 PL/SQL: Compilation unit analysis terminated
5/25 PLS-00532: Target of REF must be a complete or incomplete object
type.you can't have a REF to a table type, only to object types. so, instead use a table of REFs:
-- incomplete declaration
create or replace type data_objtyp;
-- declare table type
create or replace type data_objtyp_list is table of REF data_objtyp;
-- complete data object declaration
create or replace type data_objtyp is object (
data_id NUMBER (10),
type_ref REF type_objtyp,
creation_date DATE,
child_list data_objtyp_list
NOT FINAL;
hope that helps... g -
i just updated my latest java but the update is causing problems with some external devices. So i would like to uninstall this latest java update and get back the previous one. That should solve to problems with my external device.
Is this possible and how do i do that?
Anyone who responds thanks for that!
Juko
I am running
Hardware Overview:
Model Name: Mac Pro
Model Identifier: MacPro1,1
Processor Name: Dual-Core Intel Xeon
Processor Speed: 2,66 GHz
Number of Processors: 2
Total Number of Cores: 4
L2 Cache (per Processor): 4 MB
Memory: 6 GB
Bus Speed: 1,33 GHz
Boot ROM Version: MP11.005D.B00
SMC Version (system): 1.7f10
Serial Number (system): CK7XXXXXXGP
Hardware UUID: 00000000-0000-1000-8000-0017F20F82F0
System Software Overview:
System Version: Mac OS X 10.7.5 (11G63)
Kernel Version: Darwin 11.4.2
Boot Volume: Macintosh HD(2)
Boot Mode: Normal
Computer Name: Mac Pro van Juko de Vries
User Name: Juko de Vries (jukodevries)
Secure Virtual Memory: Enabled
64-bit Kernel and Extensions: No
Time since boot: 11 days 20:39
Message was edited by HostJava 6 you can't as Apple maintains it, and Java 7 you could if you uninstall it and Oracle provides the earlier version which they likely won't his last update fixed 37 remote exploits.
Java broken some software here and there, all you'll have to do is wait for a update from the other parties. -
Hi,
Wondering if anyone knows what's going on with my Filemaker Database that will not view properly on my desktop after upgrading from 10.5 to 10.6.8 on
my MacBook Pro. Is this a Java issue? The data is all there but all I see is blank boxes when I open or click on a specific area in the database.
My Java version is SE 6 1.6.0.37-bo6-434.Let me understand:
- you have purchased named canon, which is conencted to your PC running windows xp
- downloaded driver for win xp, and canon works fine
- canon is connected to that PC via USB
- that Canon is also activated as network printer, by allowing print sharing in windows; how did you set that option?
- now, you are in Mac OS x 10.6.8, downloaded Canon driver for Mac OS X, installed it, detected printer on the network, printer was installed; was it detected as attached to that PC running win XP? or not?
or you set canon by being connected to your mac directly via USB?
Now, there are some questions you should answer as some details are missing, and your initial text is not clear. Can you print if Canon is connected directly to your mac? did you try that? if not, do it before answering. -
i'm trying to use a madcatz controller on the mac but it turns on for 2 seconds and turns off. the system profiler picks it up as a xbox 360 gamepad but says its not been configured. how can i allow my self use this with my games!
I have exactly the same problem.
I'm a little peed-off with Microsoft on this. The original wireless controller I have doesn't work either since the cable I'm using is 'just' the charge and play cable, so a direct connection to my Mac won't work with this cable. It's a cable for god's sake. Why on EARTH put any limitations on this!?!?
Next I learn I need an additional USB wireless receiver from Microsoft to get my original 360 controller to talk to my Mac. As I certainly don't want to fork any more microsoft dollars on this, this is not an option.
Next I think, yes! I have a MadCatz 360 wired USB controller. This should surely do the trick just plugging it in and the way I go. But oh no, for some reason I plug my MadCatz Xbox360 controller in, it flashes a few times then switches off and can't be turned on again.
The System Profiles recognizes it as a MadCatz 360 device controller but that is about it, but the ontroller software I download for the System Prefs (360Controller, USBOverdrive etc) don't even recognize the controller as being plugged in.
What the **** Is The Microsoft Deal with all of this!?!?
PS: Oh, and I forgot to mention, there are No drivers for device 4716 that I can find on the MadCatz website, or am I going blind?
If anyone has a link, it would be appreciated.
Message was edited by: nostrawaggus
Maybe you are looking for
-
Ipod is not being detected on itunes or windows
I've tried everything like reseting my ipod, the five r's and it still not picking up on the computer. *_HELP PLEASE_*
-
Can't open a pdf file: there was an error opening this document access denied
Could anyone help in this problem I am facing. I have scanned documents as PDF and they opened nicely but after I renamed the files I am not able to open them. I get the message 'There was an error opening this document. Access denied'. When I try to
-
How do I edit notes on my Mac mini?
I have just switched from a PC to a Mac, and for convenience I am still using Thunderbird for email. As far as I can tell from the User Guide, Notes on the iPhone can be edited in Mail. Is there a way to set up Mail without having it be my default em
-
when importing photos from iphone it keeps spinning and repeating it is importing, gets to the last one then starts over again??
-
My iPhone 4 reboot every time i used it. A month before, started to reboot ocasionally. Now it does it all time. When it crashed show green or brown forms. After force the reboot (power + home) these forms still apears but in a while the vanish. In G