Java 01
Java 01
CS 331
Introduction
• Present the syntax of Java
• Introduce the Java API
• Demonstrate how to build
– stand-alone Java programs
– Java applets, which run within browsers e.g.
Netscape
• Example programs
Applets, Servlets and
Applications
• An applet is designed to be embedded in a
Web page, and run by a browser
• Applets run in a sandbox with numerous
restrictions; for example, they can’t read
files and then use the network
• A servlet is designed to be run by a web
server
• An application is a conventional program
Installtion
• Jdk:The Java Development Kit (JDK)
is a distribution of Java Technology
by Oracle Corporation. It implements
the Java Language Specification
(JLS) and the Java Virtual Machine
Specification (JVMS) and provides
the Standard Edition (SE) of the Java
Application Programming Interface
(API).
• Netbeans:NetBeans is an integrated
development environment (IDE) for
Java. NetBeans allows applications to
be developed from a set of modular
software components called modules.
NetBeans runs on Windows, macOS,
Linux and Solaris.
Java Virtual Machine
• The .class files generated by the compiler are
not executable binaries
– so Java combines compilation and interpretation
• Instead, they contain “byte-codes” to be
executed by the Java Virtual Machine
– other languages have done this, e.g. UCSD Pascal
• This approach provides platform
independence, and greater security
HelloWorld (standalone)
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
• class HelloWorld
• {
• public static void main(String args[])
• {
• System.out.println("Hello, World");
• }
• }
• Output
class MyClass { public static void main(String[] args) { int x, y,
sum; Scanner myObj = new Scanner(System.in);
System.out.println("Type a number:"); x = myObj.nextInt();
System.out.println("Type another number:"); y = myObj.nextInt(); sum
= x + y; of x + y System.out.println("Sum is: " + sum);} }
• Output