Java Projects
How to Run Java Projects
Step:1 |
Step:2 |
Step:3 |
Step:4 |
Step:5 |
Step:6 |
Step:7 |
Step:8 |
- Go to Program files–>Apache Software Foundation–>Apache–>root or www .
- Put all files in this folder of you website or project .
- Now you can directly run all these files through browser .
- Just go to your browser and Type : Localhost:8080/Home.html
Online Chat Java Project
First Program in Java
public class FirstProgram {
public static void main( String [] args )
{
System.out.print (“Java Program”);
System.out.print (“My Program”);
}
}
C:\ javac FirstProgram.java
C:\java FirstProgram
Java Program My Program
public class FirstProgram {
public static void main( String [] args )
{
System.out.print (“Java Program”);
System.out.println (“My Program”);
}
}
C:\ javac FirstProgram.java
C:\java FirstProgram
Java Program
My Program
What is the difference between an interpreter and a compiler?
Define Class and Object?
What are different Java programs.
Public and Private Keywords
Determines how the other parts of the program can access the members of the class.
When a class member is preceded by public, then that member can be access by code outside the class in which it is declared.
The opposite of public is private.
Prevents a member from being used by code defined outside of its class.
In our program, main() must be declared as public since it must be called by code outside of its class when the program is started.
The keyword static allows main() to be called before an object of the class has been created.
This is necessary since main() is called before an object of the class has been created.
The keyword void tells the compiler that main() does not return a value.
Methods may also return values.
As stated, main() is the method called when a Java application begins.
Any information that you need to pass to a method is received by variables specified within the set of parentheses that follow the name of the method.
These variables are called parameters.
If no parameters are required for a given method, you still need to include the empty parentheses.
The next line
System.out.println (“Java Language”);
Outputs the string “Java Language” followed by a new line on the screen.
Output is accomplished by the built-in println( ) method.
println( ) displays the string which is passed to it. println( ) can be used to display other types of information as well.
The line begins with System.out.
System is a pre-defined class that provides access to the system out is the output stream that is connected to the console.
System.out is an object that encapsulates console output.
Console input and output is not used frequently in real-world Java programs and applets. Since most application are windowed and graphical in nature, console I/O is used for simple utility programs and demonstration programs.
All statements in Java end with a semicolon.
Notice that the println( ) statement ends with a semicolon.
Java is case sensitive.
If you accidentally type Main instead of main, the program will be incorrect.
Although the Java compiler will compile classes that do not contain a main() method, it has no way to execute them.
Java Programs
Downloaded with the Web page and launched by the Internet browser
Servlets
Run by Web server on the server
Typically generate Web content
Applications
Programs that run standalone on a client
Write the source code
- Using an Integrated Development Environment (IDE) or text editor. Save in a .java file
- Creates .class file
- Run by the Java Virtual Machine
Sample Program
// FirstProgram.java
public class FirstProgram {
public static void main( String [] args )
{
System.out.println (“Java Program”);
}
}
C:\ javac FirstProgram.java
C:\java FirstProgram
Java Program
The first line of the program uses the keyword class to declare that a new class is being defined.
A class is Java’s basic unit of encapsulation.
FirstProgram is the name of the class.
The class definition begins with an opening curly brace { and ends with a closing curly brace }
All program activity occurs within a class.
The next line of the program begins the main() method.
This is the line at which the program will begin executing.
All Java applications begin execution by calling main(). Just like C and C++
Statements and expressions are similar to those in other languages, and in most cases, identical to those of C or C++.