Download Introduction to JAVA

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Structured programming wikipedia , lookup

Program optimization wikipedia , lookup

Class (computer programming) wikipedia , lookup

Object-oriented programming wikipedia , lookup

Go (programming language) wikipedia , lookup

Comment (computer programming) wikipedia , lookup

Compiler wikipedia , lookup

Library (computing) wikipedia , lookup

C++ wikipedia , lookup

Java syntax wikipedia , lookup

C Sharp syntax wikipedia , lookup

Interpreter (computing) wikipedia , lookup

Scala (programming language) wikipedia , lookup

Name mangling wikipedia , lookup

Java (programming language) wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Java performance wikipedia , lookup

Transcript
Introduction to
1
What is Java ?
•Java is a programming language and computing platform
first released by Sun Microsystems in 1995.
•The language derives much of its syntax from C and C++ but has a
simpler object model and fewer low-level facilities.
•The Java language is accompanied by a library of extra software that
we can use when developing programs.
•The library provides the ability to create graphics, communicate
over networks, and interact with databases.
•The set of supporting libraries is huge.
2
Java applications and applets
Applications – standalone Java programs
Applets – Java programs that run inside web browsers
Java is the first programming language to deliberately embrace
the concept of writing programs that
can be executed on the Web.
3
Compiling Java Programs
The Java compiler produces bytecode (a “.class” file) not
machine code from the source code (the “.java” file).
Bytecode is converted into machine code using a Java
Interpreter
4
Platform Independent Java Programs
Compiling
You can run bytecode on any computer that has a Java Interpreter
installed
“Hello.java”
“Hello.class”
5
Fundamentals
6
Hello world JAVA program
// import section
public class MyFirstprogram {
// main method
public static void main( String args[] ){
System.out.println(“Hello World”);
} // end main
} // end class
7
Saving, Compiling and Running Java Programs
Saving a Java program :
A file having a name same as the class name should be used to
save the program. The extension of this file is ”.java”.
“MyFirstprogram.java”.
Compiling a Java program : Call the Java compiler javac
The Java compiler generates a file called
” MyFirstprogram.class” (the bytecode).
Running a Java program
Call the Java Virtual Machine java:
•java MyFirstprogram.class
8
Comments in a Java Program
•Comments are used to describe what your code does its improve
the code readability.
•The Java compiler ignores them.
•Comments are made using
// which comments to the end of the line,
/* */, everything inside of it is considered a comment
(including multiple lines).
Examples:
/* This comment begins at this line.
This line is included in this comment
It ends at this line. */
// This comment starts here and ends at the end of this line.
9
GOOD Programming practice
•Be careful java is a sensitive language.
•It is good to begin every program with a comment that states the
purpose of the program and the author.
•Every java program consist of at least one class that the
programmer define.
•Begin each class name with capital letter.
•The class name doesn’t begin with a digit and doesn’t contain a
space.
•Use blank lines and spaces to enhance program readability
•When you type an opining left brace{ immediately type
the closing right brace}
•Indent the entire body of each class declaration
10