Tuesday, October 2, 2018

Reflection based on Lab1



From this Lab1, I have learnt how to identify and fix the common error.
In Test1, the word ‘static’ is missing after ‘public’ in main method. The static keyword in Java means that the variable or function is shared between all instances of that class as it belongs to the type, not the actual objects themselves.
In Test2, an error occurred as the declaration of the variable ‘k’ is missing before we assign ‘k’+2 is equal to I. We need to declare the value of variable by typing ‘double’ or ‘int’ if the value is within the range for ‘double’ and ‘int’.
For Test3, the statement int i=j=k=2 only declare i , j and k is not declared. In order to fix the error, we need to declare the value of each term, that is
int i=2;
int j=2;
int k=2;
In Test4, the answer of 5/2 should be 2.5 but the answer I get was 2 in the java program. This is because the computer assumed that there is no decimal places if we insert the amount is 5 instead of 5.0. In order to insert the amount as 5.0, we need to use ‘double’ instead of ‘int’ as ‘int’ is use for integral.
There is an error occurred in Test5. The ‘R’ in line3 should be small capital letters.
An error occurred in test 6. Since the value range of ‘int’ is -2147483648 to 2147483647, the answer we get in test 6 is overflow and exceed the range of ‘int’. so, we need to put a letter of ‘l’ after 2147483647l to represent as the word long.
We apply similar principle on Test7, long(sum) is used to calculate sum of long integral.
In Test8, I applied what I have learnt in computational physics. To get the exact value of 0.1, we need to decide the decimal format as one decimal point by inserting ‘DecimalFormat df=new DecimalFormat(“#.#”)’ after the main method line.
In Test9,Java will not throw an exception if it is divided by float zero. It will detect a run-time error only if it divided by integer zero not double zero.

Through this lab, I learnt how to design the solution to a problem by using Problem Analysis Chart (PAC) and also gain the knowledge of hot to write, compile, and run a simple computer programme based on PAC


https://mylab0programking1.blogspot.com/

Sunday, September 23, 2018

MyFirstJavaProgram Lab0

In Lab0, I have learned how to check the content list in current directory by typing 'dir' in command prompt.



 Also, i have learned that 'cd' is use to change the current directory to the specific directory.




Through this lab, I gain the knowledge of how to create a file by typing 'mkdir' followed by the name of file intended.

Then, in order to open a new file in a folder name of 'ohhuimin', I need to change the directory to 'ohhuimin' by typing 'cd ohhuimin'

Next, to create new file named of lab0, I need to type 'mkdir lab0'
This showed that 'lab0' file was already created in the folder of 'ohhuimin'.

The goal of this lab is to learned how to write, compile and run a simple computer program written in java. Before compiling the program, I learned how to check if the computer that i was using has the latest java. To check this, we go to 'local disk'(C;) and then 'program files' and search for java file and check whether the java is the latest version. 'jdk' is java development kit, this is use to write a program.'jre'is java run time environment, it use to run a program.After confirming the pc have latest version of java, now we need to check the java to see whether it can run or not by typing 'javac' in the command prompt. Before that, the name of the file in the notepad should be saved exactly the same as what was written after the word 'public class' in the notepad. Now we can compiling the program by typing java followed by the file name that we want to compile in command prompt. ( 'java file_name)
However, there were some error encountered during the experiment. I faced run time error in this experiment. I put incorrect input when running the program, this cause the computer failed to compile program.

https://mylab0programking1.blogspot.com

Reflection based on Lab1

From this Lab1, I have learnt how to identify and fix the common error. In Test1, the word ‘static’ is missing after ‘public’ in main ...