What is Java?
Java is a high level programming language, which is developed by Sun Micro-systems and released in 1995.
Java is a object oriented programming language which consists of classes and objects.
Java is a platform independent language which helps to write once and run wherever.
Java is a platform independent language which helps to write once and run wherever.
Environment Setup
Download Java compiler:
Install the downloaded file.
Adding Environment Variable
Go to Control Panel:
Check whether Java installed properly from command line.
Set and save the notepad file in proper path
While executing we have to go to complete path call file.
Compiling a Java program from command line
Running a Java Program from command line
Writing a Basic Java Program
Step1: Write Program in Notepad and save in specified folder to identify. The class name and file name should same.
Step2: Compile the program
Step3: Run the program
Variable Declaration
- Variable is a memory pointer declared to store some value.
- It can be any name given but should not exceed 32 charecters.
- Should start with character or underscore(_).
Syntax: Datatype Variable_Name;
Defining a Class
Class is a blue print and logical representation of object.
Syntax to define class: Class Class_Name
{
// Class members
}
Constructor
Declaring an Object Syntax to define object: Class_Name object_name= new Class_Name();
Program to specify usage of Class and Object.
Accessing Instance Variables and Methods
Looping statements are : for(), while(), dowhile(), goto().
Class is a blue print and logical representation of object.
Object is a physical representation of class. Takes all the members from class.
{
// Class members
}
Constructor
Program to specify usage of Class and Object.
Conditional Statements
1. if() statement:
1. if() statement:
Looping Statements
Looping statements are used to iterate a block of statements until a specified condition becomes true.
Iteration is an execution of block of statements for one time. When a sequence of instructions is executed in a repeated manner until condition becomes false, it is called a loop.
1. for() loop:
For statement is used whenever the number of iterations are fixed or known.
Syntax: for(expression1;expression1;expression1)
{
//block of statements
}
2. While() loop:
Syntax: While(Condition)
{
//block of statements
}
String Manipulation
1. Reading and displaying a string
2. String Concatenation
3. Length of a String ( length() function):
3. Searching a String ( indexOf() function):
4. Substrings ( substring() ):
Substring is a string function used to search and return a string based on index.
Syntax: string.substring( Starting_index, Ending_index)
File Handling
Example to Parse Menu
Program:
File Input Given
Output
Output Generated
0 comments: