Simulation On Assembly Code Level By Writing A Mini-compiler
Sep 28, 2014
I need to do a simulation on the assembly code level by writing a mini-compiler for each ISA, i.e., 4, 3, 2-Address Architecture, Accumulator Architecture, Stack Architecture, and Load-Store Architecture.The input to the simulator is a segment of C program:The basic sample segments of C code are:
I'm a beginner fiddling around classes in Java. I noticed on this particular code, Eclipse will give me an error and suggest I put the static keyword in front of the variable.
public class test { //the following line is where Eclipse puts the static keyword static FileAccess hello = new FileAccess("D:" + '\', ".mp3"); public static void main(String[] args) { for (int i = 0; i < hello.getTotalNumberOfFiles(); i++) {
[Code] .....
The FileAccess class is just a class I made while trying to retrieve filenames from my hard drive.
As far as I can tell, it works correctly after I put the static keyword there. I just want to know why it is required in this particular code, considering it didn't need to do that when I made a simpler class while I was getting my feet wet at creating classes in Java.
I realized I wasn't capitalizing certain things, and when I did it i was able to run the compiler. is there a utility or tool that auto formats the capitalization and such? I read kathy mentioning about eclipse I installed I don't know where that feature is.
I have a big problem with writing Gauss Elimination in Java code. This is my homework, it's true. But I want to learn this, and I don't know how to bite this. I must realise some points:
1) Create new class - Gauss Elimination with two attributes (table A (nxn) and table B with vector (n));
2) Add new method "eliminate" which transform matrix A and parametr vectors B ;
3) Add new method "solve" which calculate inverse substitution.
I am currently writing a small drawing program and I am having trouble with changing the size of the shapes. To do this, I have to access the arraylist shapes, check whether pressedX/pressedY is on any of the shapes in the arraylist using the findShape() method and then when released, uses moveBy() in the Rectangle/Oval/Line class and moveShape() in the miniDraw class to move the shape and draw it in the newreleasedX/releasedY position.
So far I think I have pin pointed the problem to being the method in all the shapes classes, that checks whether the pressedX/pressedY which is the on() method, and the findShape() method in the miniDraw class.
Me and my brother decided to make a relatively simple client/server program where clients get into a simple chat lobby and can invite others to play small games(like pong). The basic server code has been written, and we have made a special client that is used for debugging.
We use a self-defined protocol of Strings where a message looks like "4-|user,pass". The number before the delimiter "-|" is the operation code, that tells the server what kind of message this client sends. Based on that number, the server dispatches the message to the appropriate handler method. 4 is authentication for example, and the handler looks the user and pass up in a file and if found, returns true, otherwise, false. Then the server responds to the clinet with 2-|"any message" where the client will recognize opcode 2 as a "authentication accepted" and proceed with the next part of client code. In a similar way, we plan to write all message types(both in the game, in the lobby and in a game setup room).
While testing we ran into a problem where the BufferedReader .readLine() does not seem to be a blocking call like it should be, so the client keeps spamming 'null' in the output field that we made to see the server response to the message we send. When we try to debug the server code and set breakpoints at the suspicious locations, it strangely skips both while(true) loops without activating either breakpoint and executes the finally{} code, even though the client did not close the connection and the second while loop was never entered. The first while loop IS entered though, because the test client gets a "0" on its output, which is the server message indicating "please authenticate yourself".
We decided to use messages in a string format and decode it at both sides as it seemed easier than transmitting java objects and making sure they are of the same type, also for reducing overhead as much of possible.URL....
I am working on a game engine with java. I have come to the final stages of the development of this engine now and need a small hand. For this i am using java's built in libary for graphics. and am strugling to create a nice looking GUi with it, What i need:
The class extends the canvas class and adds it to the jframe, i have set the window up as standard and added a menubar, and net the canvas, what I want to do.
For those of you that have used application such as tiled (shown here [URL] .....) what i am wanting to do is create a gui around the canvas similar to this where the parts on the right are resizable up and down and in and out. i was wondering how i would go about incorporating this.
I have come across some code where it attempts to save an entity to a database, but before it does it validates that the name of the entity is unique. If it is not unique it throws a runtime exception. This results in the ugly default exception web page being displayed. Is there any way to propagate this back to the JSF page where the user enters and clicks the form button to save the entity? The page already handles some error cases such as "field required" using the h:inputText's 'required' attribute. Need something more for name validation.
Can we set the class path for one level down the current directory? My structure is like
binlibresourceshexicon.cmdinside the folder dist.
In this case I could run the .cmd file which has java -cp .;lib;resources client.Test .
c: rycpdist>java hexicon.cmdBut if i put the .cmd file inside bin as like this and run as c: rycpdistin>java hexicon.cmdI am getting this error Error: Could not find or load main class
Is there any possibility to set the class path in this case
I know that below code would put a lock on current instance of DemoClass, What I am not sure of is the role of lock on Object Class in second example. How does below works - Is it putting a lock on Object Class? If yes how will putting a lock on Object? I mean, locking DemoClass ensure no two threads access it concurrently, how does this apply to Object class?
private final Object lock = new Object(); synchronized (lock) public class DemoClass { public void demoMethod(){ synchronized (this)
We are working with LinkedBinarySearchTrees. One of specs on my assignment is to "Using a level-order traversal, create a 2-D display of your trees, using the forward and back slashes as the branch lines. The tree nodes should be spaced proportionally to show the structure of the tree neatly."
I need creating a code that will create random addition or subtraction from 0-500 depending on their grade level. I know how to create a random for the math and subtraction. I just dont know how to get it to change depending on their grade level. Example I need it to ask their name, grade level, addition or subtraction then five addition or subtraction questions depending on what they chose.
As web server has multiple threads to serve client requests in Thread Pool & to ensure Thread Safety we should not use any variables or Objects at Instance/Class level.But in case of Session Variable which one is the Best Practice as the Session object is used by all the requests to have the same Session ID.
My Code :
public class MyServlet extends HttpServlet { private static Logger log = Logger.getLogger(ClientRegistrationServlet.class); private HttpSession session; /* This is used at Instance Level*/ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
I was thinking to make a game where two cars are going to race against each other. I already have two gif pictures which are the cars. I do now have a background and a racer track. So we can start from here.
I have made a object with construction which I called Racers. Inside that, i wrote a PaintWindow (Where the window and much more is inside), -car1, -car2. All these is private. So I made something like this now:
package p2; public class Race { private Object window; private Car car1; private Car car2; public Race(PaintWindow window, Car c1, Car c2) {
[Code] .....
But the problem is now that im kinda lost and I dont really know what to write anymore. How can I get a for example a green background on the whole PaintWindow with two Racers tracks and inside the racers tracks (Each car have each track) does it have to be cars. So I need to somehow import the cars inside it too. But thats the problem I need. that I dont really know what more to do. To make it easier, I have a Main-method in another class.
public static void main(String[] args) { PaintWindow window = new PaintWindow(); Car c1 = new Car(new ImageIcon("C:/Users/Sarah/Desktop/CarBlue.GIF")); Car c2 = new Car(new ImageIcon("C:Users/Sarah/Desktop/CarRed.GIF")); Race race = new Race(window,c1,c2); race.action(); if(args.length>0) { Paintwindow.pause(2000); window.dispose();
I'd like to learn more in Java security, namly Kerberos and SSO. The question is weather I have too weak laptop. I have 8 GB ram. How many virtualbox instances od I have to run in order to JAAS, SSO kerberos demo to simulate. For instance VM with Windows 2008 Server -> 3 GB RAM, Centos VM -> 1GB. Is 8 GB RAM in my laptop not too little?
BTW
I do not have yet experience in SSO/Kreberos but I want to know what to do in order to simulate and exercise.
I have a class "ExecuteJob" which has Print Q in the form of Priority Q.
You can keep adding job to the Q by calling one of the method in the class. However, and object cant do things simultaneity can it? While im adding a new job to the print queue, can it be executing and existing job in the print Q.
To achieve that, I would need to implement process and threads? I believe am I right? So that adding a job is independent to being removed?
I'm a student designing and developing an Air Traffic Control (ATC) system for incoming aircraft, mainly implementing the part which handles the queuing system for approaching aircraft.
So what I want to do is have a method that allows me to use the callRandomNumber method so that the matrix location with that random value is marked true for all of the boards.
I am writing a simple program to simulate a traffic light. What I want is to make them glow after each 1 second, one by one. For example: Firstly Red, then after 10 seconds, red will be put to off and yellow will start glowing and then accordingly green. This process shall continue incessantly (Just for experimental purpose). I have some arrangement done but could not figure out how to put them together in run() method of Runnable interface. I know how interthread communication works. But could not find any logic in this case when three threads will run together.
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TrafficLight extends JFrame implements Runnable { JButton red, green, yellow ; TrafficLight()
I'm very new to Java (I literally started learning it yesterday) and I've been working on a simple program that's meant to simulate interactions between optics objects and light rays.
Everything has been going really well, except that my mirrors only reflect the first ray that comes in contact with them.
Here's a screenshot : 2014-09-13 at 7.39.23 PM.jpg
I wrote 7 classes:
Main class to create the optics objectOptics class. the most important class that uses a recursive function to detect the nearest intersection point of a ray with the nearest optics object. It then calculates a reflected ray and inputs it back into the function until no intersections are found or the max recursion depth is met.Ray. creates a rays (in parametric form O + tD where O is the origin, D is the direction and t is a non-negative scalar)Object. empty abstract class used for polymorphism (so when i add more optics objects like prisms and lenses they'll share the object type)Mirror. Basically a line segment created with the Line classLine. Creates a line segmentDraw. JComponent with paintComponent function that loops through an array of shapes and draws them to the screen.
What I know so far is that the problem boils down to the checkRay() function in the Optics class. When a mirror has already reflected a ray, the line:
Intersection sec = new Intersection(ray,(Mirror)obj);
creates an intersection with a null point.
I debugged it line by line and found the problem was that my variable 't' (that is the parameter for the parametric line which represents the mirror) in the Intersection class got big values when it's meant to be between 0 and 1 (since it's a line segment), which resulted in the function returning null (as it should when 't' is not between 0 and 1).
I've confirmed with tests that this has nothing to do with the specific mirror or angle of incidence. It only occurs when a mirror has already been intersected with by a ray.
I've found out that my function:
public PVector getNormal(PVector D){ D.normalize(); return new PVector(D.y,-D.x); }
Changes the value of the 'D' PVector of the mirror inside my 'objects' ArrayList. How can it access the private PVector 'D' from outside the Mirror class? This normalization to the direction vector is what causes the Intersection class to return null the second time around!
The problem was that in the getNormal function, the input vector argument was a reference to the 'D' vector for the mirror in my 'objects' ArrayList so the .normalize() function acted upon the original vector, changing it's value and screwing things up. The two classes I talked about:
Optics: (note line 64. this line returns a null intersection when it shouldn't)
package ofer.davidson; import java.util.ArrayList; public class Optics { //Arrays to store all the optics objects and rays that are created ArrayList<Object> objects; ArrayList<Ray> rays;