Results 1 to 20 of 20
  1. #1
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    Default print without built functions

    write a program to get input as "12+5-7" like this and print output without using standard function,,


    no builtin java functions to be used to get any input like this and also for output,,,
    Last edited by j2vdk; 12-26-2008 at 04:57 PM.

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default builtin funcs?

    What does "builtin functions" mean? You mean methods from classes like Scanner and System?

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    Default

    we should not use methods that are present in any classes..

  4. #4
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    Default

    if system class can be used,,, then i can simple use System.out.println(); method,,,, these methods should not be used, so give any way to write without using these methods

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by j2vdk View Post
    we should not use methods that are present in any classes..
    I don't know what you are going to do. How can I do that without using any standard methods/classes?

  6. #6
    j2vdk's Avatar
    j2vdk is offline Member
    Join Date
    Aug 2008
    Posts
    45
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    I don't know what you are going to do. How can I do that without using any standard methods/classes?


    but this question was asked in an interview, and i too replied the same wat u said,, but they said it can be written

  7. #7
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default << ?

    The only thing that I can think of (and is from C++ world) is writing to stdout:
    Java Code:
    cout << "x=" << 3 << endl;
    I have no idea if there's something similar in Java

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I don't think so there is such a way in Java.

    To our thread starter, is this the exact question ask from you in that interview.

  9. #9
    KingZebulon's Avatar
    KingZebulon is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Default Getting Input Unconventionally

    Hello all!

    This is quite a challenge. I am just a beginner when it comes to programming. I may, however, have a solution for getting input.

    Could you possibly use the FileReader and BufferedReader classes? These are not standard classes for getting input, but they can be used to get input from text files.

    As far as output goes, I cannot think of anything. There might be a class in the javax.swing libraries.

  10. #10
    Join Date
    Dec 2008
    Location
    Italy
    Posts
    79
    Rep Power
    0

    Default You can't

    I think you simply can't. Even using a BufferedReader to read input and a PrintWriter to display output is useless, because you have to attach them to System.in and System.out. So you'll eventually happen to use the same readLine() and println()... All you done was creating 2 new useless objects.
    I studied this problem because it's fascinating, and now I think that there is no Sun Java specification to access the hardware directly (Yes, you should have direct access to the hardware not to use "standard" methods). If you don't want to use any println() or read() method of the standard library you'll end up using NATIVE (C++) method, and I don't think this is what you want. Even AWT uses native method to use the hardware, there's no Java interface to it.

    Maybe you misunderstood the meaning of "standard function". In my opinion it simply says "Don't use the Scanner class". Keep in mind that the Java language is made up by some classes. For example, it is impossible to create a Class which doesn't inherit from Object... You must use Object, Exception, Thread, Integer and... PrintStream!

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by KingZebulon View Post
    Hello all!

    This is quite a challenge. I am just a beginner when it comes to programming. I may, however, have a solution for getting input.

    Could you possibly use the FileReader and BufferedReader classes? These are not standard classes for getting input, but they can be used to get input from text files.

    As far as output goes, I cannot think of anything. There might be a class in the javax.swing libraries.
    Actually he's talking about how to input and output without using standard functions. Classes you are talking about also standard with JDK, and hence all the functions contain there also standard.

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by raffaele181188 View Post
    Maybe you misunderstood the meaning of "standard function". In my opinion it simply says "Don't use the Scanner class". Keep in mind that the Java language is made up by some classes. For example, it is impossible to create a Class which doesn't inherit from Object... You must use Object, Exception, Thread, Integer and... PrintStream!
    Just looking at the 3rd post of this thread.

    we should not use methods that are present in any classes..

  13. #13
    KingZebulon's Avatar
    KingZebulon is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Default

    If you can't use built-in functions, how is it possible? You would have to reinvent the wheel every time because you would have to write your own version of the classes that are already built for you in the libraries.

    If I am misunderstanding that and you can in fact use built-in functions (just not the standard ones), you could possibly create shapes and draw the output on the screen by moving and manipulating the shapes to make words. This would not require the use of System.

    Cheers

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  15. #15
    Join Date
    Dec 2008
    Location
    Italy
    Posts
    79
    Rep Power
    0

    Default

    Eranga, I don't understand you. I silmply think that, if you can't use neither System.in or System.out, THE ONLY WAY to read input and display output si c++ code. If you downloaded the source of the Sun JDK and looked at System.java you could realize it. Althought System.in and System.out are declared to be a BufferedReader and a PrintStream, they're implemented through NATIVE code. So, if Sun used c++ to get it, how could you avoid it?
    In my opinion, simply there isn't a way to "java coding" such a thing: you should use another language. That's why (imvho) j2vdk misunderstood the meaning of "standard function": without using System.in, System.out and their methods, you can't use Java code. But maybe this is a way to test its ability in mixing java and native code... (And this happen to be a lil strange...)

  16. #16
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I think you are misunderstand here. Look at the third post of this thread.

    we should not use methods that are present in any classes..
    What you think about that?

    For me, you cannot do this in Java. Because anyhow he has to use any standard function such as println(), print(), printf().... I don't know any way to do this without using standard functions on Java classes. Using C/C++ it's possible, but not with Java.

  17. #17
    Join Date
    Dec 2008
    Location
    Italy
    Posts
    79
    Rep Power
    0

    Default

    I don't see any problem. We totally agree. If he needs to avoid existing methods, he has to use tha java native interface. I simply wrote this in my previous posts.

    In the 1st post j2vdk said:
    write a program to get input as "12+5-7" like this and print output without using standard function
    And then, after a few posts:
    we should not use methods that are present in any classes
    I think this two things are slightly different, because you could EITHER use non-standard ways to get that (maybe you rely on an existing project using import statement, ore use an exotic jdk class whose existence I am not aware of) OR you have to reimplement by yourself that functionality. These are 2 different things and if he needs the latter (completely new implementation) then he can only write C++ code through JNI. Java by itself is not sufficient (look at the Sun JDK source).

    Good Bye

  18. #18
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Then what's the non-standard way to do this in Java? I think you are talking about the native interface implementation using C/C++, right?

  19. #19
    Join Date
    Dec 2008
    Location
    Italy
    Posts
    79
    Rep Power
    0

    Default

    Yes, you guessed. There is no other way. Take a look at the source of JDK 5 System.java
    Java Code:
    public final class System {
    
        /* First thing---register the natives */
        private static native void registerNatives();
        static {
            registerNatives();
        }
    
    ...
    
        public final static InputStream in = nullInputStream();
    
    ...
    
    }
    It's quite difficult to read, I've not understood it very well. But I realized that, to read from the keyboard and sending output to the screen, your only chance is to use C++ code.

    Bye

  20. #20
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Functions in jsp
    By samson in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 03-25-2009, 10:04 PM
  2. Netbeans built .jar for Mac
    By zobelogne in forum NetBeans
    Replies: 2
    Last Post: 11-03-2008, 04:54 PM
  3. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM
  4. Using the built-in enumeration methods
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •