0% found this document useful (0 votes)
52 views3 pages

System - Out.println ("Hello, World!") : Object

This document discusses strings, objects, and methods in Java. It defines strings as text enclosed in quotation marks, objects as things that do work in a program, and methods as instructions that are executed. It uses the example of System.out.println to demonstrate how it prints a string by calling the println method on the System.out object. It then discusses different types of errors, including compile-time errors due to syntax issues, and run-time errors due to logical errors or exceptions like division by zero. Finally, it provides an example of how to calculate the total cost of two cars to determine which one to purchase based on purchase price and gas costs.

Uploaded by

Joao Salazar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views3 pages

System - Out.println ("Hello, World!") : Object

This document discusses strings, objects, and methods in Java. It defines strings as text enclosed in quotation marks, objects as things that do work in a program, and methods as instructions that are executed. It uses the example of System.out.println to demonstrate how it prints a string by calling the println method on the System.out object. It then discusses different types of errors, including compile-time errors due to syntax issues, and run-time errors due to logical errors or exceptions like division by zero. Finally, it provides an example of how to calculate the total cost of two cars to determine which one to purchase based on purchase price and gas costs.

Uploaded by

Joao Salazar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Strings, Objects, and Methods

String = it is just a technical term for the text (that could be words or numbers or
mathematical expressions. A text is usually enclosed in quotation marks
Object(s) = they are things that do work for us in a program. In the exercises I have been
doing, the objects represent the Terminal Window in which a String or number is printed
when printlng does his job.
Method = it is an instruction that is being executed.

System.out.println(Hello, World!);
Object

Method

String

The above statement prints the String


The instruction (method) here is to print something on the Terminal Window (object). The
ln part indicates that it should also be prepared to make the next printout appear just in
the line below.

TYPE OF ERRORS
1. Compile-time error (syntax error) = it is called Compile-time error because it is
found when you compile.
System.ouch.println(Hello, World!);
The terminal window object is System.out. not System.ouch.
When we try to Compile, the compiler (the program that translates Java into a
lower level code complains and it says I have no idea what the Variable ouch is.
Cannot find symbol variable ouch
The compiler knows System.out. but it does not know System.ouch.
System.out.println(Hello, Sarah);
The above error is an example of a compile-time error because the computer
doesnt know what we mean by HELLO. What we wanted is for Hello, Sarah to be
literal texts. In order to do that, we need to quotation marks (Hello, Sarah)

Cannot find symbol variable Hello


2. Run-time error (logic error)
System.out.println(Hello, Word!);
The programmer misspelled World. When we compile, there is no error:
Class compiled no syntax errors
The compiler does not know English (or Spanish or any other human language) and
has no idea that that word has been misspelled. We can run the program and it
runs. It just does the wrong thing.
When a program compiles and runs but produces the wrong output, then it is
called a run-time error. It is also called a Logic Error because there is something
wrong with the logic of the program not just its syntax.
3. Run-time error (logic error) = it compiles, runs but prints an error message. It is so
bad that it terminates the program and displays what is called an exceptional
report: java.lang.ArithmeticException: / by zero
This report says that a division by zero was attempted and that is of course very
very bad
System.out.println(1 / 0);

Car 1 Purchase price USD$15.000


Car 2 Purchase price USD$30.000
Miles driven = 50.000
Price per gallon = USD$4
For each car, compute
gas cost = (miles driven 50.000/mpg 10)
USD$20.000 * Price per gallon USD$ 4
Total cost = purchase price USD$15.000
+ gas cost USD$20.000
If total cost 1 USD$35.000

total cost 2

Buy car 1
Else
Buy car 2

For each car, compute


gas cost = (miles driven 50.000/mpg 50)
USD$4.000

* Price per gallon USD$ 4

Total cost = purchase price USD$ 30.000


+ gas cost USD$ 4.000
If total cost 1 total cost 2 USD$34.000
Buy car 1
Else
Buy car 2

You might also like