When Should I use the Inner Classes ?
When Should I use the Inner Classes ?
What is the advantage(s) and the disadvantage(s) ?
When I use innerclasses?
1) Allmost allways when I need simple owner child behavior.
2) When I need a behaviour, that is quite small, and used only once, I make it anonymous inner class. For example specialised streams and threads.
3) Enumerations
Similar Messages
-
Can I use the inner class of one containing class by the other class
Can I use the inner class of one containing class by the other class in the same package as the containing class
eg I have a class BST which has inner class Enumerator. Can I use the inner class from the other class in the same pacckage as BST?Inner classes do not share the namespace of the package of the containing class. Also they are never visible to other classes in the same package.Believe what you want, then, if you're going to make up your own rules about how Java works. For people interested in how Java actually works, here is an example that shows why that assertion is false:
package com.yawmark.jdc;
public class Outer {
public class Inner {
}And...
package com.yawmark.demo;
import com.yawmark.jdc.*;
public class Demo {
public static void main(String[] args) {
assert new Outer().new Inner() != null;
}~ -
When should I use the power adapter?
I just installed a wireless router. Should I use the power adapter when I'm not going to use the Macbook for several hours? Does the Macbook drain the battery when it is shut down or sleeping?
When should I use the power adapter?
Whenever you are near a power outlet. Not 100% of the time, of course (you have to flex the battery sometimes) but as often as possible.
Should I use the power adapter when I'm not going to use the Macbook for several hours?
If you are near an outlet, yes.
Does the Macbook drain the battery when it is shut down or sleeping?
When sleeping, it drains a negligible amount.
Further reading:
http://support.apple.com/kb/HT1446
http://support.apple.com/kb/HT1490 -
I am getting a NullPointerException when trying to use the Service class
I am getting a NullPointerException which is as follows
java.lang.NullPointerException
file:/K:/Learner/JavaFx2/ProductApplication/dist/run166129449/ProductApplication.jar!/com/product/app/view/viewsingle.fxml
at com.product.app.controller.ViewSingleController.initialize(ViewSingleController.java:70)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
And my View SingleController is as follows
package com.product.app.controller;
import com.product.app.model.Product;
import com.product.app.service.ViewProductsService;
import com.product.app.util.JSONParser;
import com.product.app.util.TagConstants;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javafx.collections.ObservableList;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.Region;
import javafx.stage.Stage;
import javax.swing.JOptionPane;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
* FXML Controller class
* @author Arun Joseph
public class ViewSingleController implements Initializable {
private static String action = "";
@FXML
private TextField txtID;
@FXML
private TextField txtName;
@FXML
private TextField txtPrice;
@FXML
private TextArea txtDesc;
@FXML
private Region veil;
@FXML
private ProgressIndicator p;
private ViewProductsService service = new ViewProductsService();
private JSONObject product = null;
private JSONParser parser = new JSONParser();
private int pid = 1;
public void setPid(int pid) {
this.pid = pid;
* Initializes the controller class.
@Override
public void initialize(URL url, ResourceBundle rb) {
veil.setStyle("-fx-background-color: rgba(0, 0, 0, 0.4)");
p.setMaxSize(150, 150);
p.progressProperty().bind(service.progressProperty());
veil.visibleProperty().bind(service.runningProperty());
p.visibleProperty().bind(service.runningProperty());
Product product = new Product();
service.start();
ObservableList<Product> products = service.valueProperty().get();
products.get(pid);
txtID.textProperty().set(String.valueOf(products.get(pid).getPid()));
//product = service.valueProperty().get().get(pid);
//txtID.setText(String.valueOf(product.getPid()));
txtName.textProperty().set(product.getName());
txtPrice.textProperty().set(String.valueOf(product.getPrize()));
txtDesc.textProperty().set(product.getDescription());
private SomeService someService = new SomeService();
@FXML
private void handleUpdateButtonClick(ActionEvent event) {
action = "update";
someService.start();
p.progressProperty().bind(service.progressProperty());
veil.visibleProperty().bind(service.runningProperty());
p.visibleProperty().bind(service.runningProperty());
@FXML
private void handleDeleteButtonClick(ActionEvent event) {
action = "delete";
someService.start();
p.progressProperty().bind(service.progressProperty());
veil.visibleProperty().bind(service.runningProperty());
p.visibleProperty().bind(service.runningProperty());
@FXML
private void handleCancelButtonClick(ActionEvent event) {
closeStage();
private void closeStage() {
ViewSingleController.stage.close();
private static Stage stage = null;
public static void setStage(Stage stage) {
ViewSingleController.stage = stage;
private class SomeService extends Service<String> {
@Override
protected Task<String> createTask() {
return new SomeTask();
private class SomeTask extends Task<String> {
@Override
protected String call() throws Exception {
String result = "";
int success = 0;
List<NameValuePair> params = new ArrayList<NameValuePair>();
switch (action) {
case "update":
params.add(new BasicNameValuePair("pid", txtID.getText()));
params.add(new BasicNameValuePair("name", txtName.getText()));
params.add(new BasicNameValuePair("price", txtPrice.getText()));
params.add(new BasicNameValuePair("description", txtDesc.getText()));
product = parser.makeHttpRequest(TagConstants.url_update_product_with_id, "POST", params);
success = product.getInt(TagConstants.TAG_SUCCESS);
if (success == 1) {
result = "Successfully Updated the product";
JOptionPane.showMessageDialog(null, result);
closeStage();
break;
case "delete":
params.add(new BasicNameValuePair("pid", txtID.getText()));
product = parser.makeHttpRequest(TagConstants.url_delete_product_with_id, "POST", params);
success = product.getInt(TagConstants.TAG_SUCCESS);
if (success == 1) {
result = "Successfully Deleted the product";
JOptionPane.showMessageDialog(null, result);
closeStage();
break;
return result;Time Machine has its own mechanism for deleting files. The number you are seeing may represent a "underflow" or a number of files which exceeds the limit and becomes negative.
The best way to remove TM files is via the TM interface: select the files and click the Gear and select delete from all backups.
If you are deleting files on an external drive which once included TM files, it is best to use the terminal and just delete them directly. They go bye-bye without ever seeing the trash bucket.
Of course, using the terminal is not for everyone.
What you might be able to do is restore the files from trash and then delete them properly or in smaller bundles. -
When should I use the .resetDRMVouchers() API?
[ Background ]
DRMManager.resetDRMVouchers() (and the corresponding APIs on iOS and Android) will reset the DRM license store on the client device. It does this by renaming the license store and notifying Adobe Access DRM to perform an individualization the next time protected content is played. On the next playback of content, a new license store directory is created and all new licenses will go into that store. The previous license store is never used again.
Sometimes, it is necessary to perform a .resetDRMVouchers() if the client device has reached a state where Adobe Access DRM can no longer function properly. For instance, if the license store has become corrupt, the device can no longer access existing licenses or store new licenses - they are stuck unless they use annother Browser or App, which would use another license store.
[ How to properly call .resetDRMVouchers() ]
Below is an Actionscript code snippet. The exact same workflow applies to iOS and Android:
import flash.net.drm.*;
private function onDRMErrorEvent(event:DRMErrorEvent) : void {
if(event.errorID == 3322 || event.errorID == 3346){
try {
DRMManager.getDRMManager().resetDRMVouchers();
// you may want to display 'please reload the page or restart the browser' message.
catch(e:Error)
// most likely in older version of flash player where resetDRMVouchers is not allowed.
[ Which error codes indicate the client is disabled and requires a DRM Reset? ]
The following error codes require a DRM Reset in order to recover a client that can no longer play Adobe Access DRM content:
DRM Error Event
Description
3322 - Device Binding Failed
The underlying hardware attributes of the device has changed so much (likely by a hardware upgrade) that Adobe Access does not recognize this machine to be the same machine it was before. Adobe Access treats this as a "copy and paste" attack where one device copies licenses to a different device in an attempt to share their DRM'd content; playback is denied.
The device can recover by re-installing their previous hardware. If that is not desired/possible, a DRM reset will re-initialize Adobe Access to set the current device attributes as the baseline. However, doing this removes access to all previous licenses stored on disk.
3323 - Corrupt Global State Store
The license store has become corrupt and can no longer be accessed until a reset is performed.
3326 - Store Tampering Detected
The license store has been tampered, causing the signature check to fail. The store can no longer be used and a reset must be performed to create a new store.
3346 - License Migration Failed
When upgrading to a newer version of Adobe Access or Flash Player, all previous licenses are migrated to the new license store. If migration fails, the old store is corrupt and must be reset so that the next individualization attempt will not attempt to migrate your previous license store.
[ How to manually perform a reset DRM ]
Please refer to this forum posting: http://forums.adobe.com/message/3051713#3051713Kanan, the difference you already know, blade .vs rack mount. There are some CPU differences, but not much. Both can be managed by UCSM in version 1.4.x
So it really is ones preference on what you are using it for and how scalable you want things to be for future expansion.
Blades: easy, as you can buy a chassis and have 2 blades in that one chassis and add blades as needed. If using boot from San, can get a server back up in minutes
Rack mount: can take rack space more quickly, takes time to duplicate in case of a failed server
Very small differences, but hope this helps to start the wheels turning.
Good Luck!
Sent from Cisco Technical Support iPhone App -
When we going to use static inner class
Hi
when we r going use static inner class
inner classes use for to create adaptorclasses that implement an interface.
what about Static inner class
if possible give some examples
Thanks in advstatic inner classes are used when the inner class does not require to access the encompassing class's variables/methods. By default non-static inner classes obtain a reference to the outer class instance through which they access the outer class variables and methods
ram. -
We have 4 iphones and an Ipad in our family. When we purchase music, I would like for the entire family to be able to use it and then back it up to Icloud. What is the best and cheapest way for this to happen. Should we all have a different apple id or should we use the same one.
You will all need to be on the same itunes account ID.
You can however all have seperate icloud accounts aswel. -
What is the Use of Inner classes in Interface.
Hi All,
Most of us we know that We can define inner classes in the interface. Like
public interface MyItf{
Demo d = new Demo();
class Demo{
Demo(){
//some additional code here
}Now I have following question in my mind:
1. An Interface is pure abstract. Then why inner classes inside the interface?
2. In what scenario, we can utilize these inner classes of interface?
Plz Share your views on this...
Thks for ur replies in advance.This we cando in defining Demo Class outside.That's no argument. You could write the programs in other languages, so why use Java? Just because you can use a top-level class instead, it's no argument against using an inner class. You also can make all attributes public... you don't o that either (I hope).
Ok Also
tell me how to pass an Object in inner class Demo. to
the method of Interface.
public abstract TheInterface.Demo doSomething(TheInterface.Demo d);
Can u give some real time situation where this
concept can be used.There are only very, very few. Just because it's possible, it doesn't mean it needs to be done or is done often. -
What is the use of Inner class.?
hello everyone.........
I want toknow that what is the use of Inner class...?Judging from what's seen around here? Mainly obfuscation.
-
What are the mapfiles for and when should I use them?
Hi,
what are the map files for and why/when should I use them?
/usr/lib/ld/map.noexstk
usr/lib/ld/map.noexbss
/usr/lib/ld/map.noexdata
/usr/lib/ld/map.pagealignHi, I'm sure you've read the comments, but for the benefit of those who haven't: /usr/lib/ld/map.noexstk # Linker mapfile to create a non-executable stack definition within an # executable. /usr/lib/ld/map.noexbss # Link-editor mapfile to create a non-executable bss segment definition # within an executable. /usr/lib/ld/map.noexdata # Link-editor mapfile to create a non-executable data segment definition # within an executable. These stop the various segments from being executable. Which could reduce the risk surface for exploiting security holes in an application. /usr/lib/ld/map.pagealign # Linker mapfile to create page-aligned data within an executable. Aligning the start of the data segment can reduce the number of TLB entries needed to map the data. So the smallest TLB page size is 8KB, then we have 64KB, then 4MB etc. If the data starts on a 4MB boundary then it can be mapped with 4MB pages, if not then it has to be mapped with 8KB pages until a 64KB boundary, then 64KB pages until we get to a 4MB boundary. You sometimes get a bit of performance from this, but you may also get performance stability from it. If the mapping is random sometimes it works well, sometimes it works less well. Regards, Darryl.
-
What is the difference between saving to "Documents" and "Macintosh HD" and when should you use each one?
When you save to the folder with the little house icon, the file is placed at
/Users/your_user_name/
You would really have to go out of my way to save at:
(the shortcut for the Boot Drive, regardless of its name).
I am not sure how you decided that Time Machine is not saving your files. The default is for Time Machine to do incremental Backups of everything on all attached drives, except for certain temporary information in Cache files. If you have four Users, Time Machine will back them all up.
Looking at the raw Time Machine backups will tell you very little, because it does lots of its work with Hard Links, and because it does incremental backups, so only files that changed since the last Backup are saved at thet cycle. The way to determine whether Time Machine is saving things is to display the window you care about in the Finder, then invoke the "Star wars"/ "Back, back, back in time" Interface. -
Excel opens and does not close when using the OI classes for some users...
Hello Experts,
I am using the OI classes(i_oi_container_control, i_oi_error, i_oi_document_proxy, i_oi_spreadsheet) to transfer Excel data to my itab. The problem we are encountering is that for some users the excel automatically opens and does not close. But in my case it is not opening so it is fine in my case. In my code I am already using the 'CLOSE_DOCUMENT' and 'RELEASE_DOCUMENT'.Viraylab,
Check by any case you set the parameter register_on_close_event of the method init_control? Dont set the parameter as it will look for the corressponding custom code in your program. Also try with the method release_all_documents.
Regards,
Kiran Bobbala -
Calling functions of the inner class in .java code file
Hello,
I created a .java code file in Visual J#.Net and converted it into
the application by adding the "public static void main(String args[])"
function.
I have created the two classes one extends from Applet, and the other
extends from Frame. The class which I inherited from the Frame class becomes
the inner class of the class extended from the Applet. Now How do I
call the functions of the class extended from Frame class - MenuBarFrame
class. the outline code is
public class menu_show extends Applet
------init , paint action function---------
public class MenuBarFrame extends Frame
paint,action function for Menu
public static void main(String args[])
applet class instance is created
instance of frame is created
Menu , MenuBar, MenuItem instance is created
and all these objects added
I have Created MenuBarFrame class instance as
Object x= new menu_show().new MenuBarFrame
????? How to call the functions such as action of MenuBarFrame class - what
should be its parameters??????
}Here's how I would do it:
interface Operation {
public int op(int y);
class X {
private int x;
public X(int x) {
this.x = x;
private class Y implements Operation {
public int op(int y) {
return x+y;
public Operation createOperation() {
return new Y();
public static void main(String[] args) {
X app = new X(17);
Operation f = app.createOperation();
System.out.println(f.op(-11));
}Your code, however, has some serious "issues". You typically don't
instantiate an applet class -- that's the job of the applet viewer or Java plugin
your browser is using. If you instantiate the applet directly, you're going
to have to supply it an AppletStub. Do you really want to go that way?
Again, use an applet viewer or browser, or better yet, why write applets at all? -
When should I use static variable and when should not? Java essential
When should I use static variable and when should not? Java essential
Static => same value for all instances of the class.
Non-static => each instance can have its own value.
Which you need in which circumstances is completely up to you. -
When should a subclass have its own fields and when should it use its super
When should a subclass have its own fields and when should it use its superclass' fields?
Hi, thank you for reading this post!
Let me use a specific example to ask my question.
public class BankAccount {
private double accountBalance;
public double getBalance() {
return this.accountBalance;
public class SavingsAccount extends BankAccount {
private double accountBalance;
public double getBalance() {
return this.accountBalance;
}In the bank account example, both BankAccount and SavingsAccount will have a method getBalance(). Therefore, they
both require a account balance field. My question is since getBalance() for both classes will perform the exact same
operation, when should I omit declaring the getBalance() method and the accountBalance field in the subclass, and
when should I include them?
My own thought is when we never have to instantiate a superclass object (e.g. an abstract class), then we place
common fields in the abstract superclass and have subclasses access these fields via protected getter/setters to
access the superclass' fields. This is the principle of reuse.
But when you do need to instantiate a superclass and the superclass does need to maintain its own fields, then
I would need to duplicate the accountBalance field and getBalance() method in the subclass.
Is my thinking correct or incorrect?
Thank you in advance for your help!
Eric
Edited by: er**** on 22-Aug-2011 20:19er**** wrote:
If SavingsAccount inherit BankAccount.getBalance()...getBalance() would return BankAccount's accountBalance. This is NOT the correct result we want.Actually, I think it's precisely what you want.
We want getBalance() to return BankAccount's accountBalance when we use a BankAccount object, and SavingsAccount's accountBalance when we use a SavingsAccount object.I seriously doubt that. I think you're confusing a BankAccount with a Customer, who can have more than one account.
In every system I've ever seen, a SavingsAccount IS-A BankAccount - that is to say, it's a genuine subtype. Now, it may well contain other fields ('interest'?) that a normal account wouldn't, but 'balance' ain't one of them.
Winston
Maybe you are looking for
-
Hello there, so I was enjoying listening to music and using my various apps when suddenly I could no longer connect to the iTunes store. I went to update my apps and I was told itunes could not connect to the store 'Error 310'. I went to go online an
-
[SOLVED}_How can I configure ALSA to use usb-soundcard as default?
Hello, I am trying to figure out how to configure ALSA correctly on my system. I have tried several times following those guides : ALSA_Arch_Wiki, ALSAProject_WIKI_Usb-audio and ALSAProject_hda-intel . As I understand there are three main files for a
-
Itunes 10.6 and 10.7 crash after installing icloud control panel
I recently upgraded itunes 10.6 to 10.7 on my windows home server 2011 computer and also installed iCloud control panel 2.0. After the upgrade itunes crashes within a few seconds of starting. I can see the status bar saying that itunes is accessing
-
Hi, I have the oracle table stored name with first letter of fname and lname are upper case like below Billon, Kelly Bito, Hideo From the search page i have text box for user to enter Lname or Fname to search the user. As you know orcale is case se
-
Every time I click on Home Icon Firefox tries to put tabs up for every page I hve been on for weeks
When I start Firefox it loads only the last tabs I had when closing. BUT if I then hit the home icon it fills the tab bar with pages I was on weeks and weeks before, I dont seem to find a way to stop it.'''bold text'''