Become Familiar with the programming Environment
Set aside some time to become familiar with the programming environment that you will use for your class work.
Please install the appropriate Java version on your system. You can download it from http://www.oracle.com/technetwork/java/javase/downloads/index.html
Familiar with these terms:
JDK - Java Development Kit, used by developers. It contains compiler, and other tools used by developers.
JRE - Java Runtime Environment - used by customers for running java programs. Contains JVM and core libraries. Good for running byte code.
Java library - rich set of library classes.
Since you want to develop the Java programs, please install JDK on your system. After installation is successful, please make to the PATH environment variable is set properly or not. If not, please set it up correctly so that you can run your java binaries from anywhere on the command line.
Java documentation samples - There are lot of samples here which helps how to use the java classes.
If you use IDE, the compilation and launching of JVM is internal to IDE. You don't have to manually launch them.
Indentation:
Set aside some time to become familiar with the programming environment that you will use for your class work.
Please install the appropriate Java version on your system. You can download it from http://www.oracle.com/technetwork/java/javase/downloads/index.html
Familiar with these terms:
JDK - Java Development Kit, used by developers. It contains compiler, and other tools used by developers.
JRE - Java Runtime Environment - used by customers for running java programs. Contains JVM and core libraries. Good for running byte code.
Java library - rich set of library classes.
Since you want to develop the Java programs, please install JDK on your system. After installation is successful, please make to the PATH environment variable is set properly or not. If not, please set it up correctly so that you can run your java binaries from anywhere on the command line.
Java documentation samples - There are lot of samples here which helps how to use the java classes.
- Step 1 : Start the Java development environment.
- An editor is a program for entering and modifying text, such as a Java program
- Use any text editor - notepad, word processor, etc where you can enter your java instructions.
- You can install an integrated development environment (IDE) like Eclipse, Netbeans, JDeveloper, etc
- Step 2: Write a simple program
- No matter which programming environment you use, you begin your activity by typing the program statements into an editor window.
- Step 3: Run the program
- Step 4: Organize your work - folders and file organization
Java is case sensitive. You must be careful about distinguishing between upper- and lowercase letters.
The Java compiler translates source code into class files that contain instructions for the Java virtual machine.
The Java Virtual Machine(JVM) executes the class files.
The Java Virtual Machine(JVM) executes the class files.
If you use IDE, the compilation and launching of JVM is internal to IDE. You don't have to manually launch them.
Indentation:
- must be four spaces
- If tabs are used in place of spaces, they must be set every eight spaces.
How to compile Java program:
Example, you have written a source file as HelloWorld.java, then use the following command:
javac HelloWorld.java
After this, compiler translates the source file(.java) file to instructions understood by JVM into a file called .class file. Now, for this example it creates HelloWorld.class
Note: There are lot of other options provided by javac compiler. Please check them by yourself.
The files that store compiled Java code are known as classfiles because they often store the runtime representation of Java classes.
How to run Java program:
To run HelloWorld.class file, you use the following command:
java HelloWorld
Note: Please don't specify .class extension at the command line. Here JVM loads the class written in HelloWorld.java source file and executes the main() function.
Writing First Java Program:
Source file name: HelloWorld.java
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello, World!\n");
}
}
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello, World!\n");
}
}
Few comments on the first Java Program:
- Every java program consists of one or more classes. Classes are the fundamental building blocks for java programs.
- The line, 'public class HelloWorld', denotes that the class is usable by the "public".
Note: In Java, a source file can contain multiple classes, but only one public class. It is almost like, "1 source file - 1 public class".
Also, If a source file has a public class then the source file name must match the public class name.
Every Java application contains a class with a main method. When the application starts, the instructions in the main method are executed. A class can also contain other methods as well.
The main method contains one or more instructions called statements. Each statement ends in a semicolon (;). When a program runs, the statements in the main method are executed one by one.
Note: Common error for beginners is omitted semicolon(;) at the end of each statement.
If you execute a file that does not exist, NoClassDefFoundError will occur.
If you execute a class that does not have a main method, NoSuchMethodError will occur.
When executing a java program, the JVM first loads the byte code of the class to memory using a program called the class loader. If your program uses other classes, the class loader dynamically loads them just before they are needed.
After a class is loaded, JVM uses a program called byte code verifier to check validity of the byte code.
If you execute a file that does not exist, NoClassDefFoundError will occur.
If you execute a class that does not have a main method, NoSuchMethodError will occur.
When executing a java program, the JVM first loads the byte code of the class to memory using a program called the class loader. If your program uses other classes, the class loader dynamically loads them just before they are needed.
After a class is loaded, JVM uses a program called byte code verifier to check validity of the byte code.
Errors:
2 types of errors can occur in java programs:
- Compiler errors
- A compile-time error is a violation of the programming language rules that is detected by the compiler.
- Run time errors
- A run-time error causes a program to take an action that the programmer did not intend.
- The program is syntactically correct and does something, but it doesn’t do what it is supposed to do. (Also called logical errors)
- Some kinds of run-time errors are so severe that they generate an exception: an error message from the Java virtual machine. like, divisible by zero
JVM uses big-endian encoding that is most significant bit(MSB) comes first. Comes first means, that is present at lower memory address.
No comments:
Post a Comment