SlideShare a Scribd company logo
A little cup of Java-coffee
Priyanka Gupta
CSE Dept.
Mcsgoc
Today’s session
• Part-1) Java overview
– What java is
– Java features
– Java’s cross-platform
• Part-2) two simple and typical java programs
– A stand-lone java and its running
– A applet and its running
Part-one
• Java overview
What Java is
• Java is an “easy” programming language,
– just a tool like C++, VB, …and English. Somehow a
language tool itself is not so complex.
• Java works for internet project(mainly), and apply
“3-tired architecture”, coding on the server-side
– So besides Java language knowledge, we need to learn
lots of thing about telecommunication on WEB, to
finish a real-time project.
What Java is(continue)
• Java applies Object-Oriented Tech.
– Java is not so difficulty, though OOP is. A java
expert must be an OOP expert.
• Java is slower than C++ ( 3-5 times), Java’s
database function is slower than VB.
• Java is very portable: cross-platform
Java’s Features
• Simple
Java omits many rarely used, poorly understood, confusing
features of C++. Say : No Pointer! No dynamic delete.
• Object Oriented
Object –oriented design is a technology that focuses design
on the data (object) and on the interfaces to it.
Let’s say, everything is an object, everything will
become a class in Java. Every java program, in top-
level view, is classes.
Java’s Features(continue)
• Robust
The single biggest difference between Java
and C/C++ is that Java has “a inner safe
pointer-model”, therefore it eliminates the
possibility of overwriting memory and corrupting
data, so programmers feel very safe in coding.
Java’s Features(continue)
• GUI [Java-Swing]
For some reason, Sun believe their java-swing
is very important, so they always put it in their
certificate-tests.
• Multi-threaded
• Secure [ Exception handling ]
• Dynamic [ for Server-side coding]
Java’s cross-platform
• Interpreted Execute: cross-platform
why: For cross-platform purpose. Once coding, run anywhere.
The Java interpreter ( java.exe and its javaVirtualMachine) can
execute compiled Java-byte-codes(Xxx.class) directly on any machine to
which the interpreter has been ported.
How: ( eg. Dos command line style)
- Edit source code “demo.java” , by notepad/or other IDE tools
- Compile ( javac.exe ) “demo.java” javac Demo.java  Java byte
codes, namely, Demo.class
- Execute (Interpreted Execute) java Demo
• Speed issue AND new solutions: java is slower than c++ in running.
however, by now, there are some new technology of Java compiler, such
as “Just-in-time”, and “HotSpot adaptive Compiler”. They make java
very faster than before.
Java: Run in Virtual Cpu
:cross-platfrom
Demo.java Compile Demo.class link xxx.class
Source-code “javac” byte-code files bytecode
program
interpretedly run on VM |-- Intel CPU
(virtual CPU: JSDK ) |-- … CPU
|-- Apple CPU
Part-2 2 samples
• How many kinds of java programs ?
• Demo-1: Stand-lone sample
• Demo-2: an Applet sample
How many kinds of Java Programs?
• Un-network app.: (1)Standalone Java program (today)
• Network app: non-standalone Java program
Internet: (2)Applet , (today)
(3)servlet
(4)JavaBean classes
Intranet: (5)EJB ( EnterpriseJavaBean ),
(6)RMI, etc
Standalone Java Program
• The main() method
public static void main(String args[]){
...
}
public--- the interpreter can call it
static ----It is a static method belonging to the class
void -----It does not return a value
String----It always has an array of String objects as its formal parameter.
the array contains any arguments passed to the program on the
command line
the source file’s name must match the class name which main method is
in
Java program
1 // Fig. 2.1: Welcome1.java
2 // A first program in Java
3
4 public class Welcome1 {
5 public static void main( String args[] )
6 {
7 System.out.println( "Welcome to Java Programming!" );
8 }
Welcome to Java Programming!
9 }
Java program
1 // Fig. 2.1: Welcome1.java
2 // A first program in Java
3
4 public class Welcome1 {
5 public static void main( String args[] )
6 {
7 System.out.println( "Welcome to Java Programming!" );
8 }
9 }
A Simple GUI Program: Printing a
Line of Text
• Display
– Most Java applications use windows or a dialog box
• We have used command window
– Class JOptionPane allows us to use dialog boxes
• Packages
– Set of predefined classes for us to use
– Groups of related classes called packages
• Group of all packages known as Java class library or Java
applications programming interface (Java API)
– JOptionPane is in the javax.swing package
• Package has classes for using Graphical User Interfaces
(GUIs)
1 // Fig. 2.6: Welcome4.java
2 // Printing multiple lines in a dialog box
3 import javax.swing.JOptionPane; // import class JOptionPane
4
5 public class Welcome4 {
6 public static void main( String args[] )
7 {
8 JOptionPane.showMessageDialog(
9 null, "WelcomentonJavanProgramming!" );
10
11 System.exit( 0 ); // terminate the program
12 }
13 }
Packages
• Like “namespace” in C++
• How to use:
– C++: using namespace xxx
– Java: import xxx, or
import xxx.xx
A Simple Java Applet: Drawing a
String
– appletviewer only understands
<applet> tags
• Ignores everything else
• Minimal browser
– Executing the applet
•appletviewer WelcomeApplet.html
• Perform in directory containing .class file
1 <html>
2 <applet code="WelcomeApplet.class" width=300 height=30>
3 </applet>
4 </html>
1 // Fig. 3.6: WelcomeApplet.java
2 // A first applet in Java
33 import javax.swing.JApplet; // import class JApplet
4 import java.awt.Graphics; // import class Graphics
5
66 public class WelcomeApplet extends JApplet {
77 public void paint( Graphics g )
8 {
9 g.drawString( "Welcome to Java Programming!", 25, 25 );
10 }
11 }
1 <html>
2 <applet code="WelcomeApplet.class" width=300 height=30>
3 </applet>
4 </html>
import allows us to use
predefined classes (allowing
us to use applets and
graphics, in this case).
extends allows us to inherit the
capabilities of class JApplet.
Method paint is guaranteed to
be called in all applets. Its first
line must be defined as above.
1 // Fig. 3.8: WelcomeApplet2.java
2 // Displaying multiple strings
3 import javax.swing.JApplet; // import class JApplet
4 import java.awt.Graphics; // import class Graphics
5
6 public class WelcomeApplet2 extends JApplet {
7 public void paint( Graphics g )
8 {
99 g.drawString( "Welcome to", 25, 25 );
10 g.drawString( "Java Programming!", 25, 40 );
11 }
12 }
1 <html>
2 <applet code="WelcomeApplet2.class" width=300 height=45>
3 </applet>
4 </html>
The two drawString statements
simulate a newline. In fact, the
concept of lines of text does not
exist when drawing strings.
1 // Displaying text and lines
2 import javax.swing.JApplet; // import class JApplet
3 import java.awt.Graphics; // import class Graphics
4
5 public class WelcomeLines extends JApplet {
6 public void paint( Graphics g )
7 {
8 g.drawLine( 15, 10, 210, 10 );
99 g.drawLine( 15, 30, 210, 30 );
10 g.drawString( "Welcome to Java Programming!", 25, 25 );
11 }
12 }
1 <html>
2 <applet code="WelcomeLines.class" width=300 height=40>
3 </applet>
4 </html>
Draw horizontal lines with
drawLine (endpoints have same
y coordinate).

More Related Content

PPT
Java review00
PPTX
Core java over view basics introduction by quontra solutions
PPTX
Mpl 1
PPT
Java essential notes
PPTX
Java introduction
PPTX
Java programming course for beginners
PDF
JVM, JRE and Javac are the main part for the java program
PPSX
Introduction to java
Java review00
Core java over view basics introduction by quontra solutions
Mpl 1
Java essential notes
Java introduction
Java programming course for beginners
JVM, JRE and Javac are the main part for the java program
Introduction to java

What's hot (18)

PPTX
History of java'
PDF
JAVA Program Examples
PPT
Introduction to java programming part 1
PPT
Introduction to Java Programming, Basic Structure, variables Data type, input...
PPT
Basic java part_ii
PPTX
Advance java prasentation
PPT
Java introduction
PPT
Java Presentation
PDF
Java basics notes
PPT
Chapter 1 introduction to java technology
PPTX
Java byte code & virtual machine
PPTX
Chapter 1
PDF
Learn Java Part 1
PPTX
Java history, versions, types of errors and exception, quiz
PPTX
Chapter 2.1
PDF
Lec 3 01_aug13
PDF
Introduction to java technology
DOCX
Java Tutorial to Learn Java Programming
History of java'
JAVA Program Examples
Introduction to java programming part 1
Introduction to Java Programming, Basic Structure, variables Data type, input...
Basic java part_ii
Advance java prasentation
Java introduction
Java Presentation
Java basics notes
Chapter 1 introduction to java technology
Java byte code & virtual machine
Chapter 1
Learn Java Part 1
Java history, versions, types of errors and exception, quiz
Chapter 2.1
Lec 3 01_aug13
Introduction to java technology
Java Tutorial to Learn Java Programming
Ad

Similar to Java ppts unit1 (20)

PPT
PPT
PPT
this_is_how_to_start_coding_in_java_lang.ppt
PPT
java swing
PDF
Java programming basics notes for beginners(java programming tutorials)
PDF
Java basics notes
PDF
Java basics notes
PPT
Javalecture 1
PPTX
JAVA ALL 5 MODULE NOTES.pptx
PPTX
Java/Servlet/JSP/JDBC
PDF
Java basics notes
PPT
INTRODUCTION TO JAVA APPLICATION
PDF
JAVA INTRODUCTION
PDF
JAVA INTRODUCTION
PPTX
Basics of JAVA programming
PDF
Java Concepts and Features-Programming in Java
PPTX
01. Introduction to programming with java
PDF
Java programming material for beginners by Nithin, VVCE, Mysuru
DOCX
Srgoc java
this_is_how_to_start_coding_in_java_lang.ppt
java swing
Java programming basics notes for beginners(java programming tutorials)
Java basics notes
Java basics notes
Javalecture 1
JAVA ALL 5 MODULE NOTES.pptx
Java/Servlet/JSP/JDBC
Java basics notes
INTRODUCTION TO JAVA APPLICATION
JAVA INTRODUCTION
JAVA INTRODUCTION
Basics of JAVA programming
Java Concepts and Features-Programming in Java
01. Introduction to programming with java
Java programming material for beginners by Nithin, VVCE, Mysuru
Srgoc java
Ad

Recently uploaded (20)

PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPT
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PDF
Smart Home Technology for Health Monitoring (www.kiu.ac.ug)
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PPTX
Funds Management Learning Material for Beg
PPTX
Introduction to Information and Communication Technology
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PPTX
newyork.pptxirantrafgshenepalchinachinane
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PPTX
innovation process that make everything different.pptx
PDF
Exploring VPS Hosting Trends for SMBs in 2025
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
Digital Literacy And Online Safety on internet
PPTX
Introduction to cybersecurity and digital nettiquette
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPT
Ethics in Information System - Management Information System
SASE Traffic Flow - ZTNA Connector-1.pdf
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
Tenda Login Guide: Access Your Router in 5 Easy Steps
Power Point - Lesson 3_2.pptx grad school presentation
Smart Home Technology for Health Monitoring (www.kiu.ac.ug)
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
Funds Management Learning Material for Beg
Introduction to Information and Communication Technology
Slides PPTX World Game (s) Eco Economic Epochs.pptx
newyork.pptxirantrafgshenepalchinachinane
Design_with_Watersergyerge45hrbgre4top (1).ppt
innovation process that make everything different.pptx
Exploring VPS Hosting Trends for SMBs in 2025
Unit-1 introduction to cyber security discuss about how to secure a system
Digital Literacy And Online Safety on internet
Introduction to cybersecurity and digital nettiquette
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Job_Card_System_Styled_lorem_ipsum_.pptx
Ethics in Information System - Management Information System

Java ppts unit1

  • 1. A little cup of Java-coffee Priyanka Gupta CSE Dept. Mcsgoc
  • 2. Today’s session • Part-1) Java overview – What java is – Java features – Java’s cross-platform • Part-2) two simple and typical java programs – A stand-lone java and its running – A applet and its running
  • 4. What Java is • Java is an “easy” programming language, – just a tool like C++, VB, …and English. Somehow a language tool itself is not so complex. • Java works for internet project(mainly), and apply “3-tired architecture”, coding on the server-side – So besides Java language knowledge, we need to learn lots of thing about telecommunication on WEB, to finish a real-time project.
  • 5. What Java is(continue) • Java applies Object-Oriented Tech. – Java is not so difficulty, though OOP is. A java expert must be an OOP expert. • Java is slower than C++ ( 3-5 times), Java’s database function is slower than VB. • Java is very portable: cross-platform
  • 6. Java’s Features • Simple Java omits many rarely used, poorly understood, confusing features of C++. Say : No Pointer! No dynamic delete. • Object Oriented Object –oriented design is a technology that focuses design on the data (object) and on the interfaces to it. Let’s say, everything is an object, everything will become a class in Java. Every java program, in top- level view, is classes.
  • 7. Java’s Features(continue) • Robust The single biggest difference between Java and C/C++ is that Java has “a inner safe pointer-model”, therefore it eliminates the possibility of overwriting memory and corrupting data, so programmers feel very safe in coding.
  • 8. Java’s Features(continue) • GUI [Java-Swing] For some reason, Sun believe their java-swing is very important, so they always put it in their certificate-tests. • Multi-threaded • Secure [ Exception handling ] • Dynamic [ for Server-side coding]
  • 9. Java’s cross-platform • Interpreted Execute: cross-platform why: For cross-platform purpose. Once coding, run anywhere. The Java interpreter ( java.exe and its javaVirtualMachine) can execute compiled Java-byte-codes(Xxx.class) directly on any machine to which the interpreter has been ported. How: ( eg. Dos command line style) - Edit source code “demo.java” , by notepad/or other IDE tools - Compile ( javac.exe ) “demo.java” javac Demo.java  Java byte codes, namely, Demo.class - Execute (Interpreted Execute) java Demo • Speed issue AND new solutions: java is slower than c++ in running. however, by now, there are some new technology of Java compiler, such as “Just-in-time”, and “HotSpot adaptive Compiler”. They make java very faster than before.
  • 10. Java: Run in Virtual Cpu :cross-platfrom Demo.java Compile Demo.class link xxx.class Source-code “javac” byte-code files bytecode program interpretedly run on VM |-- Intel CPU (virtual CPU: JSDK ) |-- … CPU |-- Apple CPU
  • 11. Part-2 2 samples • How many kinds of java programs ? • Demo-1: Stand-lone sample • Demo-2: an Applet sample
  • 12. How many kinds of Java Programs? • Un-network app.: (1)Standalone Java program (today) • Network app: non-standalone Java program Internet: (2)Applet , (today) (3)servlet (4)JavaBean classes Intranet: (5)EJB ( EnterpriseJavaBean ), (6)RMI, etc
  • 13. Standalone Java Program • The main() method public static void main(String args[]){ ... } public--- the interpreter can call it static ----It is a static method belonging to the class void -----It does not return a value String----It always has an array of String objects as its formal parameter. the array contains any arguments passed to the program on the command line the source file’s name must match the class name which main method is in
  • 14. Java program 1 // Fig. 2.1: Welcome1.java 2 // A first program in Java 3 4 public class Welcome1 { 5 public static void main( String args[] ) 6 { 7 System.out.println( "Welcome to Java Programming!" ); 8 } Welcome to Java Programming! 9 }
  • 15. Java program 1 // Fig. 2.1: Welcome1.java 2 // A first program in Java 3 4 public class Welcome1 { 5 public static void main( String args[] ) 6 { 7 System.out.println( "Welcome to Java Programming!" ); 8 } 9 }
  • 16. A Simple GUI Program: Printing a Line of Text • Display – Most Java applications use windows or a dialog box • We have used command window – Class JOptionPane allows us to use dialog boxes • Packages – Set of predefined classes for us to use – Groups of related classes called packages • Group of all packages known as Java class library or Java applications programming interface (Java API) – JOptionPane is in the javax.swing package • Package has classes for using Graphical User Interfaces (GUIs)
  • 17. 1 // Fig. 2.6: Welcome4.java 2 // Printing multiple lines in a dialog box 3 import javax.swing.JOptionPane; // import class JOptionPane 4 5 public class Welcome4 { 6 public static void main( String args[] ) 7 { 8 JOptionPane.showMessageDialog( 9 null, "WelcomentonJavanProgramming!" ); 10 11 System.exit( 0 ); // terminate the program 12 } 13 }
  • 18. Packages • Like “namespace” in C++ • How to use: – C++: using namespace xxx – Java: import xxx, or import xxx.xx
  • 19. A Simple Java Applet: Drawing a String – appletviewer only understands <applet> tags • Ignores everything else • Minimal browser – Executing the applet •appletviewer WelcomeApplet.html • Perform in directory containing .class file 1 <html> 2 <applet code="WelcomeApplet.class" width=300 height=30> 3 </applet> 4 </html>
  • 20. 1 // Fig. 3.6: WelcomeApplet.java 2 // A first applet in Java 33 import javax.swing.JApplet; // import class JApplet 4 import java.awt.Graphics; // import class Graphics 5 66 public class WelcomeApplet extends JApplet { 77 public void paint( Graphics g ) 8 { 9 g.drawString( "Welcome to Java Programming!", 25, 25 ); 10 } 11 } 1 <html> 2 <applet code="WelcomeApplet.class" width=300 height=30> 3 </applet> 4 </html> import allows us to use predefined classes (allowing us to use applets and graphics, in this case). extends allows us to inherit the capabilities of class JApplet. Method paint is guaranteed to be called in all applets. Its first line must be defined as above.
  • 21. 1 // Fig. 3.8: WelcomeApplet2.java 2 // Displaying multiple strings 3 import javax.swing.JApplet; // import class JApplet 4 import java.awt.Graphics; // import class Graphics 5 6 public class WelcomeApplet2 extends JApplet { 7 public void paint( Graphics g ) 8 { 99 g.drawString( "Welcome to", 25, 25 ); 10 g.drawString( "Java Programming!", 25, 40 ); 11 } 12 } 1 <html> 2 <applet code="WelcomeApplet2.class" width=300 height=45> 3 </applet> 4 </html> The two drawString statements simulate a newline. In fact, the concept of lines of text does not exist when drawing strings.
  • 22. 1 // Displaying text and lines 2 import javax.swing.JApplet; // import class JApplet 3 import java.awt.Graphics; // import class Graphics 4 5 public class WelcomeLines extends JApplet { 6 public void paint( Graphics g ) 7 { 8 g.drawLine( 15, 10, 210, 10 ); 99 g.drawLine( 15, 30, 210, 30 ); 10 g.drawString( "Welcome to Java Programming!", 25, 25 ); 11 } 12 } 1 <html> 2 <applet code="WelcomeLines.class" width=300 height=40> 3 </applet> 4 </html> Draw horizontal lines with drawLine (endpoints have same y coordinate).