what is a class in Java?
451493
I'd equate a Java Class to a noun that is being modeled in a program. The methods in the class would be the verbs. You can group classes together with a Java Package. \n\nSo\ncanine->dog->sit\n\nis to \npackage->class->method
74376
Networking in Java is fairly simple. It has a lot of features through which one can implement application level networking. Java has specialised classes for Socket Programming, and many standard protocols (esp. TCP/IP suite, UDP etc. are well supported). IO streaming classes are also an integral part of the Java networking domain.
382095
java usees wrapper classes...Byte,Integer..they are in java.lang package..\n\nin each such class there is one memeber \nstatic int SIZE\n\nusing that u can find out..\n\neg.System.out.println(Byte.SIZE);\n//The number of bits used to represent a byte value in two's complement binary form\n\nSIMILARITY FOR OTHER DATA TYPES..\n\ncheck out documentation site..or if u have already downloaded doc..then use that..
379385
Singleton classes have only one instance of the class. They are accessed like StaticFactory classes, i.e. SingletonClass.instance(). This commonality of syntax allows a StaticFactory class to be converted to a Singleton and vice versa during refactoring. A Singleton class has the following properties: \n\nThe class must be final \n\nThe class must have a single, private, no argument, constructor that throws IllegalStateException if it is called more than once \n\nIf the class is serializable then it should have a readResolve method that returns the 'singleton' \n\nThe class can't be clonable \n\nThe class must have a method called instance (see below for more details) \n\nThis instance method must: \n\nAlways return the same object \n\nHave no arguments \n\nBe static \n\nHave either package or public access \n\nThe advantages of singletons are well documented in Joshua Block, Effective Java, "Item 2: Enforce the singleton property with a private constructor", pp 10. Note: Joshua Block uses either a static field called INSTANCE or a static method called getInstance, as noted above this design of a singleton uses a static method called instance to be compatible with factory classes. \n\nIf a class is definitely a singleton with no chance of ever becoming a factory then consider using a NoInstance class instead. If you want a limited numer of instances use enum (enum is in Java 1.5).
883565
If you know the package name (like in your example), then look at this:\nhttp://forum.java.sun.com/thread.jspa?threadID=341935&start=15\n\nTo get to that point from any given object, get the object's class, and then get the Package object.\n\nClass clazz = myObj.getClass();\nPackage package = clazz.getPackage();\nString packageName = package.getName();
701316
Inner Classes \n\nInner classes let you define one class within another. \n\nThey provide a type of scoping for your classes since you can make one class a member of another class.\n\nJust as classes have member variables and methods, a class can also have member classes.\n\nclass Outer { \n/class Inner { } \n}// End of class \n\nif you compile it,\n%javac Outer.java\n\n\nyou’ll end up with two class files:\nOuter.class\nOuter$Inner.class\n\n\ne.g.\n\nclass Outer { \nprivate int x = 5;\n\npublic void outerMethod() {\nInner in = new Inner();\nin.innerMethod();\n}\n\nclass Inner {\npublic void innerMethod() {\nSystem.out.println("Outer variable x is " + x);\n}\n} \n}// End of class \n\n\nYou can create four different types of inner classes, based upon the how and the where of creation. \nNested top-level classes\nIf you declare a class within a class and specify the static modifier, the compiler treats the class just like any other top-level class. Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. eg, outer.inner. Top-level inner classes implicitly have access only to static variables. There can also be inner interfaces. All of these are of the nested top-level variety.\n\nMember classes\nMember inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables. This means a public member class acts similarly to a nested top-level class. The primary difference between member classes and nested top-level classes is that member classes have access to the specific instance of the enclosing class.\n\nLocal classes\nLocal classes are like local variables, specific to a block of code.Their visibility is only within the block of their declaration. In order for the class to be useful beyond the declaration block, it would need to implement a more publicly available interface.Because local classes are not members, the modifiers public, protected, private, and static are not usable.\n\nAnonymous classes \nAnonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor.
89402
Code:\npublic class BTNode \n{\n    private Object data;\n    private BTNode left, right;\n    public BTNode(Object initialData, BTNode initialLeft, BTNode initialRight)\n        { \n            data = initialData;\n            left = initialLeft;\n            right = initialRight;\n        }\n    public BTNode()\n            { this(null, null, null); }\n    \n    public BTNode(Object newdata)\n            { this(newdata, null, null); }\n    \n    //NODE methods\n    public Object getData()                     //return and set data in node\n            {return data;}\n    \n    public void setData(Object data)\n            {this.data = data; }\n    \n    public BTNode getLeft()                 //return and set left child\n            {return left; }\n    \n    public void setLeft(BTNode left)\n            {this.left = left; }\n    \n    public BTNode getRight()                //return and set right child\n            {return right; }\n    \n    public void setRight(BTNode right)\n            {this.right = right; }\n    \n    public boolean isLeaf()                 //return true if this is leaf node\n            {return (left == null)&&(right == null); }\n \n// TREE Methods - for tree starting at this node\n// get specific data from a tree\n    \n        public Object getLeftmostData()\n        { if(left == null)\n               return data;\n          else \n              return left.getLeftmostData(); }\n        \n        public Object getRightmostData()\n              { if(right == null)\n               return data;\n          else \n              return right.getRightmostData(); }\n// print data in a tree\n        public void inorderPrint()\n                {\n                    if (left != null)\n                        left.inorderPrint( );\n                    System.out.print(data+"&#92;t");\n                    if (right != null)\n                        right.inorderPrint( ); }\n        \n        public void preorderPrint()\n                {\n                    System.out.print(data+"&#92;t");\n                    if (left != null)\n                        left.preorderPrint( );\n                    if (right != null)\n                        right.preorderPrint( ); }\n        \n        public void postorderPrint()\n                {\n                    if (left != null)\n                        left.postorderPrint( );\n                    if (right != null)\n                        right.postorderPrint( );\n                    System.out.print(data+"&#92;t"); }\n        \n// pretty print a tree\n        //public void print(int depth);\n \n//Interface for Nodes in Binary Tree (3)\n//removing nodes from a tree\n//returns reference to tree after removal of node\n        public BTNode removeLeftmost()\n              {\n                    if (left == null)                               // we are as deep as we can get\n                        return right;                               // remove this node by returning right subt ree\n                    else\n                        {                                           // keep going down recursively\n                            left = left.removeLeftmost( );\n                                                                    // when done, return node that act ivated this\n                                                                    // method as root of t ree\n                            return this; }}\n        \n        public BTNode removeRightmost()\n        {\n                    if (right == null)                               // we are as deep as we can get\n                        return left;                               // remove this node by returning left subt ree\n                    else\n                        {                                           // keep going down recursively\n                            right = right.removeRightmost( );\n
604118
This is an identical java code for your C++ code,\n\n1. create a filename, say HelloWorld.java,\n\n2. Write in following codes,\n\npublic class HelloWorld\n{\n      public static void main (String args[])\n      {\n           System.out.println("Hello World");\n      }\n}\n\n3. Save it and compile it. Then open the class file using java.
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
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
74620
Given the architecture of the JVM, you need only be concerned with instance and class variables when you worry about thread safety. Because all threads share the same heap, and the heap is where all instance variables are stored, multiple threads can attempt to use the same object's instance variables concurrently. Likewise, because all threads share the same method area, and the method area is where all class variables are stored, multiple threads can attempt to use the same class variables concurrently. When you do choose to make a class thread-safe, your goal is to guarantee the integrity -- in a multithreaded environment -- of instance and class variables declared in that class. \n\nYou needn't worry about multithreaded access to local variables, method parameters, and return values, because these variables reside on the Java stack. In the JVM, each thread is awarded its own Java stack. No thread can see or use any local variables, return values, or parameters belonging to another thread.
145863
The premise of Object Oriented Design is that data(properties) are combined with methods to create the objects.  The methods are actually functions that the object uses.  As such, algorithms are still used to design the methods(functions) that are implemented in each object's template(class).
933481
What class did you get this question from?
775295
The idea behind an abstract class is that you can't instantiate it. It is a class that is "missing" something.\n\nAre you familiar with how memory allocation works in Java? When a class is loaded the first time it needs to have some tables initialized - for instance, transfer tables for methods, and storage for static variables. Abstract classes are the same as any other class, the tables are initialized. When an object is created the memory is allocated for all its instance variables. Since an abstract class cannot be instantiated, its instance variables are not allocated directly. When a subclass object is created the memory for all superclass objects, including abstract superclasses, is created.\n\nSo it is actually in 2 places, once when the class is initially loaded and once when a subclass is instantiated.
1066843
I'm assuming you're asking from a Java point of view, so I'll answer along those lines.\n\nAn interface defines a set of methods clustered around common theme. It provides no implementation at all. When a class "implements" an interface, it must provide an implemenation for each method defined in the interface.\n\nAn abstraction (or abstract class) also defines a set of methods clustered around a common theme. The main different is that the abstract class may have implemenation provided behind some or all of the methods, although it does not need to.\n\nIn Java, a class must extend exactly [abstract] class. If not specified, then Object is defaulted as that extended class.\n\nA class may implement as many interfaces as it wishes.
1053311
//created by vinyl21 for yahoo answers\n//gjfr77@yahoo.com\nimport java.io.*;\nclass matrix{\nint n,m;\nint a[][]=new int[100][100];\nint r[]=new int[10];\nint c[]=new int[10];\nDataInputStream d=new DataInputStream(System.in);\n\nvoid input() throws IOException{\nSystem.out.println("ENTER THE NO OF ROW");\nn=Integer.parseInt(d.readLine());\nSystem.out.println("ENTER THE NO OF COLUMN");\nm=Integer.parseInt(d.readLine());\n\nfor(int i=1;i<=n;i++){\nfor(int j=1;j<=m;j++){\nSystem.out.print("("+i+","+j+"):");\na[i][j]=Integer.parseInt(d.readLine());}}}\n\nvoid process(){\nfor(int i=1;i<=n;i++){\nfor(int j=1;j<=m;j++){\nr[i]+=a[i][j];}}\n\nfor(int j=1;j<=m;j++){\nfor(int i=1;i<=n;i++){\nc[j]+=a[i][j];}}\n}\n\nvoid display(){\nSystem.out.println("given matrix");\n\nfor(int i=1;i<=n;i++){\nfor(int j=1;j<=m;j++){\n\nSystem.out.print(a[i][j]+"&#92;t");\n\n}\nSystem.out.println("&#92;n");}\n\nSystem.out.println("row sum");\n\nfor(int i=1;i<=n;i++){\nfor(int j=1;j<=m;j++){\n\nSystem.out.print(a[i][j]);\nif(j<m)System.out.print("   +   ");\nelse System.out.print("   =   ");}\nSystem.out.println(r[i]);\nSystem.out.println();}\n\nSystem.out.println("column sum");\n\nfor(int i=1;i<=n;i++){\nfor(int j=1;j<=m;j++){\n\nSystem.out.print(a[i][j]+"&#92;t");}\n\nif(i<n){\nSystem.out.print("&#92;n");\nfor(int d=0;d<m;d++){System.out.print("+&#92;t");}\n}\nelse {System.out.print("&#92;n");\nfor(int d=0;d<m;d++){System.out.print("=&#92;t");}}\nif(i==n){System.out.println();\nfor(int k=1;k<=m;k++){\nSystem.out.print(c[k]+"&#92;t");}}\nSystem.out.println();}\n\n}\n\nvoid displaye() throws IOException{\nSystem.out.println("PRESS ANY KEY TO EXIT");\nString n=d.readLine();}\n\n\npublic static void main(String args[])throws IOException{\nmatrix k=new matrix();\nk.input();\nk.process();\nk.display();\nk.displaye();}}\n\n/*output\nI:&#92;>cd j\n\nI:&#92;j>cd bin\n\nI:&#92;j&#92;bin>java matrix\nENTER THE NO OF ROW\n3\nENTER THE NO OF COLUMN\n3\n(1,1):1\n(1,2):2\n(1,3):3\n(2,1):9\n(2,2):8\n(2,3):7\n(3,1):4\n(3,2):5\n(3,3):6\ngiven matrix\n1       2       3\n\n9       8       7\n\n4       5       6\n\nrow sum\n1   +   2   +   3   =   6\n\n9   +   8   +   7   =   24\n\n4   +   5   +   6   =   15\n\ncolumn sum\n1       2       3\n+       +       +\n9       8       7\n+       +       +\n4       5       6\n=       =       =\n14      15      16\nPRESS ANY KEY TO EXIT\n*/
23975
POJO, or Plain Old Java Object, is a normal Java object class (that is, not a JavaBean, EntityBean etc.)  and does not serve any other special role nor does it implement any special interfaces of any of the Java frameworks. This term was coined by Martin Fowler, Rebbecca Parsons and Josh MacKenzie who believed that by creating the acronym POJO, such objects would have a "fancy name", thereby convincing people that they were worthy of use.