SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
Sulaimani Polytechnic University
TechnicalCollegeof Informatics
ComputerNetworksDepartment
By : Msc. Fariaa Abdulmajed
Introduction:-
Programming and programminglanguage
Programming: is the technique of converting the idea of solving a specified
problem into a logical related sequence of statements using a programming
language to obtain a required goal.
Programming language is a set of rules and symbols used to construct a
computer program
Programming Languages
Programming languages can be classified according to two criteria:
▪ Purpose of the Languages: This means, the objective that this language is
produced to.
▪ Level of the Language: This mean, the association level of the language from the
machine (microprocessor) or from the user (Human).
LanguagePurpose
Language Level
Compiler and Interpreter
• A program written in a high-level language is called a source
program or source code.
• A computer cannot execute a source program, a source program
must be translated into machine code for execution.
• The translation can be done using another programming tool
called an interpreter or a compiler.
Structureof Java programs
public class <name> {
public static void main(String[] args) {
<statement(s)>;
}
}
• Every executable Java program consists of a class...
• that contains a method named main...
• that contains the statements to be executed
Simple First Program: "Hello World"
public class Hello {
public static void main(String[] args) {
// Program execution begins here
System.out.println("Hello world.");
}
}
9
public // Accessible outside this file. "public" is a reserved word.
class // "class" is a reservedword.
Hello// The name of the class - same name as filename.
{ // Braces instead of begin/end.
public // This function must be accessible. "public" is reserved.
static // "static"is reserved.
void // The return value - nothing. "void" is reserved.
main // To start execution, a class must have a "main" function.
(String[] args)
System.out.println ("Hello World!"); // useful function called println, which takes in a string and
prints it out on a new line.
SimpleFirstProgram:"HelloWorld"
Important Notes
▪Filenames must end with .java in lowercase letters.
▪Filenames must match their class names (more info on this
soon).
▪Filenames cannot contain spaces.
▪Filenames are case sensitive: firstTry.java vs.
FirstTry.java vs. FIRSTTRY.java
▪Filenames consist only of letters (A-Z, a-z), digits (0-9),
underscores (_), dashes (-) and periods (.).
System.out.println
• Java programs use a statement called System.out.println
to instruct the computer to print a line of output on the console
• Two ways to use System.out.println :
1. System.out.println("<Message>");
• System.out.println (“I love JAVA");.
2. System.out.println(mathematical computations);
• System.out.println ((3*4)+7-8);
AnotherJavaprogram
The code in this program instructs the computer to print four messages on
the screen.
public class Hello2 {
public static void main(String[] args) {
System.out.println("Hello, world!");
System.out.println();
System.out.println("This program produces");
System.out.println("four lines of output");
}
}
13
Program Development Process
Text editor Source code
(.java)
Saves Java statements
Java compiler
Byte code
(.class)
Produces
Java
Virtual
Machine
Program
Execution
Results in
• All Java source files must end with the .java extension
• Those source files are then compiled into .class files by the javac compiler.
• it instead contains bytecodes — the machine language of the Java Virtual Machine (Java VM).
• The java launcher tool then runs your application with an instance of the Java Virtual Machine.
An overview of the software development process
• the Java VM is available on many different operating systems, the same .class files are capable of
running on Microsoft Windows,Linux, or Mac OS.
Through the Java VM, the same application is capable of running on multiple platforms
syntaxerrors & Runtime errors
• syntax error or compiler error: A problem in the structureof a program that causes the compiler to
fail.
• If you type yourJava program incorrectly, you may violate Java's syntax and see a syntax error.
public class Hello {
pooblic static void main(String[] args) {
System.owt.println("Hello, world!")_
}
}
H:summerHello.java:2: <identifier> expected
pooblic static void main(String[] args) {
^
H:summerHello.java:5: ';' expected
}
^
2 errors
Tool completed with exit code 1
compiler output:
Runtime errors are errors that cause a program to
terminate unusually.
WHEN we get Runtime errors!!!
1- if the program is running on the environment detects an
operation that is impossible to carry out.
2- If Input mistakes typically cause runtime errors
Ex : you have to read in a number, but you input string, this
causes data-type errors to occur in the program.
3- division by zero
System.out.println (12/0);
Comments
•Comments in Java can be one of two styles:
–Single line
•starts at //anywhere on a line
•ends at the end of that line
–Multi-line
•starts with character sequence /*anywhere
•ends with character sequence */anywhere after that
•can span multiple lines
Escapesequences
• Escape sequences,or escape characters, begin with a slash and are immediately followed by another
character.
• This two-character sequence,inside ""allows you to control your output (n, t, b)
lab work
1- write a program to execute “Hello, World! ” using TextPad
Step 1: Launch TextPad editor as demonstrated as follows:
Step 2: Write any sample Java program in the editor tool as
demonstrated as follows:
public class Hello {
public static void main(String [] arg) {
// Program execution begins here
System.out.println("Hello world.");
}
}
Step 3: Select ‘TextPad tools compile java’ choice from the Tools Menu
– > External Tools Sub Menu (or you can likewise use Ctrl+1 alternate
way key
Step 4: Ensure that the ‘Sava As’ dialog is shown. In ‘Save As’ dialog,
guarantee that ‘Save as Type’ is chosen as All Files, type ‘Hello.java’ into
the ‘File Name’ field and tap on ‘Save’ button as demonstrated as
follows:
Hello
Hello
Step 5: Repeat Step 3 to compile the saved Java document
Step 6: Select ‘Run Java Application’ alternative from the Tools Menu –
> External Tools Sub Menu (or you can likewise use Ctrl+2 easy shortcut
key)
Step 7: Observe that the outcome of the above composed Java
program is shown in the command window
2- what is the output of the following program and why
public class Ex1
{
public static void main ( String[] args )
{
System.out.println("HellontWorldn!" );
}
}
3) Write a java program to print your name . For example you get this output
4) Write a java program to output the following message.
5- what is the output of the following program
public class Ex1
{
public static void main ( String[] args )
{
System.out.println(12/4*(6+12)-8);
}
}
THANK YOU

Weitere ähnliche Inhalte

Ähnlich wie java 1 new.pdf

Java basics notes
Java basics notesJava basics notes
Java basics notes
Nexus
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
Ali Baba
 
01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one
ssuser656672
 
Lecture 3 java basics
Lecture 3 java basicsLecture 3 java basics
Lecture 3 java basics
the_wumberlog
 
Java-1st.pptx about Java technology before oops
Java-1st.pptx about Java technology before oopsJava-1st.pptx about Java technology before oops
Java-1st.pptx about Java technology before oops
buvanabala
 

Ähnlich wie java 1 new.pdf (20)

Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Mpl 1
Mpl 1Mpl 1
Mpl 1
 
INTRODUCTION TO JAVA APPLICATION
INTRODUCTION TO JAVA APPLICATIONINTRODUCTION TO JAVA APPLICATION
INTRODUCTION TO JAVA APPLICATION
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
java:characteristics, classpath, compliation
java:characteristics, classpath, compliationjava:characteristics, classpath, compliation
java:characteristics, classpath, compliation
 
01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software Development
 
lab1.ppt
lab1.pptlab1.ppt
lab1.ppt
 
Lecture 3 java basics
Lecture 3 java basicsLecture 3 java basics
Lecture 3 java basics
 
2 Getting To Know Your Programing Environment
2 Getting To Know Your Programing Environment2 Getting To Know Your Programing Environment
2 Getting To Know Your Programing Environment
 
2 Getting To Know Your Programing Environment
2 Getting To Know Your Programing Environment2 Getting To Know Your Programing Environment
2 Getting To Know Your Programing Environment
 
Introduction to java programming part 1
Introduction to java programming   part 1Introduction to java programming   part 1
Introduction to java programming part 1
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
 
Java Notes
Java Notes Java Notes
Java Notes
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Lesson 1 - Introduction to Computer Programming.pptx
Lesson 1 - Introduction to Computer Programming.pptxLesson 1 - Introduction to Computer Programming.pptx
Lesson 1 - Introduction to Computer Programming.pptx
 
Programming in Java: Getting Started
Programming in Java: Getting StartedProgramming in Java: Getting Started
Programming in Java: Getting Started
 
Java-1st.pptx about Java technology before oops
Java-1st.pptx about Java technology before oopsJava-1st.pptx about Java technology before oops
Java-1st.pptx about Java technology before oops
 
Srgoc java
Srgoc javaSrgoc java
Srgoc java
 

Kürzlich hochgeladen

Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Cara Menggugurkan Kandungan 087776558899
 

Kürzlich hochgeladen (6)

Leading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfLeading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdf
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
 
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
 
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
 

java 1 new.pdf

  • 1. Sulaimani Polytechnic University TechnicalCollegeof Informatics ComputerNetworksDepartment By : Msc. Fariaa Abdulmajed
  • 2. Introduction:- Programming and programminglanguage Programming: is the technique of converting the idea of solving a specified problem into a logical related sequence of statements using a programming language to obtain a required goal. Programming language is a set of rules and symbols used to construct a computer program
  • 3. Programming Languages Programming languages can be classified according to two criteria: ▪ Purpose of the Languages: This means, the objective that this language is produced to. ▪ Level of the Language: This mean, the association level of the language from the machine (microprocessor) or from the user (Human).
  • 6. Compiler and Interpreter • A program written in a high-level language is called a source program or source code. • A computer cannot execute a source program, a source program must be translated into machine code for execution. • The translation can be done using another programming tool called an interpreter or a compiler.
  • 7. Structureof Java programs public class <name> { public static void main(String[] args) { <statement(s)>; } } • Every executable Java program consists of a class... • that contains a method named main... • that contains the statements to be executed
  • 8. Simple First Program: "Hello World" public class Hello { public static void main(String[] args) { // Program execution begins here System.out.println("Hello world."); } }
  • 9. 9 public // Accessible outside this file. "public" is a reserved word. class // "class" is a reservedword. Hello// The name of the class - same name as filename. { // Braces instead of begin/end. public // This function must be accessible. "public" is reserved. static // "static"is reserved. void // The return value - nothing. "void" is reserved. main // To start execution, a class must have a "main" function. (String[] args) System.out.println ("Hello World!"); // useful function called println, which takes in a string and prints it out on a new line. SimpleFirstProgram:"HelloWorld"
  • 10. Important Notes ▪Filenames must end with .java in lowercase letters. ▪Filenames must match their class names (more info on this soon). ▪Filenames cannot contain spaces. ▪Filenames are case sensitive: firstTry.java vs. FirstTry.java vs. FIRSTTRY.java ▪Filenames consist only of letters (A-Z, a-z), digits (0-9), underscores (_), dashes (-) and periods (.).
  • 11. System.out.println • Java programs use a statement called System.out.println to instruct the computer to print a line of output on the console • Two ways to use System.out.println : 1. System.out.println("<Message>"); • System.out.println (“I love JAVA");. 2. System.out.println(mathematical computations); • System.out.println ((3*4)+7-8);
  • 12. AnotherJavaprogram The code in this program instructs the computer to print four messages on the screen. public class Hello2 { public static void main(String[] args) { System.out.println("Hello, world!"); System.out.println(); System.out.println("This program produces"); System.out.println("four lines of output"); } }
  • 13. 13 Program Development Process Text editor Source code (.java) Saves Java statements Java compiler Byte code (.class) Produces Java Virtual Machine Program Execution Results in
  • 14. • All Java source files must end with the .java extension • Those source files are then compiled into .class files by the javac compiler. • it instead contains bytecodes — the machine language of the Java Virtual Machine (Java VM). • The java launcher tool then runs your application with an instance of the Java Virtual Machine. An overview of the software development process
  • 15. • the Java VM is available on many different operating systems, the same .class files are capable of running on Microsoft Windows,Linux, or Mac OS. Through the Java VM, the same application is capable of running on multiple platforms
  • 16. syntaxerrors & Runtime errors • syntax error or compiler error: A problem in the structureof a program that causes the compiler to fail. • If you type yourJava program incorrectly, you may violate Java's syntax and see a syntax error. public class Hello { pooblic static void main(String[] args) { System.owt.println("Hello, world!")_ } } H:summerHello.java:2: <identifier> expected pooblic static void main(String[] args) { ^ H:summerHello.java:5: ';' expected } ^ 2 errors Tool completed with exit code 1 compiler output:
  • 17. Runtime errors are errors that cause a program to terminate unusually. WHEN we get Runtime errors!!! 1- if the program is running on the environment detects an operation that is impossible to carry out. 2- If Input mistakes typically cause runtime errors Ex : you have to read in a number, but you input string, this causes data-type errors to occur in the program. 3- division by zero System.out.println (12/0);
  • 18. Comments •Comments in Java can be one of two styles: –Single line •starts at //anywhere on a line •ends at the end of that line –Multi-line •starts with character sequence /*anywhere •ends with character sequence */anywhere after that •can span multiple lines
  • 19. Escapesequences • Escape sequences,or escape characters, begin with a slash and are immediately followed by another character. • This two-character sequence,inside ""allows you to control your output (n, t, b)
  • 21. 1- write a program to execute “Hello, World! ” using TextPad Step 1: Launch TextPad editor as demonstrated as follows:
  • 22. Step 2: Write any sample Java program in the editor tool as demonstrated as follows: public class Hello { public static void main(String [] arg) { // Program execution begins here System.out.println("Hello world."); } }
  • 23. Step 3: Select ‘TextPad tools compile java’ choice from the Tools Menu – > External Tools Sub Menu (or you can likewise use Ctrl+1 alternate way key
  • 24. Step 4: Ensure that the ‘Sava As’ dialog is shown. In ‘Save As’ dialog, guarantee that ‘Save as Type’ is chosen as All Files, type ‘Hello.java’ into the ‘File Name’ field and tap on ‘Save’ button as demonstrated as follows: Hello Hello
  • 25. Step 5: Repeat Step 3 to compile the saved Java document Step 6: Select ‘Run Java Application’ alternative from the Tools Menu – > External Tools Sub Menu (or you can likewise use Ctrl+2 easy shortcut key) Step 7: Observe that the outcome of the above composed Java program is shown in the command window
  • 26. 2- what is the output of the following program and why public class Ex1 { public static void main ( String[] args ) { System.out.println("HellontWorldn!" ); } }
  • 27. 3) Write a java program to print your name . For example you get this output 4) Write a java program to output the following message.
  • 28. 5- what is the output of the following program public class Ex1 { public static void main ( String[] args ) { System.out.println(12/4*(6+12)-8); } }