Introduction to Java, its syntax and environment setup
The first tutorial is going to be an introduction to Java and its syntax. The tutorial starts with basic examples such as printing out a String and ends with some quiz questions for you to practice what you have learned. Also I provided the download links for the Integrated Development Environments for Java Programming. The rest of the tutorials will follow the same content-quiz pattern so get ready for some hands on experience!
Check out rest of the Tutorials: https://berksoysal.blogspot.com/2016/06/java-se-tutorials-basics-exercises.html
2. • 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
4. • 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
8. // 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
11. • 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
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 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
15. 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
16. 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
18. 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
19. For Quiz Question 1
You can use DrJava as well as Command
Line Interface
2016 Winter
20. Write the program ArrayTool described below. Test with several values
for “cutOffValue” to ensure that your program works.
2016 Winter
21. Write the program ArrayTool described below. Test with several values
for “cutOffValue” to ensure that your program works.
2016 Winter