SlideShare ist ein Scribd-Unternehmen logo
1 von 23
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

Weitere ähnliche Inhalte

Was ist angesagt?

66781291 java-lab-manual
66781291 java-lab-manual66781291 java-lab-manual
66781291 java-lab-manual
Laura Popovici
 
User controls
User controlsUser controls
User controls
aspnet123
 

Was ist angesagt? (20)

All about Office UI Fabric
All about Office UI FabricAll about Office UI Fabric
All about Office UI Fabric
 
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
 
JavaFX Presentation
JavaFX PresentationJavaFX Presentation
JavaFX Presentation
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Angular js PPT
Angular js PPTAngular js PPT
Angular js PPT
 
66781291 java-lab-manual
66781291 java-lab-manual66781291 java-lab-manual
66781291 java-lab-manual
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
 
.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging Techniques
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
 
Program control statements in c#
Program control statements in c#Program control statements in c#
Program control statements in c#
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
User controls
User controlsUser controls
User controls
 
Java lab-manual
Java lab-manualJava lab-manual
Java lab-manual
 
Project report
Project reportProject report
Project report
 
C programming
C programmingC programming
C programming
 
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
 
Scientific Calculator.pptx
Scientific Calculator.pptxScientific Calculator.pptx
Scientific Calculator.pptx
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
7. check box control
7. check box control7. check box control
7. check box control
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 

Andere mochten auch

Chapter12 - Designing System Interfaces, Controls and Security(Demo Presentat...
Chapter12 - Designing System Interfaces, Controls and Security(Demo Presentat...Chapter12 - Designing System Interfaces, Controls and Security(Demo Presentat...
Chapter12 - Designing System Interfaces, Controls and Security(Demo Presentat...
John Ely Masculino
 

Andere mochten auch (13)

Java Tutorial Lab 7
Java Tutorial Lab 7Java Tutorial Lab 7
Java Tutorial Lab 7
 
Java Tutorial Lab 3
Java Tutorial Lab 3Java Tutorial Lab 3
Java Tutorial Lab 3
 
Java Tutorial Lab 2
Java Tutorial Lab 2Java Tutorial Lab 2
Java Tutorial Lab 2
 
Java Tutorial Lab 4
Java Tutorial Lab 4Java Tutorial Lab 4
Java Tutorial Lab 4
 
Java Tutorial Lab 8
Java Tutorial Lab 8Java Tutorial Lab 8
Java Tutorial Lab 8
 
Self Evaluation Test
Self Evaluation Test Self Evaluation Test
Self Evaluation Test
 
Java Tutorial Lab 9
Java Tutorial Lab 9Java Tutorial Lab 9
Java Tutorial Lab 9
 
Java Tutorial Lab 6
Java Tutorial Lab 6Java Tutorial Lab 6
Java Tutorial Lab 6
 
Java Tutorial Lab 5
Java Tutorial Lab 5Java Tutorial Lab 5
Java Tutorial Lab 5
 
Behavior Management Part 2
Behavior Management Part 2Behavior Management Part 2
Behavior Management Part 2
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
Chapter12 - Designing System Interfaces, Controls and Security(Demo Presentat...
Chapter12 - Designing System Interfaces, Controls and Security(Demo Presentat...Chapter12 - Designing System Interfaces, Controls and Security(Demo Presentat...
Chapter12 - Designing System Interfaces, Controls and Security(Demo Presentat...
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 

Ähnlich wie Java Tutorial Lab 1

Chapter 1.3
Chapter 1.3Chapter 1.3
Chapter 1.3
sotlsoc
 

Ähnlich wie Java Tutorial Lab 1 (20)

OOP with Java
OOP with JavaOOP with Java
OOP with Java
 
Java Programming Fundamentals
Java Programming Fundamentals Java Programming Fundamentals
Java Programming Fundamentals
 
Java introduction
Java introductionJava introduction
Java introduction
 
Unit of competency
Unit of competencyUnit of competency
Unit of competency
 
01slide
01slide01slide
01slide
 
01slide
01slide01slide
01slide
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 
Java
JavaJava
Java
 
Java programming - solving problems with software
Java programming - solving problems with softwareJava programming - solving problems with software
Java programming - solving problems with software
 
Comp102 lec 3
Comp102   lec 3Comp102   lec 3
Comp102 lec 3
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Introduction to Java Programming.pdf
Introduction to Java Programming.pdfIntroduction to Java Programming.pdf
Introduction to Java Programming.pdf
 
Introduction to java technology
Introduction to java technologyIntroduction to java technology
Introduction to java technology
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
perl-java
perl-javaperl-java
perl-java
 
perl-java
perl-javaperl-java
perl-java
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
 
Chapter 1.3
Chapter 1.3Chapter 1.3
Chapter 1.3
 
GETTING STARTED WITH JAVA(beginner)
GETTING STARTED WITH JAVA(beginner)GETTING STARTED WITH JAVA(beginner)
GETTING STARTED WITH JAVA(beginner)
 

Kürzlich hochgeladen

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Kürzlich hochgeladen (20)

%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 

Java Tutorial Lab 1

  • 1. 2016 Winter LAB #1 Prepared by: Berk Soysal
  • 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
  • 3. Project Name Package Name Java File Dog Class Class Variables Constructor Method Other User Defined Methods 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
  • 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 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
  • 17. Click on Compile first, then Run 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