KEMBAR78
Java Tutorial Lab 1 | PPTX
2016 Winter
LAB #1
Prepared by: Berk Soysal
• As of 2015, Java is one of the most popular
programming languages in use.
• https://en.wikipedia.org/wiki/Measuring_programming_language_popularity
• Java is an Object-Oriented Programming Language.
• Structurally, the Java language starts with packages.
A package is the Java language's namespace
mechanism. Within packages are classes, and within
classes are methods, variables, constants, and
more.
2016 Winter
Project Name
Package Name
Java File
Dog Class
Class Variables
Constructor Method
Other User Defined
Methods
2016 Winter
• An object is a self-contained entity that contains attributes and
behavior.
• Every program must contain a main method, public static
void main(String[] args).
• Java is a strongly typed language. You must declare the type
of each variable.
• Every instruction ends with a semi-column “;”.
• Instructions that belong to the same block must be between
curly brackets “{. . .}”.
• Now, let’s have a look at the indentation and comments.
2016 Winter
2016 Winter
http://www.drjava.org/
2016 Winter
https://www.eclipse.org/downloads/
if(condition1 == condition2){
while(condition3!=false){
if(condition3==condition4){
doSomethingAboutIt();
System.out.println(“Something");
}
else{
doNotDoSomethingAboutIt();
System.out.println(“Nothing");
}
}
}
if(condition1 == condition2){
while(condition3!=false){
if(condition3==condition4){
doSomethingAboutIt();
System.out.println(“Something");
}
else{
doNotDoSomethingAboutIt();
System.out.println(“Nothing");
}
}
}
2016 Winter
// This is a single line comment
if (a == 2) {
return TRUE; /* First block comment here*/
}
else {
return verifyInteger(a); /* Your next block comment here*/
}
// Use as many comments as possible, explain everything
// in your code.
/* Otherwise you will forget what you have written after
a period of time */
Download this ppt. - http://uottawa.ml2016 Winter
2016 Winter
2016 Winter
• For the indentation in DrJava; you need to select
your code, and press on the TAB key on the
keyboard.
• Please always use comments in your code to
explain your steps.
2016 Winter
2016 Winter
• Java Compiler: javac is the executable/application which
compiles the .java source files into the byte code (.class
files).
• Java Run-time Environment (JRE): Java Run-time
Environment helps in running the programs. JRE contains
the JVM, the java classes/packages and the run-time
libraries.
• Java Virtual Machine (JVM): Java Virtual Machine is
important part of the JRE, which actually runs the programs
(.class files), it uses the java class libraries and the run-time
libraries to execute those programs.
2016 Winter
Let’s open a notepad document and start writing
our code.
Open the Command Line Interface and Compile;
 javac Main.java
public class Main{
public static void main(String[] args){
System.out.println("Hello World!");
}
}
2016 Winter
After compilation, run the Program
 java Main
Observe the output!
Let’s modify our code so that we can input 3
Strings to the main method!
public class Main{
public static void main(String[] args){
System.out.println("Hello World!");
System.out.println(“Entered Strings: "+args[0]+args[1]+args[2]);
}
}
2016 Winter
Now, let’s run the same program in DrJava..
Let’s compile and run again;
 javac Main.java
 java Main I am YourName
Observe the output!
2016 Winter
Click on Compile first, then Run
2016 Winter
Write a program called Command.java that gives the following output:
What if the number of String inputs is not fixed?
How can we print them??
2016 Winter
For Quiz Question 1
You can use DrJava as well as Command
Line Interface
2016 Winter
Write the program ArrayTool described below. Test with several values
for “cutOffValue” to ensure that your program works.
2016 Winter
Write the program ArrayTool described below. Test with several values
for “cutOffValue” to ensure that your program works.
2016 Winter
2016 Winter
2016 Winter

Java Tutorial Lab 1

  • 1.
  • 2.
    • As of2015, Java is one of the most popular programming languages in use. • https://en.wikipedia.org/wiki/Measuring_programming_language_popularity • Java is an Object-Oriented Programming Language. • Structurally, the Java language starts with packages. A package is the Java language's namespace mechanism. Within packages are classes, and within classes are methods, variables, constants, and more. 2016 Winter
  • 3.
    Project Name Package Name JavaFile Dog Class Class Variables Constructor Method Other User Defined Methods 2016 Winter
  • 4.
    • An objectis a self-contained entity that contains attributes and behavior. • Every program must contain a main method, public static void main(String[] args). • Java is a strongly typed language. You must declare the type of each variable. • Every instruction ends with a semi-column “;”. • Instructions that belong to the same block must be between curly brackets “{. . .}”. • Now, let’s have a look at the indentation and comments. 2016 Winter
  • 5.
  • 6.
  • 7.
    if(condition1 == condition2){ while(condition3!=false){ if(condition3==condition4){ doSomethingAboutIt(); System.out.println(“Something"); } else{ doNotDoSomethingAboutIt(); System.out.println(“Nothing"); } } } if(condition1== condition2){ while(condition3!=false){ if(condition3==condition4){ doSomethingAboutIt(); System.out.println(“Something"); } else{ doNotDoSomethingAboutIt(); System.out.println(“Nothing"); } } } 2016 Winter
  • 8.
    // This isa single line comment if (a == 2) { return TRUE; /* First block comment here*/ } else { return verifyInteger(a); /* Your next block comment here*/ } // Use as many comments as possible, explain everything // in your code. /* Otherwise you will forget what you have written after a period of time */ Download this ppt. - http://uottawa.ml2016 Winter
  • 9.
  • 10.
  • 11.
    • For theindentation in DrJava; you need to select your code, and press on the TAB key on the keyboard. • Please always use comments in your code to explain your steps. 2016 Winter
  • 12.
  • 13.
    • Java Compiler:javac is the executable/application which compiles the .java source files into the byte code (.class files). • Java Run-time Environment (JRE): Java Run-time Environment helps in running the programs. JRE contains the JVM, the java classes/packages and the run-time libraries. • Java Virtual Machine (JVM): Java Virtual Machine is important part of the JRE, which actually runs the programs (.class files), it uses the java class libraries and the run-time libraries to execute those programs. 2016 Winter
  • 14.
    Let’s open anotepad document and start writing our code. Open the Command Line Interface and Compile;  javac Main.java public class Main{ public static void main(String[] args){ System.out.println("Hello World!"); } } 2016 Winter
  • 15.
    After compilation, runthe Program  java Main Observe the output! Let’s modify our code so that we can input 3 Strings to the main method! public class Main{ public static void main(String[] args){ System.out.println("Hello World!"); System.out.println(“Entered Strings: "+args[0]+args[1]+args[2]); } } 2016 Winter
  • 16.
    Now, let’s runthe same program in DrJava.. Let’s compile and run again;  javac Main.java  java Main I am YourName Observe the output! 2016 Winter
  • 17.
    Click on Compilefirst, then Run 2016 Winter
  • 18.
    Write a programcalled Command.java that gives the following output: What if the number of String inputs is not fixed? How can we print them?? 2016 Winter
  • 19.
    For Quiz Question1 You can use DrJava as well as Command Line Interface 2016 Winter
  • 20.
    Write the programArrayTool described below. Test with several values for “cutOffValue” to ensure that your program works. 2016 Winter
  • 21.
    Write the programArrayTool described below. Test with several values for “cutOffValue” to ensure that your program works. 2016 Winter
  • 22.
  • 23.