Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

[an error occurred while processing this directive]

Java review

Organized by Java: How to Program chapter.

  1. About Java - history, compilation, etc.
  2. Applications, first program, arithmetic, memory.
  3. Applets, drawing, floating point.
  4. Conditional statements - if, else, while ++, --
  5. Conditional statements - for, do...while, switch, break, continue.
  6. Methods
  7. Arrays
  8. Object-Oriented Programming
  9. Graphical User Interface Components I

Typical Java Compilation/Execution Steps

  1. Edit source (.java) program (eg, your IDE)
  2. Compile source program to byte-codes (.class).
  3. Load into RAM using the Java Class Loader.
    • Verify correctness of byte codes.
    • Allocate stack, heap (classes and statics).
    • Start JVM (Java Virtual Machine) at main (application).
  4. JIT. JVM may translate a method from byte code to machine code the first time it's called (Just In Time compilation).
  5. Execute the machine code.
  6. The server version of the Java run-time system may recompile from byte code to machine instructions after analyzing the performance (HotSpot).

Implications of Java Byte Code

Java Byte Code (JBC) is interpreted/translated by the Java Virtual Machine (JVM).

  • Why compile to Java Byte Code instead of machine code?
  • Why use JIT compilation instead of an interpreter?
  • Is Java slower, same, or faster than eg C++ because of Java Byte Code.
  • How does JBC affect portability?
  • How does JBC affect distribution as eg Applets or WebStart?
  • Can other languages be compiled into Java Byte Code?
    See www.robert-tolksdorf.de/vmlanguages.html.

Design Patterns

Design patterns are "proven architectures for constructing flexible and maintainable object-oriented software". They:

  • Promote design reuse.
  • Help solve common problems.
  • Help avoid common mistakes.
  • Establish a common vocabulary among developers.

A First Program with Console Output

Similar to JHTP p 34 without comments

public class Welcome1 {
    public static void main(String[] args) {
        System.out.println("Welcome Earthlings");
    }
}
  • What file is this in?
  • What is the alternative way to declare the array parameter?

Program using Dialog Box

// Similar to JHTP p 43 without comments.
import javax.swing.JOptionPane;

public class Welcome2 {
    public static void main(String[] args) {
        JOptionPane.showMessageDialog(null, "Welcome Earthlings");
        
        System.exit(0);
    }
}

I don't expect you to know the answers to these - this time!

  • Give two alternatives to the import.
  • Why is System.exit(0) necessary here, but not in previous example?
  • What does the zero mean in System.exit(0)?
  • What would often replace the null in this example?
  • Is JOptionPane a class or an object?
  • Methods that are are qualified with a class are called which? static or instance?

Converting Strings to Integers

// Similar to JHTP p 47 without comments.
import javax.swing.JOptionPane;
public class Add2 {
    public static void main(String[] args) {
        String s1, s2;
        int    n1, n2;
        s1 = JOptionPane.showInputDialog(null, "Enter 1st number");
        n1 = Integer.parseInt(s1);
        s2 = JOptionPane.showInputDialog(null, "Enter 2nd number");
        n2 = Integer.parseInt(s2);
        
        JOptionPane.showMessageDialog(null, "Sum is " + (n1 + n2));
        
        System.exit(0);
    }
}
  • What happens if the user enters something that's not an int?
  • Are the parentheses around (n1 + n2) necessary?

Arithmetic Operators

Basic arithmetic operators: +, -, *, /, %

Precedence: *, /, and % are done before + or -.

If either operand of + is a string, the other operand is converted to string and the two strings are concatenated.

Arithmetic Comparison Operators

Comparison operators: <, <=, ==, !=, >=, >

Precedence: All are lower precedence than the arithmetic operators.
<, <=, >=, > are higher than ==, !=, but there is no apparent reason for this except compatibility with C and C++.

The result of any comparison is boolean true or false.

Logical Operators

  • boolean true or false is the result of all logical operators.
  • "Short circuit" operators (&&, ||): They do not need to evaluate both operands when result is known. Best choice most of the time.
  • And - &&, & - true only if both operands are true.
  • Or - ||, | - true if either of the operands is true.
  • Not - ! - true if operand is false, false if operand is true.
  • Xor (exclusive or) - ^ - true if the operands are different, false if they are the same.
  • Precedence: comparisons > & > ^ > | > && > ||
    In practice, remember they are lower than comparison, but always use parentheses when mixing logical operators.

End

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (
post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.