Dimentary Java 1
Dimentary Java 1
C02.1 - Rudimentary
Java
Melgine M. Bauat, MSIT
Instructor
Components of Java Program
Examples:
o packages: org.omg.CORBA , java.lang , eecs2011.assignments
o Classes:Name , Math , enum , MyClass , YourClass
o Interfaces: Comparable, Clonable, Iterable
o methods: verb , getValue , isEmpty , equals , clone , toString
o variables: name , counter3 , $testVariable , _testVar
o CONSTANTS: PI , MAX_INT , ELECTRON_MASS
Variables and Data Types
• Variable definitions
• Variable: name of place in memory that can contain data
• All variables have:
• Data type kind of data variable can contain
• Name identifier that refers to the variable
• Value the default or specified value
• also called the literal of the statement
• Semicolon
• Remember: All java statements end with a semicolon!
• e.g.
• String myname= “Melgine”;
• int count = 5;
Constants
• Using Constants
• Variable with a value that doesn’t change
• Keyword
• final
• Denotes value cannot change
• Example:
• final double SALES_TAX_RATE = 4.5;
• note the naming convention
• other examples?
Java Primitive Data Types
• Java has several primitive types, which are basic ways of storing
data.
editor helloJava.java
Hellojava.java
HelloJava.java These are wrong
compiler
HelloJava.class
JVM
Output
Programmer and JVM perspective.
This is Java Language that programmers This is the compiled byte code that JVM
can understand. However, JVM can’t can understand. However, programmers
understand this. can’t understand this.
COMPILER
(javac)
Java Comments
• Comments
• Single line
• // compiler ignores
everything to end of line
• Multi-line
• /* compiler ignores
everything in between */
https://drive.google.com/file/d/1Has5wcqNkFy3pSPJpH6uw6O9_8JJq
j-q/view?usp=sharing