Difference Between Interpreter And Compiler?
Aug 13, 2014I am reading a java book and find a theory about Interpreter and Compiler. explain different between them?
View RepliesI am reading a java book and find a theory about Interpreter and Compiler. explain different between them?
View RepliesAn example from the SCJP(OCP) book:
Java Code:
class Animal {
void makeNoise() {System.out.println("generic noise"); }
}
class Dog extends Animal {
void makeNoise() {System.out.println("bark"); }
void playDead() { System.out.println("roll over"); }
[Code] .....
The book states that the above code will compile if there is a downcast in the line 14 . But there is a compiler error saying playDead method is not defined for type animal even after downcasting.
Running a java source code through an online java compiler (in which you will just pass the the source code using a http request, then the compiler will return the output/error of the source code automatically)?.
View Replies View RelatedI am working in software testing, specifically automatic test cases generation. Among the existing forms of test cases, my focus is on the test cases that are composed of sequences of events such as _.event1.event2 eventx()
However, the events can be classified into: sensitive and insensitive. The latter does not affect the system's states, and hence, it can be ignored; while the former affects the states. Anyhow, the sensitive events in the test cases may lead to states explosion and there is a need to prevent that. Therefore, some techniques suggest using one variable to present states and group all similar states together such as using len variable in circular queue. Relatively, the states can be represented by using specific drawings such FSM.
For example, the test cases for circular queue may look like:
add(0).remove().add(1).Front()
add(0).add(1).remove().Front()
which produce the following states:
len=1, rear=0, front=0 and dataQ[0]=0
len=0, rear=0, front=1 and dataQ={0}
len=1, rear=1, front=1 and dataQ[1]=1
len=1, rear=0, front=0 and dataQ[0]=0
len=2, rear=1, front=0 and dataQ[1]=1
len=1, rear=1, front=1 and dataQ={1,0}
As can be seen, every addition/deletion produces a new state. A state is composed of 4 variables: len, rear, front and dataQ. The 1st three variables are integers while the dataQ is an integer array. Nonetheless, the states produced by different test cases can be identical which wastes effort and time. So, there is a need to optimize these states. The search techniques were suggested where the problem can be represented as a search problem and the technique is applied. If we consider Len as a state, then we will have: len=0; 0QSize. However, this does not represent the state but it suits for classifying the states into groups.
In terms of states representation, State Machine/Map Compiler (SMC) was suggested as a modeling mechanism that takes the state machines (i.e. FSM) drawing and generates the code in any preferred language. In SMC, the FSM is represented in a specific syntax (state---transition----next state) and saved in a file (.sm). This file will be compiled by SMC to generate a context class which includes definitions of states, transitions and actions in FSM but still need to be triggered by another class. This class has to call the transitions that modifies the state.
We had created that class and implemented all the methods with their transitions. However, the FSM used was based on 1 variable only (i.e. len). Besides, we are still looking for the SMC results as they will be the input for any search technique to be applied. Supposedly, the states generated by SMC can be used directly in the search technique but this is still questionable.
I have started to learn JAVA and was referring Head First JAVA book.
I have 3 separate .java files - GuessGame.java , Player.java, GameLauncher.java
I have successfully compiled GuessGame.java & Player.java
But I am getting an error when I am compiling GameLauncher.java.
I remember reading Instance variables & local variables (in methods) are initialized to appropriate value by the compiler.
Is this true for static class variables and variables in nested classes ?
public class Main {
private static void foo(Integer a) {
System.out.println("Integer");
}
private static void foo(long a) {
System.out.println("long");
[Code] ....
This code prints long. Why is that? How did compiler decided that it likes long version of foo() method the most. If I had to guess I'd pick int... or possibly Integer as they are most similiar to what was passed. But why long?
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.
public void init(Board board) {
JPanel Panel = new JPanel();
Panel.setLayout(new GridLayout(board.getWidth(), board.getHeight()));
getContentPane().add(Panel, BorderLayout.CENTER);
Panel.setBorder(new LineBorder(Color.BLACK)); // it does not work also
[code]....
I have a JFrame. I added two JPanels to the JFrame. The first one is GridLayout and it should be situated at CENTER. Another one is bottomPanel, and that one should be situated at SOUTH.I would like to add two new JPanels(kit and another one) to the bottomPanel.Compiler does not show any warning or errors.The problem is, that bottomPanel situates at NORTH, not at SOUTH. kit situates at CENTER of bottomPanel, not at WEST.
I was trying to execute the following codes, but the something that I don't undestand was happen. The program was compiled differently according to ouput picture of the program in my java book. Furthermore, then I tried to compile the program in eclipse and NetBeans. I saw that all of output are different each other.
package finallyblock;
public class FinallyBlock {
public static void main(String[] args) {
try{
throwException();
}
catch(Exception exception){
System.err.println("Exception handled in main");
[code]...
Is there any way to compile a program without calling constructor.
View Replies View RelatedI am trying to make lexical phase of compiler. But when I try to add character (after validating them, whether they are character or not) to token array I cannot do it.
public class Main {
static int counter;
static char ch[];
static char c;
static char token[];
static String read;
[Code] .....
My objective here is to process a HashMap's key's in order. I found SortedSet as a way to do it.
The HashMap is like this:
nobelPrizeWinners = new HashMap<String, PrizeWinner[]>();
// 2009:
nobelPrizeWinners.put(new String ("2009 Physics"), new PrizeWinner[] {new PrizeWinner("Charles K.", "Kao"), new PrizeWinner("Willard S.", "Boyle"), new PrizeWinner("George S.", "Smith")});
[Code] ....
This is the method I am trying to write
public void displayAllYearsAndWinners_2()
{
// Creation of the SortedSet
SortedSet sortedSet = new TreeSet();
[Code] ....
However, the compiler gives me a warning of NobelPrizeWinners.java uses unchecked or unsafe operations. Recompile with -Xlint:unchecked for details.
As I said, my objective here is to process them in order. If this compiler warning cannot be resolved, I am open to other methods of accomplishing my objective.
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:
1. A = (B + C) * D - E;
2. F = (G + H) - (I + J);
3. G = H + A[I];
4. If (I == J) F = G + H;
Else F = G - H;
5. Loop: G = G + A[I];
I = I + J;
If (I != H) Goto Loop;
6. If (G < H) Goto Less;
7. While (save[I] == K)
I = I + J;
So I'm trying to implement a quick sort method for an ArrayList of Strings and right now I'm getting the compiler error message: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space. I don't know what that error means nor how to fix it. I've marked in my code where the error seems to be occurring.
import java.util.ArrayList;
public class quickSort
{
// constructor
public quickSort()
[code]....
what is the use of checked exception.I know unchecked exception or Runtime exception are thrown by jvm whenever programmer makes any mistake in logic and current thread is terminated.But checked Exception are checked at compile time so that compiler compels programmer to put risky methods in try catch clause. And this checked Exception are caused due to problem in IO operation or any such operation which the programmer can't control.Programmer can't do anything to avoid this checked exception but can catch this exception.
Now the question is Why compiler compels checked exception to be put in try catch clause but doesn't complain anything in case of Runtime Exception???
A java program to print 10 random numbers between 512 and 1024 and then finds the smallest and biggest numbers from the list using only one loop
class BSLab4d {
public static void main (String[] args){
int[] nums = new int[10];
int largest = nums[0];
int x = 0;
int smallest = nums[0];
int y = 0;
[code]....
I am using a static method to convert a string to an Integer object. Next using a instance method to convert Integer object to an int.
Compiler is giving me two "cannot find symbol" errors:
One pointing to the dot operator between "Integer.valueOf(s)"
The other pointing to the dot operator between "obj.intValue()"
I have latest JDK installed: jdk-7u51-windows-x64.exe
Looks like JCL installed correctly with rt.jar file located in "lib" directory under "Program Files"
Following is source code:
Java Code:
public class StringToInt
{
public static void main (String args [])
{
String s = "125";
Integer obj = Integer.valueOf(s);
int i = obj.intValue();
i += 10;
System.out.println(i);
}
} mh_sh_highlight_all('java');
I'm not sure if that's the right place to ask
But I am a bit confused:
I know that JDK means "Java Development Kit" , but isn't Eclipse the same thing? (so why it's called "IDE"?)
Or maybe Eclipse is a type of JDK?
Or actually JDK and Eclipse are 2 different things
What Is the difference between an ActionListener and an EventHandler ?
button.addActionListener(new ActionListener() {
button.setOnAction(new EventHandler<ActionEvent>() {
exact difference between
1. unread fields
2. unused fileds
in java
I am new to java i dont understand the difference between the abstract and inheritance i mean we use the abstract class with extends with other class name ,even we do that same in the inheritance pls tell me main difference between abstract and inheritance...
View Replies View Relatedhow to program in Javascript, I am wondering what are the advantages and disadvantages OR pros/cons of using JS versus say a language like Java?
View Replies View RelatedI have been tasked with creating an invoice (school assignment). Part of the calculations is creating an interest depending on the amount of days between the current date entered, and invoice date entered (The program prompts the user to enter both the current and invoice dates by asking for the day, month and year).
We are also supposed to set the contructor to a default date of 1/1/1900.. but I don't know how or where to code that.
How to calculate the difference between the CurrentDate and Invoice. I have displayed the dates to the user as follows.
public void displayDate() {
System.out.println("
Today's Date: " + month + "/" + day + "/" + year);
}
public void displayInvDate() {
System.out.println("
Invoice Date: " + invMonth + "/" + invDay + "/" + invYear);
I have just begin to understand collections in Java. I read about the differences between LinkedList and ArrayList but have several doubts on it. I have mentioned them below
1) Why retrieving in ArrayList is faster then LinkedList?. Since both have the get method how does performance differ?.
2) How does re-sizing happens internally in ArrayList when a item is added or removed?. How slow this is compared to the pointer re-shuffling in LinkedList when a item is added or removed?.
I read that InputStream is used for byte based reading it reads 1 byte at a time.And InputStreamReader is used for charcter based reading so it reads one charcter at a time so no need to convert this first to int then read it.Here is reading using InputStream.
input=new FileInputStream("D:/input.txt");
int c;
while((c=input.read())!=-1)
{
System.out.print((char)c);
}
and here is reading using InputStreamReader
input=new FileInputStream("D:/input.txt");
reader=new InputStreamReader(input,"UTF-8");
int c;
while((c=reader.read())!=-1)
{
System.out.print((char)c);
}
so what is difference between InputStream and InputStreamReader in both case i have to use a Int and then read it and at the end if I want to print that data I have to cast that with "(char)c".So what is advantage of using InputStreamReader?