| | |
Help with implementing a Loader[Operating Systems]
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2008
Posts: 79
Reputation:
Solved Threads: 0
I have this big operating system's project where I have to basically write my own mini operating system. I have everything broken into pieces and am taking it step by step. Starting with the loader. Prior to this class, I had no idea how intricate an OS system was and everything is fairly new to me. I've decided to do this in java for various reason mainly b/c it'll be a good refresher for me. Coding isn't my strong point...actually its probably a weak point and it's been 2 yrs since I last worked with java.
Can any1 with the patience and expertise help me through this ordeal? Ok so i understand the basic concept of the loader and i've started something here....the reading the input part. I have yet to get to implementing the part where it loads it into memory [I'll be using an array].
Can someone help me double check this?
Thank you! Whoever decides to help me will be getting a lot of this!
Can any1 with the patience and expertise help me through this ordeal? Ok so i understand the basic concept of the loader and i've started something here....the reading the input part. I have yet to get to implementing the part where it loads it into memory [I'll be using an array].
Can someone help me double check this?
Java Syntax (Toggle Plain Text)
import java.io.*; public class Loader { public static void main(String args[]) String line = null; int count = 0; try { FileReader input = new FileReader();//args[0]); BufferedReader buffRead = new BufferedReader(new FileReader(input)); while((line=buffRead.readLine()) != null) { System.out.println(count+": "+line); line = bufRead.readLine(); count++; } } catch (IOException e) { // catch possible io errors from readLine() System.out.println("Got an IOException error!"); e.printStackTrace(); } close buffRead(); }
Thank you! Whoever decides to help me will be getting a lot of this!
What problem are you having with it?
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Jan 2008
Posts: 79
Reputation:
Solved Threads: 0
When i compile it i get these errors.....and its more so that I don't know how to implement the second part.....have it write what it reads into memory.
Errors:
Its pretty late.....I'm going to wake up early in the morning to start back on this...
Errors:
Java Syntax (Toggle Plain Text)
Loader.java:39: ';' expected close buffRead(); ^ Loader.java:41: reached end of file while parsing } 1A 00 00 00 00 00 00 00 00 00 ^
Its pretty late.....I'm going to wake up early in the morning to start back on this...
On this line
you have the method before the object. Is that right? No. How did you call readLine? Call close the same way.
As for "the second part" Java does not give you direct access to memory.
You should not be doing this stuff in main. You need to place it into a different method, and have that method return a String, or StringBuffer, or something to that effect. Then other parts of your program/os/whatever will simply call the method, using the filename as a parameter, and retreive the whatever as the result.
Java Syntax (Toggle Plain Text)
close buffRead();
As for "the second part" Java does not give you direct access to memory.
You should not be doing this stuff in main. You need to place it into a different method, and have that method return a String, or StringBuffer, or something to that effect. Then other parts of your program/os/whatever will simply call the method, using the filename as a parameter, and retreive the whatever as the result.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Jan 2008
Posts: 79
Reputation:
Solved Threads: 0
Was i just tired when that happened? Thanks for pointing those things out to me. Here is a basic sketch of what am trying to do:
The driver is my main and its going to call the loader which in turn loads user programs, which will already be assembled by our professor (given as a stream of hex character) and stored in a ‘program-file.’
The basic steps of the loader are:
Update:
Am still getting the second error and I know you said I needed to do it in a method and I did. But rather than throw the exception, i still get the second error.
Java Syntax (Toggle Plain Text)
Driver { loader(); loop scheduler(); dispatcher(); CPU(); waitforinterrupt(); endloop; }
The basic steps of the loader are:
Java Syntax (Toggle Plain Text)
while (not end-of-program data-file) do { Read-File(); Extract program attributes into the PCB Insert hex-code into simulated RAM }
Update:
java Syntax (Toggle Plain Text)
import java.io.*; public class Driver { //--------------------------------------------------< main >--------// public static void main (String[] args) { Driver D = new Driver(); D.loader(); } //--------------------------------------------< loader >--------// public StringBuffer loader() { String line = null; int count = 0; try { FileReader input = new FileReader(args[0]).input(); BufferedReader buffRead = new BufferedReader(new FileReader(input)); line = new String(); while((line=buffRead.readLine()) != null) { System.out.println(count+": "+line); line = bufRead.readLine(); count++; } } catch (IOException e) { // catch possible io errors from readLine() System.out.println("File input error!"); e.printStackTrace(); } buffRead.close(); }
Am still getting the second error and I know you said I needed to do it in a method and I did. But rather than throw the exception, i still get the second error.
Last edited by orangejuice2005; Sep 18th, 2008 at 12:57 pm.
Java Syntax (Toggle Plain Text)
while((line=buffRead.readLine()) != null) { System.out.println(count+": "+line); line = bufRead.readLine(); count++; }
Delete the readLine in the body of the while loop.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Jan 2008
Posts: 79
Reputation:
Solved Threads: 0
Thanks I realized that earlier and i've already stopped getting that error. Am trying to figure out how to store an indefinite number of strings into an array. And am going through a trial and error process here. This is a sample data to be read in:
In the middle of things i get this error and i don't know why I do b/c there really is no file being read yet....
Update:
Java Syntax (Toggle Plain Text)
// JOB 1 17 2 0xC050005C 0x4B060000 0x4B010000 0x4B000000 0x4F0A005C 0x4F0D00DC
In the middle of things i get this error and i don't know why I do b/c there really is no file being read yet....
Java Syntax (Toggle Plain Text)
Loader.java:72: reached end of file while parsing
Update:
java Syntax (Toggle Plain Text)
import java.io.*; public class Driver { //--------------------------------------------------< main >--------// public static void main (String[] args) { //array to hold data String[] Data = new String[0]; Driver D = new Driver(); D.loader(); } //--------------------------------------------< loader >--------// public StringBuffer loader() { String line = null; int count = 0; try { FileReader input = new FileReader(args[0]).input(); BufferedReader buffRead = new BufferedReader(new FileReader(input)); line = new String(); while((line=buffRead.readLine()) != null) { System.out.println(count+": "+line); Data = add(line, Data); //add each line to the array as it reads count++; } buffRead.close(); } catch (IOException e) { // catch possible io errors from readLine() System.out.println("File input error!"); e.printStackTrace(); } print(Data); } private static String[] add(String s, String[] array) { int len = array.length; String[] temp = new String[len+1]; System.arraycopy(array, 0, temp, 0, len); temp[len] = s; return temp; } private static void print(String[] data) { for(int i = 0; i < data.length; i++) System.out.println(data[i]); }
•
•
Join Date: Jan 2008
Posts: 79
Reputation:
Solved Threads: 0
Thanks! Both of you! Ezzaral you were right about there being a missing closing brace. After I added the brace though I kept getting I know one way to solve it would be changing the return type to void but masijade previously said that I needed to be doing this as a method and have a String or StringBuffer return type but when I tried to do that I got the error. When i added a return statement....it kept on saying
Maybe i was putting the return statement in the wrong place or i really have no clue of what am talking about.
Java Syntax (Toggle Plain Text)
missing Return type error.
Java Syntax (Toggle Plain Text)
Cannot find symbol.
Maybe i was putting the return statement in the wrong place or i really have no clue of what am talking about.
I believe Masijade had something like this in mind, though I could be a bit off--
--notice the dummy String declared near the top of the method. You'll have to change it to the actual path for the file you ned to read information from.
As for commenting out your String-appending method, I instead used an ArrayList to append each String to the list. If your Instructor will not allow this, uncomment the method and use that instead of an ArrayList.
For more information about ArrayLists, refer to this link.
Edit: Also if this isn't a multi-threaded application and speed is an issue, StringBuilder may be preferable instead of using a StringBuffer.
java Syntax (Toggle Plain Text)
import java.io.*; import java.util.ArrayList; public class Driver { //--------------------------------------------------< main >--------// public static void main (String[] args) { //array to hold data //String[] Data = new String[0]; Driver D = new Driver(); System.out.println(D.loader().toString()); // displays the information collected by the StringBuilder in loader } //--------------------------------------------< loader >--------// public StringBuffer loader() { String line = null; int count = 0; String example = ""; // dummy string, change this to the file that needs to be read ArrayList<String> variableSizeArray = new ArrayList<String>(0); // resizable array that is initially 0 lengthed StringBuffer sb = new StringBuffer(); try { // does FileReader.input() exist? And does it return a FileReader object? FileReader input = new FileReader(/*args[0]*/ example)/*.input()*/; // BufferedReaders wrap Reader objects, and input is already a Reader =P BufferedReader buffRead = new BufferedReader(/*new FileReader(*/input/*)*/); line = new String(); while((line=buffRead.readLine()) != null) { System.out.println(count+": "+line); variableSizeArray.add(line); //add each line to the array as it reads count++; } buffRead.close(); } catch (IOException e) { // catch possible io errors from readLine() System.out.println("File input error!"); e.printStackTrace(); } String Data[] = variableSizeArray.toArray(new String[variableSizeArray.size()]); print(Data); for(int i = 0; i < Data.length; i++) sb.append(Data[i]); return sb; } /* private static String[] add(String s, String[] array) { int len = array.length; String[] temp = new String[len+1]; System.arraycopy(array, 0, temp, 0, len); temp[len] = s; return temp; } */ private static void print(String[] data) { for(int i = 0; i < data.length; i++) System.out.println(data[i]); } }
--notice the dummy String declared near the top of the method. You'll have to change it to the actual path for the file you ned to read information from.
As for commenting out your String-appending method, I instead used an ArrayList to append each String to the list. If your Instructor will not allow this, uncomment the method and use that instead of an ArrayList.
For more information about ArrayLists, refer to this link.
Edit: Also if this isn't a multi-threaded application and speed is an issue, StringBuilder may be preferable instead of using a StringBuffer.
Last edited by Alex Edwards; Sep 18th, 2008 at 6:21 pm.
![]() |
Other Threads in the Java Forum
- Previous Thread: Need a little help
- Next Thread: JOptionPane
| Thread Tools | Search this Thread |
account android api applet application array arrays automation bidirectional binary birt bluetooth chat class classes client code columns component data database designadrawingapplicationusingjavajslider eclipse editor error errors event exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance input integer intellij j2me java javaprojects jlabel jme jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source plazmic print problem program programming project property recursion ria scanner screen search server set size sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads time tree windows






