is System class comes under Singleton category in Java ? If Yes, how can i create a single object for System ?
78985
No it does not.\n\nSometimes it's appropriate to have exactly one instance of a class: window managers, print spoolers, and filesystems are prototypical examples. Typically, those types of objects—known as singletons—are accessed by disparate objects throughout a software system, and therefore require a global point of access. Of course, just when you're certain you will never need more than one instance, it's a good bet you'll change your mind.\n\nThe Singleton design pattern addresses all of the previous paragraph's concerns. With the Singleton design pattern you can:\n\n    * Ensure that only one instance of a class is created\n    * Provide a global point of access to the object\n    * Allow multiple instances in the future without affecting a singleton class's clients\n\nAlthough the Singleton design pattern—as evidenced below by the figure below—is one of the simplest design patterns, it presents a number of pitfalls for the unwary Java developer. This article discusses the Singleton design pattern and addresses those pitfalls. \n\n Example 1. The classic singleton\n\npublic class ClassicSingleton {\n   private static ClassicSingleton instance = null;\n\n   protected ClassicSingleton() {\n      // Exists only to defeat instantiation.\n   }\n   public static ClassicSingleton getInstance() {\n      if(instance == null) {\n         instance = new ClassicSingleton();\n      }\n      return instance;\n   }\n}\n\nThe singleton implemented in Example 1 is easy to understand. The ClassicSingleton class maintains a static reference to the lone singleton instance and returns that reference from the static getInstance() method.\n\nThere are several interesting points concerning the ClassicSingleton class. First, ClassicSingleton employs a technique known as lazy instantiation to create the singleton; as a result, the singleton instance is not created until the getInstance() method is called for the first time. This technique ensures that singleton instances are created only when needed.\n\nSecond, notice that ClassicSingleton implements a protected constructor so clients cannot instantiate ClassicSingleton instances; however, you may be surprised to discover that the following code is perfectly legal:\n\npublic class SingletonInstantiator {\n  public SingletonInstantiator() {\n   ClassicSingleton instance = ClassicSingleton.getInstance();\nClassicSingleton anotherInstance =\nnew ClassicSingleton();\n       ...\n  }\n}\n\nHow can the class in the preceding code fragment—which does not extend ClassicSingleton—create a ClassicSingleton instance if the ClassicSingleton constructor is protected? The answer is that protected constructors can be called by subclasses and by other classes in the same package. Because ClassicSingleton and SingletonInstantiator are in the same package (the default package), SingletonInstantiator() methods can create ClassicSingleton instances. This dilemma has two solutions: You can make the ClassicSingleton constructor private so that only ClassicSingleton() methods call it; however, that means ClassicSingleton cannot be subclassed. Sometimes, that is a desirable solution; if so, it's a good idea to declare your singleton class final, which makes that intention explicit and allows the compiler to apply performance optimizations. The other solution is to put your singleton class in an explicit package, so classes in other packages (including the default package) cannot instantiate singleton instances.\n\nA third interesting point about ClassicSingleton: it's possible to have multiple singleton instances if classes loaded by different classloaders access a singleton. That scenario is not so far-fetched; for example, some servlet containers use distinct classloaders for each servlet, so if two servlets access a singleton, they will each have their own instance.\n\nFourth, if ClassicSingleton implements the java.io.Serializable interface, the class's instances can
130751
As far as I know, there is no way untill now,\nBut there is a Java system tray icon from which you can see Java console. I'm not sure but you may be able to see a list from there.
1081144
A static method does not require an instance of an object (which is why you can't use "this" within it), whereas an instance menthod requires you to have an instance of an object.\n\nFor example, if you have a class called "Person":\n\npublic class Person\n{\n     public string FirstName;\n     public string LastName;\n\n     public string GetFullName()\n     {\n            return this.FirstName + " " + this.LastName;\n     }\n\n     static public string GetFullName(string First, string Last)\n     {\n           return First + " " + Last;\n     }\n}\n\nThe first method is an instance method. You would have to call it using an instance of a Person object:\n\nPerson objPerson = new Person;\nobjPerson.FirstName = "John";\nobjPerson.LastName = "Doe";\nResponse.Write( objPerson.GetFullName() );\n\nThe second method is a static method. You don't need a current Person object to execute it.\n\nResponse.Write( Person.GetFullName("John", "Doe") );\n\n\nStatic methods are helpful for when you don't need to the overhead of instancing an entire object just to perform one menial function.
142743
First make sure that the class which contains ur               main (String args[])\nfunction hass got the same name as ur file name.\nIf u r using command prompt to run ur program make sure u have set the classpath properly or copy ur file to the bin directory of the jdk installation and run it from there.
507128
We need the notion of a parent class (from which we can inherit) that is prohibitted from being instantiated.\n\nThink about abstract classes as semicomplete generalised implementations that can not exist as objects on their own, they can only exist as parts of child objects. \n\nFor example, think of a "Shape" hierarchy with subclasses such as Rectangle, Circle, Line etc. As shapes share data and implementation (i.e. coordinates, ability to paint themselves) it makes sense generalising, that is, creating a parent class (Shape) that contains all common aspects of the shapes. So at this point "Shape" is just a superclass.\nIt does not make sense however being able to instantiate an object of the class Shape because it misses critical information. To prohibit it,we make the class an abstract class.\nFor quick info on abstract classes & methods look at:\nhttp://www.thanassis.com/java/java%20training%20course/java%20and%20object%20orientation.htm#JavaAbstractClasses\nhope it helps :)
798508
You have to enable the Eclipse console by default. System.out will print to it by default, so that's why it will open the console, but System.in won't! System.in will read from standard jre input stream which is set to the OS console by default.
15887
You cannot call the garbage collector explicitly from your program.\n\nCalling System.gc() just flags the jvm, indicating you wish to garbage collect. Garbage collection may or may not occur immedietly. \n\nYou cannot force a garbage collection to occur at the preceise moment you want - that is the main point.
932102
You...cannot. Either declare it as a static variable, or create an instance of the object it is in.
528808
It purely depends upon the programming language u use\n\nThe following is in C#\nThread.CurrentThread.Name = "Main thread";\nClass1 obj = new Class1();\nThread thread = new Thread(\nnew ThreadStart(obj.ThreadStart));\nthread.Name = "Forked thread";\n\nNow in Java\nJava's creators have graciously designed two ways of creating threads: implementing an interface and extending a class. Extending a class is the way Java inherits methods and variables from a parent class. In this case, one can only extend or inherit from a single parent class. This limitation within Java can be overcome by implementing interfaces, which is the most common way to create threads\nthread.Start();\n\nimport java.lang.*;\npublic class Counter extends Thread \n{                      \n        public void run()                       \n        {              \n        ....            \n        }\n}\n\nand\n\nimport java.lang.*;\npublic class Counter implements Runnable\n{\n        Thread T;                        \n        public void run()                       \n        {                              \n        ....            \n        }\n}
150471
*  Objects...\n          o Autonomous entities\n          o No direct access to their components, or run time type2\n          o Interact purely by messages, with no assumption of implementation \n\n    * Object Organization...\n          o Inheritance mechanism to construct an object classification hierarchy\n          o Not just for code sharing\n          o Must have abstract nodes in hierarchy for more realistic modeling\n          o Provide potential for individuality in objects\n          o Dynamicly determine (via run time type) correct response to messages \n\n    * Programs as Models...\n          o Programs model the development of some planned system\n          o Changing state of system reflected by the changing state of the objects\n          o Objects can be thought of as acting concurrently\n          o Support for ``non OO'' programming techniques in situations where they make sense
178015
It's been a while since I did anything in Java but I'm fairly certain it's just this:\n\nfile.add(new MenuItem("Print"));\nfile.add(new MenuItem("-"));\nfile.add(new MenuItem("Exit"));\n\n..give it a shot.
463342
yse u can.Why because u r getting the values based on the hashcode.So hashcode is unique based on the u will get that object
599192
In the object oriented world of thinking you have objects that are made of classes. These classes can be ordered through a special inheritance relationship into hierarchies of parent/child relationships. \n\nUpcasting means taking a reference to an object and changing\nits type to that of any of its parent classes. (for java, add to this list also all the interfaces that any of the parent classes may be implementing)\n\nFor example:\nclass A extends B{\n}\nclass B{\n}\nclass Program{\n\n    .......\n    B b = new B();\n    A a = (A) b; // this is upcasting!\n    .......\n}\n\nUpcasting in java is implicit. This means that you dont need\nthe preceding parenthesis with the upcasting type.\n    A a = b;\nwould have equally worked. This is because you are going from something specific (class B - child) to something more general (class A - parent) and the java compiler can infer this fact by its design.\n\nDowncasting is the opposite:\n    .......\n    A a = new B(); //here you have an object from class B\n                   //referenced to a variable of class A\n                   //Implicit upcasting happens here.\n\n    B b = (B) a; // this is downcasting.\n\nDowncasting must be explicit. If you try to downcast an\nobject to a type that cant be downcasted to, then the compiler will offer protection by giving you an error.\nOtherwise your program would have crashed at runtime.\n\nYou can test with the operator instanceOf whether a \ndowncast is safe.\nexample:\n   if (a instanceOf (B)) { \n        b = (B)a;\n   }\n\nThe problem with this is that it creates a dependency in that segment of code and the type B. If in the future you create sibling to B classes you will have to remember to change all the places where you are checking with "instanceOf" and this can be a try nightmare on a large system.\n\nSo, generally speaking, you want to create code that avoids downcasting. This is not always possible and not always a good idea as there are many cases where explicit downcasting is needed or at least is possible to use without problems. \nAgain generally speaking, you want to create designs that have parts that are as independent, decoupled, reusable, robust, modular, and change adaptive as possible. This is not easy because many of these forces lead you to contradictions. So its all about making choices.\n\nfor an easy visual guide to java have a look at an online tutorial that I have recently added to: http://www.thanassis.com/java/index.htm
207768
%SystemRoot%&#92;\nsystem32&#92;\ndfrg.msc\n\nDecompile for C/C++\n\n:-)
53359
A constructor is a piece of code that is called when an instance of a class is created.\n\nYou usually use the constructor to initialize the object's attributes and state, perhaps with some parameters passed to it.\n\nConversely, the destructor is called when the object is destroyed.\n\nYou only need to explicitly define a destructor if you have cleanup code you want performed. Perhaps your instance needs to free up additional memory elsewhere, or you want to close an open file or something.\n\nExpansion of what humill_bca states: It is not required for a constructor to be public, and I don't believe should be one of its criteria. I don't know if its a language constraint of C++, but I code in Java, and we see private constructors all the time, espcially when implementing the Singleton Design pattern, or prior to Java 1.5, building your own enumerated type-safe classes, where we want to prevent the programmer from explicitely instantiating an instance of a class.
161388
The idea is to equate a "programming object" to a "real world object."  Using a very simple and probably useless example (don't know how to indent here, code looks a little screwy):\n\nclass apple :\n  color = 'red'\n  def get_color(self) :\n    return self.color\n\nSo you could create an apple object & get its color:\n\na = apple()\nprint a.get_color()\n\nSlightly more useful might be a Person object for an address book, for instance:\n\nclass Person :\n  def get_address(self):\n     ...\n  def get_phone_number(self):\n     ...\n  def get_name(self) :\n     ...\n  def get_age(self) :\n     ...\n\n#blah blah blah\n\nSo, Object Oriented programming is mostly just a way to organize your program so classes (i.e. objects) resemble real objects.  This is very handy for keeping code maintainable.\n\nThere are more advanced Object oriented concepts, such as polymorphism and inheritance, but it's easier you to google them than for me write out examples :)
1131033
The first is a Java Class called Main.\n\nThe second is the constructor for this class. This is what isused to basically set the class up and make an instance of it.\n\nThe third is a method called main which takes in a string array which you have named args. You could call args whatever you want, its juts a general name most coders put on it. It has a modifier which is static and is public so other classes can invoke it. The main method is what is looked for by the java compiler at run time when you execute the program.\nSo a class may look like this:\n\npublic class Main\n{\npublic String greeting;\n\n public Main()\n{\ngreeting = "hello"\n}\n\npublic static void main(String[] args)\n{\nSystem.out.println(args[0]);\nSystem.out.println(greeting);\n}\n}\n\nThis would result in the value stored at args[0] being printed out. Then "hello" printed out on a new line.\nThe args are the arguments that you pass to your program. Most programs take in strings or ints.