java:characteristics, classpath, compliation

13
1. Java is Object-Oriented Object-oriented programming provides great flexibility, modularity, clarity, and reusability through encapsulation, inheritance, and polymorphism. 2. Java Is Distributed Distributed computing involves several computers working together on a network. Java is designed to make distributed computing easy as networking capability is inherently integrated into Java. Thus, writing network programs is like sending and receiving data to and from a file. CHARACTERISTICS OF JAVA

Transcript of java:characteristics, classpath, compliation

Page 1: java:characteristics, classpath, compliation

1. Java is Object-Oriented

• Object-oriented programming provides great flexibility, modularity, clarity, and

reusability through encapsulation, inheritance, and polymorphism.

2. Java Is Distributed

• Distributed computing involves several computers working together on a network.

• Java is designed to make distributed computing easy as networking capability is

inherently integrated into Java.

• Thus, writing network programs is like sending and receiving data to and from a

file.

CHARACTERISTICS OF JAVA

Page 2: java:characteristics, classpath, compliation

3. Java Is Interpreted

• You need an interpreter to run Java programs.

• The programs are compiled into the Java Virtual Machine code called bytecode.

• The bytecode is machine-independent and can run on any machine that has a Java

interpreter, which is part of the Java Virtual Machine (JVM).

4. Java Is Robust

• Java compilers can detect many problems that would first show up at execution

time in other languages.

• Java has a runtime exception-handling feature to provide programming support

for robustness.

CHARACTERISTICS OF JAVA

Page 3: java:characteristics, classpath, compliation

5. Java Is Secure

• Java implements several security mechanisms to protect your system against

harm caused by stray programs.

6. Java Is Architecture-Neutral

• Write once, run anywhere. With a Java Virtual Machine (JVM), you can write one

program that will run on any platform.

7. Java Is Portable

• They can be run on any platform without being recompiled.

CHARACTERISTICS OF JAVA

Page 4: java:characteristics, classpath, compliation

Set path to JDK bin directory

set path=c:\Program Files\java\jdk1.6.0\bin

Set classpath to include the current directory

set classpath=.

Compile

javac Welcome.java

Run

java Welcome

COMPILING AND RUNNING JAVA FROM THE CMD

Page 5: java:characteristics, classpath, compliation

Right click My Computer.

Choose Properties from the context menu.

Click the Advanced system settings link.

Go to Advanced tab. Click Environment Variables.

In the section System Variables, find the PATH environment variable and

select it. Click Edit.

If the PATH environment variable does not exist, click New.

In the Edit System Variable (or New System Variable) window, specify

the value of the PATH environment variable.

Click OK. Close all remaining windows by clicking OK.

SETTING PATH AND CLASSPATH DIRECTLY IN WINDOWS 7

Page 6: java:characteristics, classpath, compliation

After installation, the JDK directory will have the structure shown below.

C:\Java\jdk1.7.0\bin\ //contains both the compiler and the launcher.

The PATH environmental variable contains the path of the executables (javac.exe,

java.exe, javadoc.exe, and so on)

The CLASSPATH variable is one way to tell applications, including the JDK tools, where

to look for user classes.

After setting the PATH variable, we can access these executables (compiler, launcher

etc) from any directory without having to type the full path of the command. For e.g.

javac Example.java - If the PATH is set, then we use following in CMD

C:\Java\jdk1.7.0\bin\javac Example.java - Otherwise

The following is an example of a PATH environment variable:

C:\Java\jdk1.7.0\bin;C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem

PATH and CLASSPATH

Page 7: java:characteristics, classpath, compliation

1. System.out.println(“Hello World”); – outputs the string

“Hello World” followed by a new line on the screen.

2. System.out.print(“Hello World”); - outputs the string “Hello

World” on the screen. This string is not followed by a new line.

3. Some Escape Sequence –

• \n – stands for new line character

• \t – stands for tab character

PRINTING ON THE SCREEN

Page 8: java:characteristics, classpath, compliation

//This program prints Welcome to Java!

public class Welcome {

public static void main(String[] args) {

System.out.println("Welcome to Java!");

}

}

A SIMPLE JAVA PROGRAM

Page 9: java:characteristics, classpath, compliation

//This program prints Welcome to Java!

public class Welcome {

public static void main(String[] args) {

System.out.println("Welcome to Java!");

}

}

PROGRAM EXECUTION – STEP I

Enter main method.

The main method provides the control of program flow. The Java interpreter

executes the application by invoking the main method.

Page 10: java:characteristics, classpath, compliation

//This program prints Welcome to Java!

public class Welcome {

public static void main(String[] args) {

System.out.println("Welcome to Java!");

}

}

PROGRAM EXECUTION – STEP II

Execute Statement 1

Page 11: java:characteristics, classpath, compliation

Java Standard Edition (J2SE)J2SE can be used to develop client-side standaloneapplications or applets.

Java Enterprise Edition (J2EE)J2EE can be used to develop server-side applications such asJava servlets and Java ServerPages.

Java Micro Edition (J2ME)J2ME can be used to develop applications for mobile devicessuch as cell phones.

Popular Java IDEs NetBeans Open Source by Sun Eclipse Open Source by IBM

JDK Editions & IDEs

Page 12: java:characteristics, classpath, compliation
Page 13: java:characteristics, classpath, compliation