Java Programs

 

  Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers “write once, run anywhere” (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.-wikipedia

To learn Java Programming first you must know the how java programming works and how to write,compile and execute java programs.


Working of java Programs:

  Java is computer programming language as other programming languages such as c,c++ bt what makes it diffierent from other is its javas byte code.byte code is nothing but patform independet code generated by jvm(java virtual machine).we can run this bye code on any device.When we compile any file .class file is generated by jvm for that computer.Now lets see the Structure of java File.


General Structure of java File:

package statement;
import statemet.*;
class class_name
{
public static void main(String args[])
{
}
}


How to write java code:

important rules to consider while writing java code.

  1. File name and main class name has to be same.
  2. There can be one public class per source file .
  3. If there is any package need to be used package has to be the first statement.
  4. Import statement must be between package statement and the class statement.

 Before you use java programming commands to compile,run java programs you must set path for java.To learn how to set path in java read this article how to set path in java

 


How to compile java Programming code.

javac command is used to invoke java compiler.general structure for javac command is
javac [options] [source file ]

example:
javac -help // for help

java programming

java programming

javac program.java //for compiling

java programming

java programming

when you compile any java file you will get .class file for it.


How to execute (run) java program:

java command is used to invoke JVM. Here is structure of java command
java [options] [file name] [args if any]

example:
java program //program is file name
java program 123 //123 is pass to args array

To lean how to run java applet read this article how run applet in command prompt.Beginers should use cmd to learn java programming once you get comfortable with it start using advance tools like net-beans and eclips


Simple java programs to learn java

  1. java program for prime number
  2. java program to Convert string to int
  3. java program to remove specific character from string in java
  4. java program to Swap values of two variables without using third variable
  5. java program for Fibonacci series
  6. java program to check palindrome
  7. java program to check armstrong number
  8. java program for pascal triangle
  9. java program for Merge Sort
  10. java program for Heap Sort
  11. java program for insertion Sort
  12. java program for Quick Sort
  13. java program for Selection Sort
  14. java program for Bubble Sort
  15. java program for Binary search
  16. java program for Linear search