Learn Java with Rick Delpo

this is our homepage for Java related content

click here for tutorials.....

featuring JAVA Tutorial with SQL for beginners


click here for a quickie beginner JDBC Tutorial on how to connect to DATA

click here to explore JDBC using the Java Servlet API with embedded Tomcat

click here to go to our home page where we can read up on SQL and Webdev (AWS) too


plus...Additional Learning Material for the absolute Java Beginner

Table of Contents

 

 

 

 


Java is a popular programming language, created in 1995. It is owned by Oracle, and more than 3 billion devices run Java.

Back to top of page
1.1 What is java all about?

Like any programming language, the Java language has its own structure, syntax rules, and programming paradigm. The Java language's programming paradigm is based on the concept of OOP, which the language's features support.

The Java language is a C-language derivative, so its syntax rules look much like C. For example, code blocks are modularized into methods and delimited by braces ({ and }), and variables are declared before they are used.

Structurally, the Java language starts with packages. A package is the Java language's namespace mechanism. Within packages are classes, and within classes are methods, variables, constants, and more. You learn about the parts of the Java language in this app.



Back to top of page
1.2 The Java compiler

When you program for the Java platform, you write source code in .java files and then compile them. The compiler checks your code against the language's syntax rules, then writes out bytecode in .class files. Bytecode is a set of instructions targeted to run on a Java virtual machine (JVM). In adding this level of abstraction, the Java compiler differs from other language compilers, which write out instructions suitable for the CPU chipset the program will run on.

Compiling a Java Program

Java source code is always stored in files with the extension .java. After you have created the source code for a program and saved it in a .java file, you need to process the source using a Java compiler. Using the compiler that comes with the JDK, you make the directory that contains your Java source file the current directory, and then enter the following command:

javac MyProgram.java

Here, javac is the name of the Java compiler, and MyProgram.java is the name of the program source file. This command assumes that the current directory contains your source fi le. If it doesn't, the com'piler isn't able to fi nd your source fi le. It also assumes that the source fi le corresponds to the Java language as defined in the current version of the JDK. There is a command-line option, -source, that you can use to specify the Java language version, so for JDK 7, the preceding command to execute the compiler is equivalent to the following:

javac -source 1.7 MyProgram.java

In practice you can ignore the -source command-line option unless you are compiling a Java program that was written using an older version of the JDK. You get the current source version compiled by default. To compile code written for JDK 6 you would write:

public class MyProgram{
  public static void main(String[] args){
        System.out.println(Rome wasn't burned in a day!);
  }
}

Executing a Java Application

To execute the bytecode program in the .class fi le with the Java interpreter in the JDK, you make the directory containing the .class fi le current and enter the command:

java MyProgram

Note that you use just the name MyProgram to identify the program, not the name of the file that the compiler generates, MyProgram.class. It is a common beginner's mistake to use the latter by analogy with the compile operation.



Back to top of page