0% found this document useful (0 votes)
8 views

Java

The document is a lecture on Java programming language, detailing its history, features, and basic structure. Java, originally named Oak, is highlighted for its simplicity, object-oriented nature, and architecture neutrality, allowing it to run on any machine. It also includes a brief introduction to writing and executing a simple Java program, explaining key components like the main method and output statements.

Uploaded by

Niaz Tanha
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Java

The document is a lecture on Java programming language, detailing its history, features, and basic structure. Java, originally named Oak, is highlighted for its simplicity, object-oriented nature, and architecture neutrality, allowing it to run on any machine. It also includes a brief introduction to writing and executing a simple Java program, explaining key components like the main method and output statements.

Uploaded by

Niaz Tanha
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Modern Programming

Language
Lecture-01

Instructor: Mr. Suleman shah

University of Shangla
Introduction
 Java is a High Level programming
Language.

The first name of Java was Oak,


developed in 1991. In 1995, it was
renamed as Java.
Why Choose Java?
 Simple
 Object-oriented
 Robust
 Multithreaded
 Architecture-Neutral
 Interpreted and High Performance
 Distributed
 Portable
Java is Architecture Neutral!
 The most important advantage of
java over other programming
Languages is that, Java is
Architecture Neutral.
 This means that a Program written in
java can be run by “Any Machine”
having “Any operating System”.
Java’s Magic
 Java program is first compiled and
then it is interpreted. When a java
program is compiled, it is then
converted into byte code. Byte code
is intermediate code. Byte code is a
set of instructions designed to be
executed by the JVM. JVM stands for
the Java Virtual Machine. The JVM is
interpreter for java byte code.
A Brief History of Java
 In 1990, Sun Microsystems began an internal project
known as the Green Project to work on a new technology.
 1995, Java was first publicly released.
 In 1996, Java Development Kit (JDK ) 1.0 was released.
 In 2002, JDK 1.4 (codenameMe rlin Merlin) was released, the
most widely used version.
 In 2004, JDK 5.0 (codenameTige r Tiger) was released, the
latest version.
 James Gosling is generally credited as the inventor of the
Java programming language
 He was the first designer of Java and implemented its
original compiler and virtual machine
 He is also known as the Father of Java
 He is currently the Chief Technical Officer of Sun
Microsystems
James Gosling
Your First Java Program

 class Example {

 // Your program begins with a call to main().

 public static void main(String args[]) {

 System.out.println("This is our first Java program.");

 }

 }
Compiling The Program
 To compile the Example program, execute the
compiler, javac, specifying the name of the source
file on the command line, as shown here:

 C:\>javac Example.java

 The javac compiler creates a file called


Example.class that contains the bytecode version of
the program. The Java bytecode is the intermediate
representation of your program that contains
instructions the Java interpreter will execute. Thus,
the output of javac is not code that can be directly
executed.
Executing The Program
 To actually run the program, you must
use the Java interpreter, called java. To
do so, pass the class name Example as
a command-line argument, as shown
here:
 C:\>java Example
 When the program runs, the following
output is displayed:

This is a simple Java program.


class Example {
 This line uses the keyword class to
declare that a new class is being
defined. Example is an identifier that
is the name of the class. The entire
class definition, including all of its
members, will be between the opening
curly brace ({) and the closing curly
brace (}). This is one reason why all
Java programs are object-oriented.
public static void main(String
args[]) {
 This line begins the main( ) method.
As the comment preceding it
suggests, this is the line at which the
program will begin executing. All Java
applications begin execution by
calling main( ). (This is just like C/C+
+.)
public
 The public keyword is an access specifier,
which allows the programmer to control
the visibility of class members. When a
class member is preceded by public, then
that member may be accessed by code
outside the class in which it is declared.
public…
 In this case, main( ) must be declared as
public, since it must be called by code
outside of its class when the program is
started. The keyword static allows main( ) to
be called without having to instantiate a
particular instance of the class. This is
necessary since main( ) is called by the Java
interpreter before any objects are made.
The keyword void simply tells the compiler
that main( ) does not return a value.
main()
 main( ) is the method called when a Java
application begins. Keep in mind that Java
is case-sensitive. Thus, Main is different
from main. It is important to understand
that the Java compiler will compile classes
that do not contain a main( ) method. But
the Java interpreter has no way to run
these classes. So, if you had typed Main
instead of main, the compiler would still
compile your program. However, the Java
interpreter would report an error because
it would be unable to find the main( )
parameter
 Any information that you need to
pass to a method is received by
variables specified within the set of
parentheses that follow the name of
the method. These variables are
called parameters. If there are no
parameters required for a given
method, you still need to include the
empty parentheses.
Parameter…
 In main( ), there is only one
parameter. String args[ ] declares a
parameter named args, which is an
array of instances of the class String.
Objects of type String store character
strings. In this case, args receives
any command-line arguments
present when the program is
executed.
main() revisited…
 One other point: main( ) is simply a
starting place for your program. A
complex program will have dozens of
classes, only one of which will need
to have a main( ) method to get
things started.
System.out.println("This is a
simple Java program.");
 This line outputs the string “This is
our first Java program.” followed by a
new line on the screen. Output is
actually accomplished by the built-in
println( ) method. In this case,
println( ) displays the string which is
passed to it. System is a predefined
class that provides access to the
system, and out is the output stream.
End

You might also like