Java Programming I on YouTube:
https://www.youtube.com/playlist?list=PLLIqcoGpl73iaXAtS_-V_Xdx3mhTzPwb5
Developed by Sun Microsystems
Object-oriented
General-purpose
Architecturally neutral, can run on wide variety of computers
Does not execute instructions on computer directly
Runs on a hypothetical computer known as Java virtual machine (JVM)
Source code -- files containing
data definitions, and
programming statements written in high-level programming language
Even simplest Java application involves fair amount of confusing syntax
NetBeans
Eclipse
JCreator
BlueJ
many more exist!
IDE that lets you to
manage projects
view and compile the source code
run the application
debug the application
Each class is placed in its own source .java file
The source file name is the same as the class name
Java application is split in several source files and directories
Compiled source code for each class is placed in its own .class file that contains the bytecode
Always: file's name must match the name of the class!
Java programs execute in Java Virtual Machine, JVM
JVM makes Java interpreted programming language:
intermediate compilation step -- javac -- yields intermediate bytecode
When Java program executes its bytecode, it runs in the virtual machine
JVM's class loader has bytecode verifier to prevent unexpected results from loading corrupted .class files
communicates with operating system
executes bytecode instructions line by line within Java virtual machine
Standalone, or Desktop Application
Applet -- downloaded by the Java-enabled browser, running in a sandbox:
Untrusted applets don't have all of the JVM power. The Java sandbox restricts applets from performing many activities.
Trusted applets are digitally signed by their creator.
Servlets -- Java programs running on the web server
Distributed systems:
Java Enterprise Edition apps that run on application servers
Such apps require Application Server that works closely with web server and database:
WebLogic Application Server (Oracle)
WebSphere Application Server (IBM)
JBoss (Red Hat)
Geronimo (Apache)
TomEE (Apache)
Console applications: character-only input/output
Windowed applications: include GUI, Menus, Toolbars, Dialog boxes, etc.
Program is a set of written instructions that tells computer what to do
A compiler translates language statements into CPU instructions or bytecode, e.g.
( 2 + 5 ) * 3
internally becomes
multiply: ( add: 2 5 ) ( 3 )
Source code can have a syntax errors, which will prevent the compiler from finishing its translation.
If so, make necessary changes and recompile.
Most basic circuitry-level language
Low-level programming language
Allows more complex syntax and rules
Program statements
(Somewhat similar to human sentences)
Carry out tasks of program
Also known as semantic errors
Example: incorrect order of instructions
Debugging: Freeing program of all errors
The dialog box for opening a project
The dialog boxes for creating a new project
How to open, close, and delete a project
The starting source code
How to compile and run a project
The output window used for input and output
All Java applications must have method named main() wrapped inside a class:
public class HelloWorld { public static void main( String[] args ) { System.out.println( "Hello World!" ); } }
Literal string:
appears in output exactly as entered
written between double quotation marks
Program Arguments:
pieces of information passed to method
Method:
requires information to perform its task
The System class:
refers to the standard output device for a system
Everything used within Java program must be part of a class
class has a name, or identifier.
The identifier must begin with
Letter
Underscore
Dollar sign
Cannot begin with digit
Can only contain:
Letters
Digits
Underscores
Dollar signs
Cannot be Java reserved keyword, like true, false, or null
Comments are non-executing statements added to program for documentation
Comments leave notes for yourself or others, for example,
/* * author, date, purpose of the program */
Comment can temporarily deactivate a program statement by turning it into a comment
Compiler does not translate comments, and JVM does not know about comments
Line comments start with two forward slashes // and continue to the end of the current line
public class HelloWorld { // Application begins here: public static void main( String[] args ) { System.out.println( "Hello World!" ); // print } }
Block comments
start with forward slash and asterisk /*
end with asterisk and forward slash */
/*
This is my homework
*/
public class HelloWorld {
public static void main( String[] args ) {
System.out.println( "Hello World!" );
}
}
Block comments allow multiple lines of the program to hold your remarks:
/* This is a comment line. This is another comment line. */
To compile and run manually on the command line:
"C:\Program Files\Java\jdk1.7.0_06\bin\javac" C:\myrojects\Java\HelloWorld\src\helloworld\*.java cd C:\myrojects\Java\HelloWorld\src java -classpath "." helloworld.HelloWorld
If using NetBeans build, go to your "dist" folder and run "java -jar" command
cd C:\myrojects\Java\HelloWorld\dist java -jar "HelloWorld.jar"