Sunteți pe pagina 1din 51

 Java is developed by Sun Microsystems.

 This language was initially called “Oak” but was renamed


“Java” in 1995.

 Java was developed for creating platform independent


software for various consumer electronic devices.
 In an attempt to find such a solution,
 Gosling and others began work on a portable, platform-
independent language that could be used to produce code
that would run on a variety of CPUs under differing
environments. This effort ultimately led to the creation of
Java
 This second force was, of course, the World Wide Web.
 Java is also needed for Portable Internet programs.
 Java program are secure and portable
 Java creates two types of programs
 Application Programs
 It is a program that runs on your computer,
under the operating system of that computer.
That is, an application created by Java is more
or less like one created using C or C++.
 Applet
◦ It is a program designed to be transmitted over the
Internet and executed by a Java-compatible Web
browser.
◦ The important difference is that an applet is an
intelligent program, not just an animation or media
file. In other words, an applet is a program that can
react to user input and dynamically change—not just
run the same animation or sound over and over.
 The key that allows Java to solve both the
security and the portability problems just
described is that the output of a Java
compiler is not executable code. Rather, it is
bytecode.
 Java Virtual Machine (JVM) is Java run time
system, which interpret source code to
BYTECODE instead of executable code.
 Bytecode is a highly optimized set of
instructions designed to be executed by the
java run time system (JVM)
 Translating a Java program into bytecode
helps makes it much easier to run a program
in a wide variety of environments.
 The reason is straightforward: only the JVM
needs to be implemented for each platform.
 Once the run-time package exists for a given
system, any Java program can run on it.
 Remember, although the details of the JVM
will differ from platform to platform, all
interpret the same Java bytecode.
 The fact that a Java program is interpreted also
helps to make it secure. Because the execution of
every Java program is under the control of the
JVM, the JVM can contain the program and
prevent it from generating side effects outside of
the system.
 When a program is interpreted, it generally runs
substantially slower than it would run if compiled
to executable code.
 However, with Java, the differential between the
two is not so great. The use of bytecode enables
the Java run-time system to execute programs
much faster than you might expect.
 Simple
 Secure and Robust
 Platform independent
 Portable
 Object oriented
 Multithreaded and Distributed
 Dynamic and high performance
 Abstraction
 Encapsulation
 Inheritance
 Polymorphism
 Java environment includes a large number of
development tools and classes and methods.
 The development tools are part of the system
known as java development kit (JDK) and java
standard library (JSL) also known as
application programming interface (API)
 Appletviewer
 Javac (compiler)
 Java (interpreter)
 Javap(java disassembler)
 Javah( for c header file)
 Javadoc(for creating HTML document)
 Jdb(java debugger)
Text Editor

Java source code javadoc HTML Files

Javac

Java class file javah Header files

java JDB

Java program output


 Language support package
 Utilities package
 Input/output package
 Networking package
 AWT package
 Applet package
 Document section
 Package statement
 Import statement
 Interface statement
 Class definition
 Main method class
 Enter the program in Notepad

Run Program
The descriptions that follow use the standard Java 2 SDK (Software
Development Kit), which is available from Sun Microsystems.
Java is case-sensitive.
 Java Class Libraries

 Data Types- Integers, Floating Point


numbers, Characters, Boolean.

 Variable Declaration
type identifier = value;
Java Keywords
 16 bit. Range is 0 to 65536
 Type Conversion and Casting

 For automatic conversions the two types


should be compatible and destination type
should be larger than the source type.

 Explicit conversion
(target-type) value

 Arrays
type var-name[ ]; or type[ ] var-name;
 Operators – Arithmetic, Bitwise, Relational,
Logical, Assignment.

 ? Operator
exp1 ? exp2 : exp3
i=
Relational
 Selection Statements- if-else, switch case

 Iteration Statements- while, do-while, for.

 Jump Statements- break, continue, return.


 Group of like typed variables
 A specific element in an array is accessed by
its index.
 Index starts for 0 to n-1.
 One dimensional, two dimensional, 3
dimensional etc.
 Size of array is found in its length instance
variable.
 Type var-name[];
 Var-name = new type[size];
 E.g. Int num[];
 num = new int[5]; or
 int num= new int[5];
 Arrays can be initialized when they are
declared.
 E.g. int num[] = {1,2,3,4,5};
 Int twoD[][] = new int[4][5];
 or
 Int twoD[][]= new int[2][];
 twoD[0]= new int[5];
 twoD[1]= new int[5];
 Or initialize array when declaring
 Int twoD[][]={{1,2},{3,4}};
 Char array is declared as String object
 String str=“This is a test”;
 When user wants to pass information into a
program
 Whatever is passed to main() is stored as
String array
 Example 1 (cmdline)
 Example 2 (cmdlineint)

S-ar putea să vă placă și