Java Basics: - Presentation By: - Abh
Java Basics: - Presentation By: - Abh
What Java is
Java is an easy programming language,
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.
Java is slower than C++ ( 3-5 times), Javas database function is slower than VB. Java is very portable: cross-platform
Javas 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. Lets say, everything is an object, everything will become a class in Java. Every java program, in toplevel view, is classes.
Javas Features(continue)
Distributed Basically, Java is for Net-Work application, for WEB
project. Java can open and access objects across the Net via URLs (Uniform Resource Locator)----eg. http//:gamut.neiu.edu/~ylei/home.html, with the same ease as when accessing a local file system
Javas 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.
Javas 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.
Javas 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.
Demoh.h
2. Interpreters execute the source code directly. Examples: BASIC, Perl, TCL/Tk, ML.
source
[load]
source-program
[interpret run]
- Intel cpu
demo.perl - data
1 2 3 4 5 6 7
public class Welcome1 { public static void main( String args[] ) { System.out.println( "Welcome to Java Programming!" );
8
9 }
Java program
1 2 3 4 5 6 7
public class Welcome1 { public static void main( String args[] ) { System.out.println( "Welcome to Java Programming!" );
8
9 }
Java program
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)
1 2 3 4 5 6 7 8 9 10 11 12
// Fig. 2.6: Welcome4.java // Printing multiple lines in a dialog box import javax.swing.JOptionPane; // import class JOptionPane
public class Welcome4 { public static void main( String args[] ) { JOptionPane.showMessageDialog( null, "Welcome\nto\nJava\nProgramming!" );
System.exit( 0 ); }
13 }
Packages
Like namespace in C++ How to use: C++: using namespace xxx Java: import xxx, or import xxx.xx
1 2 3 4
1 2 3 4 5 6 7
// Fig. 3.6: WelcomeApplet.java // A first applet in Java import javax.swing.JApplet; import java.awt.Graphics; // import class JApplet // import class Graphics
import allows us to use predefined classes (allowing us to use applets and graphics, in this case).
8
9
{ }
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.
10
11 } 1 2 3 4
1 2 3 4 5 6 7 8 9 10 11
// Fig. 3.8: WelcomeApplet2.java // Displaying multiple strings import javax.swing.JApplet; import java.awt.Graphics; // import class JApplet // import class Graphics
public class WelcomeApplet2 extends JApplet { public void paint( Graphics g ) { g.drawString( "Welcome to", 25, 25 ); g.drawString( "Java Programming!", 25, 40 ); }
12 }
1 2 3 4
The two drawString statements simulate a newline. In fact, the concept of lines of text does not exist when drawing strings.
1 2 3 4 5 6 7 8 9 10 11
// Displaying text and lines import javax.swing.JApplet; import java.awt.Graphics; // import class JApplet // import class Graphics
public class WelcomeLines extends JApplet { public void paint( Graphics g ) { g.drawLine( 15, 10, 210, 10 ); g.drawLine( 15, 30, 210, 30 ); g.drawString( "Welcome to Java Programming!", 25, 25 ); }
12 }