Results 1 to 20 of 20
Thread: print without built functions
- 12-26-2008, 04:54 PM #1
- 12-26-2008, 05:05 PM #2
builtin funcs?
What does "builtin functions" mean? You mean methods from classes like Scanner and System?
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-26-2008, 05:12 PM #3
we should not use methods that are present in any classes..
- 12-26-2008, 05:16 PM #4
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
- 12-27-2008, 03:51 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 12-27-2008, 01:43 PM #6
- 12-27-2008, 05:51 PM #7
<< ?
The only thing that I can think of (and is from C++ world) is writing to stdout:
I have no idea if there's something similar in JavaJava Code:cout << "x=" << 3 << endl;
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-27-2008, 06:01 PM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 12-27-2008, 09:20 PM #9
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.
- 12-27-2008, 09:48 PM #10
Member
- Join Date
- Dec 2008
- Location
- Italy
- Posts
- 79
- Rep Power
- 0
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!
- 12-28-2008, 02:32 AM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 12-28-2008, 02:34 AM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 12-28-2008, 03:25 AM #13
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
- 12-28-2008, 07:33 AM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
That's why most of the people mess with this thread. :)
- 12-28-2008, 11:32 AM #15
Member
- Join Date
- Dec 2008
- Location
- Italy
- Posts
- 79
- Rep Power
- 0
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...)
- 12-28-2008, 04:36 PM #16
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I think you are misunderstand here. Look at the third post of this thread.
What you think about that?we should not use methods that are present in any classes..
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.
- 12-28-2008, 04:52 PM #17
Member
- Join Date
- Dec 2008
- Location
- Italy
- Posts
- 79
- Rep Power
- 0
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:
And then, after a few posts:write a program to get input as "12+5-7" like this and print output without using standard function
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).we should not use methods that are present in any classes
Good Bye
- 12-28-2008, 04:58 PM #18
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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?
- 12-28-2008, 05:18 PM #19
Member
- Join Date
- Dec 2008
- Location
- Italy
- Posts
- 79
- Rep Power
- 0
Yes, you guessed. There is no other way. Take a look at the source of JDK 5 System.java
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.Java Code:public final class System { /* First thing---register the natives */ private static native void registerNatives(); static { registerNatives(); } ... public final static InputStream in = nullInputStream(); ... }
Bye
- 12-28-2008, 05:22 PM #20
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Ya ya, I know that story lol. :) We just mess up here. It's clear now.
Similar Threads
-
Functions in jsp
By samson in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 03-25-2009, 10:04 PM -
Netbeans built .jar for Mac
By zobelogne in forum NetBeansReplies: 2Last Post: 11-03-2008, 04:54 PM -
Print the text file and print preview them
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 11:04 PM -
Using the built-in enumeration methods
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:35 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks