2. Introduction to Java Programming
– Environment Setup
Java Overview?
Features of Java?
Components of Java
JVM, JDK and JRE
Steps to Write Program?
Basic Java Syntax & Rules
Comments, Package, Imports
Class Structure
Constructor
Variables/Properties
Methods -Main
Java IDEs
Lab Problem
Java – Environment Setup
Download and Install
Set Environments
Write Your First Program
Install Eclipse IDE
Create Workspace
Write Program and Execute
Home Work
Write Programs and Execute
3. What is Java?
• Easy English like Language
• Developed by James Gosling
in 1995 for Sun Microsystems
• Java is an object-oriented language
similar to C++, but with advanced and
simplified features.
• Java is free to access
• Write Once and Run Any Where
6. Components of Java:
• JVM (Java Virtual Machine)
• Execute the bytecode produced by compiler.
• Each operating system has different JVM
• JRE (Java Runtime Environment)
• JRE includes JVM, browser plugins and applets support.
• When you only need to run a java program on your computer, you would only
need JRE.
• JDK (Java Development Kit)
• Java development kit that includes JRE (Java Runtime Environment), compilers
and various tools like JavaDoc, Java debugger etc.
• In order to create, compile and run Java program you would need JDK
8. Steps to Write Program:
• Type the Program – Source Code
• Compile to Bytecode
• Run the program
compile execute
output
source code
Hello.java
byte code
Hello.class
11. Basic Structure and Syntax of Java:
public class HelloJava {
public static void main(String args[]){
System.out.println("Hello Java World");
}
}
12. Basic Structure and Syntax of Java:
• Case Sensitivity
• Class Names
• Example: class MyFirstJavaClass
• Method Names
• Example: public void myMethodName()
• Program File Example: Assume 'MyFirstJavaProgram' is the class
name. Then the file should be saved as 'MyFirstJavaProgram.java'
• public static void main(String args[]) - Java program processing
starts from the main() method which is a mandatory part of every
Java program.
13. Class Structure :
package <package name>
Import <package name>.* or <class name>
/* comments */
public class <class name> {
private String <variable name>
/*Constructor */
public <class name> (){
}
//Methods
public static void main(String args[]) {
<statement>;
<statement>;
...
<statement>;
}
public <return type> <method name>(<parameters>){
<statement>;
<statement>;
...
<statement>;
}
}
14. Basic Structure and Syntax of Java:
Comments:
Single line
// compiler ignores everything to end of line
Multi-line
/* compiler ignores everything in between */
Block/Multi-line (documentation)
/** compiler ignores everything in between */
Comments do not appear in executable code
run on all platforms.
Concurrent where you can execute many statements instead of sequentially executing it.
Class-based and an object-oriented programming language.
Independent programming language that follows the logic of “Write once, Run anywhere” i.e. the compiled code can run on all platforms which supports java.
Simple :
Portable: Java is platform independent which means “Write Once and Run Anywhere”
Object-oriented: Everything is considered to be an “object” which possess some state, behavior.
Secured: All the code is converted in bytecode after compilation, which is not readable by a human.
Dynamic: supports dynamic memory allocation due to which memory wastage is reduced and performance of the application is increased.
Distributed: You can access files by calling the methods from any machine on the internet.
Robust: Java has a strong memory management system. It helps in eliminating error as it checks the code during compile andruntime.
High Performance: With the use of JIT (Just-In-Time) compilers, Java enables high performance.
Interpreted:
Multithreaded
has only one method main(), which is an entry point of a Java application (program).
Methods can call (use) other methods, for example our method main() calls the method println()
Each method starts with a declaration line called a method signature: t tton Run, to start the the program. It will prorld in the co
Who can access the method - public
Instructions on how to use it - static.
Does the method return any data?
The name of the method is main.
The list of arguments
- Java is case sensitive, which means identifier Hello and hello would have different meaning in Java.
- For all class names the first letter should be in Upper Case. If several words are used to form a name of the class, each inner word's first letter should be in Upper Case.
- All method names should start with a Lower Case letter. If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case.
Name - Name of the program file should exactly match the class name. When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match, your program will not compile).