Introduction to Java Programming / / What is Java and its types? // What is the first name of Java? //
Who introduced Java? //
It is a general-purpose, object-oriented programming language .developed by Sun Microsystems of the USA in 1991.
Originally called Oak by James Gosling We can develop two types of Java programs.
1. Standalone Application
2. Web applets
Qn: What is the full form of java?
Ans: Java doesn't have any Full form but (Quora) Java Stands for
JUST ANOTHER VIRTUAL ACCELERATION.
1 Standalone Application:
Standalone applications are programs written in Java to carry out certain tasks on a standalone local computer Java can be used to develop programs for all kinds of applications, which earlier, were developed using languages like C and C++ As pointed out earlier, HotJava itself is a Java application program Executing a standalone Java program involves two steps:(A). Compiling source code into bytecode using the javac compiler.
(B). Executing the bytecode program using java interpreter.
2.Web applets:
Applets are small Java programs. that was developed for Internet applications An applet located on a distant computer (Server) can be downloaded over the Internet and run on a local computer (Client) using a Java-compatible browser. We can develop applets for doing everything from simple animated graphics lo complex games and utilities.As if applets are embedded in an HTML(Hypertext Markup Language) document and run inside a Web page or any programming platform, creating and running applets are more complex than creating an application.
Standalone programs can read and write files and perform certain operations that applets cannot do An applet can only run within an internet browser. In this chapter, we shall consider some simple application programs, which would demonstrate the general structure of Java application programs.
We shall also discuss here the basic elements of Java language and steps involved in executing a Java application program.
• SIMPLE PROGRAM OF JAVA
If you want to learn any new language is to write a few simple example programs with very carefully and execute them. We begin with a very simple program that prints a line of text as output.Qn: java program with source code // Simple program of java // java basic program.
Program
class Simple{
public static void main(String args[])
{
System.out.println("Hello, Mr programmer");
}
}
Output:
Hello, Mr programmer
Program
Simple java program |
The output of a simple java program. |
SIMPLE PROGRAM OF JAVA is perhaps the simplest of all Java programs. Nevertheless, it brings out some salient features of the language. Let us, therefore, discuss the program line by line and understand the unique features that constitute a Java program.
• CLASS DECLARATION
The first line
class Simple
Here: class :> class is a keyword
Here: class :> class is a keyword
Simple:> Simple is an identifier.
the first character of an identifier is always capital
Declares a class, which is an object-oriented construct. As stated earlier, Java is a true object-oriented Programming Language and so that, everything must be placed inside a class. Class is a keyword and declares that a new class. And Simple is a java identifier that specified the name of the class to be defined.the first character of an identifier is always capital
• OPENING BRACE
Opening Brace in java Every class definition in Java programming begins with an opening brace "{" and ends with a closing brace ” } ”. appearing in the last line in the example. It is similar to the C++ class construct.Note:-> That a class definition in C++ ends with a semicolon.
Opening brace: {
Close brace: }
• THE MAINLINE
The third linepublic static void main (String args [])
defines a method named main, Conceptually, this is similar to the main( ) function in C/C++. Every Java application should include the main ( ) method. This is the starting point for the interpreter to being the execution of the program.
A Java application can have some number of classes but only one of them must include a main method to initiate the execution ( Note that Java applets will not use the main method at all ) This line has contained several keywords, public, static, and void.
• Public: The public keyword is an access specifier, which declares that the main method is not secure and therefore makes it accessible to all other classes. This is similar to the C ++ public switch.
• Static: Then the static keyword appears, which declares this method as one that belongs to the entire class and not as part of any object in the class, the main should always be declared as static since the interpreter uses this method before creating any object. More about the static method.
• Void: The type of modifier void states that the main method does not return any value (but simply print some text to the screen.)
All the parameters of a method are declared within a pair of parentheses. Here, String args [ ] declares a parameter called args, which contains an array of objects of the String type class.
• THE OUTPUT LINE
The only executable statement in the program isSystem.out.println(“Hello, Mr programmer”);
It is almost like the printf() statement of C or cout<< construct of C++. Since Java is a true object-oriented Programming language, every method should be part of an object. The println is a method, which is a member of the out object, which is a static data member of System class. This line prints the string.
Hello, Mr programmer
To the screen. The method println always appends a newline character to the end of the string. This means that any subsequent output will start on a new line. Note the semicolon at the end of the statement. Every java statement must end with a semicolon. (Saving, compiling, and executing a java program are discussed in Section 3.8).
COMMENTS
Java permits both the single-line comments and multi-line comments available in C++. The single-line comments begin with // and end at the end of the fine as shown on the lines declaring x and y. For longer comments, we can create long multi-line comments by starting a /* with a and ending with a */ as shown at the beginning of the program.Single line comments: // .........paragraphs.............
Multiline comments: /* .........paragraphs............. */
Example of HelloWorld
class HelloWorld{
public static void main(String args[])
{
System.out.println("HelloWord");
}
}
Output:
HelloWorld
Example of HelloWorld
Example of HelloWorld.Output |