Wednesday 26 July 2017

JAVA


Download a compiler in Java:

Open google and download Java compiler for windows.
 Click on Java JDK platform.
Click on Accept License Agreement and download jdk windows 64 bit.
After we can see in downloads folder.
Now right click and open jdk folder and install it.
After open My computer and open c drive we can see program files folder and open we can see in that java has been installed.




Open java folder we can see jdk and jre files.
Open jdk we can see bin folder.
Click on bin we can see the address and copy that.
How to set path in java:
Right click on MyComputer - properties.
Click on advanced system settings.
Click on Environment Variables.
Create new to set path.
It will ask to enter variable name and path enter name and paste the address we have copied before till bin folder.
Click on ok.
Setting path is completed.
Open start menu and enter command prompt (or) windows + R button run opens enter cmd.
Command prompt opened we can check whether java is running or not.
Why java:
We write the program in English language which we can understand but JVM cant understand.
Java compiler will convert our English language program to byte which JVM can understand.
Once we compile our java program it will generate .class file with class name which has byte code.
Why we write a program:
To execute it right for that we have to use Java ClassName
Successfully java is running.
We have to check whether javac is running or not. Successfully javac is also running.
javac for compiling the program.
HelloWorld program:
Data Types:

                             
Variable initiation:
Used to declare a variable.
Variable is a piece of memory that contains data.
We can see the error that variable is not initialised.
To avoid this error we have to initialize a variable.
Syntax for variable initiation:
Eg:
int number = 10;
Different variables:
Local variables:
Declared inside a method, can be accessible within the same method.
Class variables:
Static variables declared inside a class.
Instance variables:
Non-static variables declared inside a class.
Eg:
class A {
int data = 50; //instance variable
static int m = 100; //static variable
void method() {
int n = 90; //local variable
}
}
Loops:
Particular block which will execute a set of statements till the block is true.
Different kinds:
For:
Executes for certain number of iterations.
Syntax:
for(initialization; condition; increment / decrement)
{
 statements
}
Eg:
While:
Executes till the condition false, there is no fixed number of iterations.
Syntax:
while(condition)
{
statements
increment / decrement
}
Eg:
Do-While:
Executes at least once, then it will check for the condition.
Syntax:
do {
statements
increment / decrement
}(condition);
Eg:
Conditional statements:
If statement:
Syntax:
if(condition) {
//code to be executed
}
Eg:
If else statement:
Syntax:
if(condition) {
//code if condition is true
}
else {
//code if condition is false
}
Eg:
If else if ladder statement:
Syntax:
if(condition1) {
//code if it is true
}
else if(condition2) {
//code executes if it is true
}
else if(condition3) {
//code executes if it is true
}
...
else {
//code executes if it is false
} 
Eg:
Switch:
Syntax:
switch(expression) {
case value1: 
//code;
break;
case value2:
//code;
break;
....
default:
code executes if all cases are not matched;
}
Eg:
Loop control statements:
Break:
Syntax:
jump-statement;
break;

Continue:
Syntax:
jump-statement;
continue;

Add two strings:
String concatenation forms a new string that is combination of multiple strings.
2 ways:
String concatenation (+) operator.
Concat() method.
Partial string:
A part of string is called substring.
Index starts from 0.
Start index is inclusive and end index is exclusive.
Eg: hello
string s="hello";
System.out.println(s.substring(0,2));
output: he
0 points to h and 2 points to l but end index is exclusive.
Eg:
Find starting point for a string:
Read from user input and write to user output syntax:
Count the number of occurences of a substring in a string:
Read from a file and write to a file:
Reading a file:
Create a sample text in notepad and save it with .txt extension.
Enter some text in it and save it.
While writing in a program we have to specify the particular path where we have stored it.
Now, in output we can see the entered text it reads from a file.
Writing a file:
While writing a program set the path and enter a filename with .txt extension.
After compiling and executing the program we can see the success message and file will be created in our specified location.
We can see in E drive because i specified the location as E drive in my program so .txt will be created.
Now, open the example1.txt file we can see the message which is file writer.
Replace Ravi with Chandu:
Graphic output syntax:
Draw a Line:
Draw a Circle:
Draw a Rectangle:
Draw a Star:
First non repeated character in a given string:
Permutation of a string:
Digit identification if string have any numbers:
Program to print the following pattern:
Program to sum a number in given string:
Database connection:
To connect to a database we have to install mysql installer.
Click on download.
Just click on start my download.
After that we can see it has been successfully downloaded and right click and click on show in folder.
We can see in downloads folder now right click on it and click on install. 
We can see it is configuring to install.
Click on accept and next.
Here we have to choose and the button and click on next.
Click on next to continue.
Installation is ready to install then click on execute.
After that it is execute then we can see our status as complete then click on next.
Click on next to continue configuration.
Click on next to continue.
Next to continue.
Here it will ask to specify the password for mysql. Then click on next.
Click on next to continue.
We can see portnumber and click next to continue.
Click on execute.
Now, configuration steps are installing after configuring click on finish.
Click on next to continue.
Click on finish to continue.
Click on next step.
We can see that it is a server and before we specified user name and password that we can see here and click on check to continue.
After clicking on check we can see connection successful and click on next to continue.
Click on execute to continue.
Click on finish.
Now again in product configuration we can see click on next to continue.
Installation complete then click on finish.
After successfully installing we can see MySQL commandline will be opened.
In start button click on mysql commandline and open it.
Enter password as root and we can see it is successfully running mysql in your command line.
Now, write a program to establish connection to database.
It is telling that class not found exception and no driver installed.
Now, download sql driver connector.
Download Tarfile.
Click on just start my download.
After downloading we can see tar file is downloaded and right click on it and click on show in folder.
We can see in downloads.
Now, go to file and paste in it.
We can see my sqlconnector jar file has copied.
Now, right click on it we can see build path and configure buildpath.
In libraries add jars.
Successfully added.
In order and export select it and click on apply.
This is our program to connect to database.
But still we are getting error.
We have to create database and we have to specify that name.
We can see connection successfull to database.