2.introduction To JAVA
2.introduction To JAVA
2
Syeda Ajbina Nusrat, Lecturer, CSE, UITS
What is Java?
3
Syeda Ajbina Nusrat, Lecturer, CSE, UITS
What is Java?
• Distributed
– Fully supports IPv4, with structures to support IPv6
– Includes support for Applets: small programs embedded in HTML
documents
• Interpreted
– The program are compiled into Java Virtual Machine (JVM) code
called bytecode
– Each bytecode instruction is translated into machine code at the
time of execution
4
Syeda Ajbina Nusrat, Lecturer, CSE, UITS
What is Java?
• Robust
– Java is simple – no pointers/stack concerns
– Exception handling – try/catch/finally series allows for
simplified error recovery
– Strongly typed language – many errors caught during
compilation
5
Syeda Ajbina Nusrat, Lecturer, CSE, UITS
JAVA - the popular one
6
Syeda Ajbina Nusrat, Lecturer, CSE, UITS
JAVA - the popular one
7
Syeda Ajbina Nusrat, Lecturer, CSE, UITS
JAVA - the popular one
8
Syeda Ajbina Nusrat, Lecturer, CSE, UITS
Java Editions
9
Syeda Ajbina Nusrat, Lecturer, CSE, UITS
Java platform
10
Syeda Ajbina Nusrat, Lecturer, CSE, UITS
Java Development Environment
• Edit
– Create/edit the source code
• Compile
– Compile the source code
• Load
– Load the compiled code
• Verify
– Check against security restrictions
• Execute
– Execute the compiled
● javac Welcome.java
○ Searches the file in the current directory
○ Compiles the source file
○ Transforms the Java source code into bytecodes
○ Places the bytecodes in a file named Welcome.class
• A Java source file can contain multiple classes, but only one class can be
a public class
• Typically Java classes are grouped into packages (similar to
namespaces in C++)
• A public class is accessible across packages
• The source file name must match the name of the public class defined
in the file with the .java extension
• Think of JVM as a outside Java entity who tries to access the main
method of class Welcome
○ main must be declared as a public member of class
Welcome
• JVM wants to access main without creating an object of class Welcome
○ main must be declared as static
• JVM wants to pass an array of String objects containing the
command line arguments
○ main must take an array of String as parameter
• System.out.println()
○ Used to print a line of text followed by a new line
○ System is a class inside the Java API
○ out is a public static member of class System
○ out is an object of another class of the Java API
○ out represents the standard output (similar to stdout or cout)
○ println is a public method of the class of which out is an object
• Place the .java file in the bin directory of your Java installation
○ C:\Program Files\Java\jdk1.8.0_51\bin
• Open a command prompt window and go to the bin
directory
• Execute the following command
○ javac Welcome.java
• If the source code is ok, then javac (the Java compiler) will produce a
file called Welcome.class in the current directory
• If the source file contains multiple classes then javac will produce
separate .class files for each class
• Every compiled class in Java will have their own .class file
• .class files contain the bytecodes of each class
• So, a .class file in Java contains the bytecodes of a single class only