Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 20-09-2008
Member
 
Join Date: Sep 2008
Posts: 1
java

can any buddy tell me can we make constructer as private in java the progran will run or not
Reply With Quote
  #2  
Old 20-09-2008
Member
 
Join Date: Dec 2007
Posts: 2,273
Have a look here: http://www.javapractices.com/topic/TopicAction.do?Id=40
Reply With Quote
  #3  
Old 20-09-2008
Member
 
Join Date: Dec 2007
Posts: 1,592
If you have a method that has a parameter that can take on only a limited set of values then use typesafe enumeration. Example method

Code:
public void setMode(TypeSafeEnum  mode)
{
...
}
where TypeSafeEnum is defined by

Code:
public class TypeSafeEnum {
  
  public static final TypeSafeEnum ONE = new TypeSafeEnum();
  public static final TypeSafeEnum TWO = new TypeSafeEnum();
  public static final TypeSafeEnum THREE = new TypeSafeEnum();
  public static final TypeSafeEnum FOUR = new TypeSafeEnum();
  
  private TypeSafeEnum() {}
}
It then become impossible to pass a wrong value (other than null) to the method.
Reply With Quote
  #4  
Old 20-09-2008
Member
 
Join Date: Jun 2006
Posts: 620
I make all my constructors private:

Code:
public class Private {
    private String string;
 
    private Private(String string) {
        this.string = string;
    }
 
    public String toString() {
        return string;
    }
}

Then I do the following:

Code:
import java.lang.reflect.*;
 
public class Test{
    public static void main(String[] args) throws Exception {
         Constructor<Private> constructor = Private.class.getDeclaredConstructor(String.class);
         constructor.setAccessible(true);
         Private obj = constructor.newInstance("bingo");
         System.out.println(obj);
    }
}
Reply With Quote
  #5  
Old 26-09-2008
Member
 
Join Date: Sep 2008
Posts: 1
ava is a programming language expressly designed for use in the distributed environment of the Internet. It was designed to have the "look and feel" of the C++ language, but it is simpler to use than C++ and enforces an object-oriented programming model. Java can be used to create complete applications that may run on a single computer or be distributed among servers and clients in a network.
------------------------------
ages
Reply With Quote
  #6  
Old 04-10-2008
victor2008
 
Posts: n/a
Java Game

Now a days every animated games develop by the help of Java. The looking of Java is attract to people and the man who love the plying games. The use of MVC Pattern by architectural make the Java game more attractive.
Reply With Quote
  #7  
Old 02-03-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: java

Typically you declare methods private to prevent others from calling them. If you declare a constructor private, you prevent others from creating objects of your class from the outside. This makes sense under some circumstances, e.g. if you implement the so called singleton pattern. This pattern makes sure, that only one object of a certain class exists, so you have to control explicitly, who creates that one and only object.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "java"
Thread Thread Starter Forum Replies Last Post
Java Auto Updater wants me to update java everyday in Windows 7 minajoh Windows Software 4 04-09-2013 11:04 PM
Setting Of Java to The Point At Manual Java winni Software Development 4 10-01-2011 10:05 PM
Java Programming using Adventnet SNMP Java API ROCKING_Suhas Software Development 5 17-07-2010 06:52 AM
Link List Example in Java Sample program in Java trickson Software Development 2 04-08-2009 08:23 PM


All times are GMT +5.5. The time now is 08:59 PM.