0% found this document useful (0 votes)
4 views21 pages

Java Notes

Uploaded by

bc210423749ame
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
4 views21 pages

Java Notes

Uploaded by

bc210423749ame
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 21

JAVA+MYSQL

1899 -19
ROOBA AHMAD
Tech inn Solutions
SOFTWARE DEVELOPMENT
01-Mar-18

1.

Intro to java
Software:Approximately 8 billion devices work on the compiler of java. For example:
Software asLike
an editor:
oven, Sublime text
Machines, Android mobiles and etc.
Link: https://www.sublimetext.com/3/
Why we learn it?
Software as compiler: xamp

Link: https://www.apachefriends.org/index.html

Java jdk 8

Eclipse IDE: https://www.eclipse.org/ide


It is use as the competitor of c# in app dev. And also use in web dev. as the
competitor of c# and PHP.

It is both frontend and backend language.

Compiler: JDK 8

Write javac in cmd for successfully installation.

JDK stand for java dev. Kit

JDK includes compiler of java (javac), library files of java, event library file of
java.

Add path in cmd’s properties in a folder.

Extension: .java

+ sign use for concatenation.

RULES
1. Use a class with file name without extension with public key word.
2. Use main in only one file in the whole folder.
3. Extension of object code is .class.

Header files in java


Import java.io.*; use to i\o function.

Import java.util.*; use for classes

Import javax.swing.*; use for i\o in GUI

Import java.awt.*; use to show a GUI screen.


Learn code
1. Scanner myScanner = new Scanner (System.in);
2. System.out.println(“Enter a number”);
3. System.out.print(“Enter a number”);
4. JOptionPane.showInputDialog (“Enter a number”);
5. JOptionPane.showMessageDialog (null, “The number is
”+x);
6. public static void main (String [] args) {}
7. ArrayList<String> name=new ArrayList<String>();
8. human rehan= new human();
9. String[] name= new String[10];
10. JFrame frame= new JFrame(“*”); *=title
11. Container c= frame.getContentPane();
12. frame.setVisible(true);
13. JFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS
E);
14. Container c=new frame.getContentPane();
15. JButton button=new JButton("Click Me");
16. JLable label=new JLable("Enter number");
17. JTextFeild text=new JTextFeild(10);
Parts of main: public static void main (String [] args) {}

Public: it has to be public so that compiler can execute it during


compilation. Use to show to everyone.

Static: allow to use main only one time in whole folder.

Void: will return nothing.

String [] args: java main accepts a single argument of string type array.

Args is argument. You may change its name.

Basics in java:
To print hello world: System.out.println (“Hello World”);

To run a program:

Cd * * =use to enter in the folder

Javac * * =file name with extension

Java * * =use for source code without extension

Println VS print: println: works as \n or endl. & print: work without \n.

How to input in java?


First of all add the header file “import java.util.*;”before main.

Scanner myScanner = new Scanner (System.in); <- use for input method

An example of input java code:

nex
tint is use to convert string data into integer because compile always
returns data in the form of string.
2. Collection and swings
Input using JOptionPane:
Use library file javax.swing

String x= JOptionPane.showInputDialog (“Enter a number”);

JOptionPane.showMessageDialog (null, “The number is”+x);

Integer to String conversion


Int x= Integer.parseInt (JOptionPane.showInputDialog (“Enter
a number”));

Converts string to integer

Int x= Integer.parseString (JOptionPane.showInputDialog


(“Enter a no”));

Converts string to integer

Like this we can also converts float to int and so on...

ArrayList:
ArrayList is built in the library file of “java util”.

ArrayList<String> name=new ArrayList<String> ();

name.add (“Rehan”);

name.add (“Ali”);

name.add (“Asad”);

System.out.println (name.get (2));

Why we use ArrayList?


Array list is a type of array. We can change size of array anytime but in
array we can’t. Once it fixed it cannot change anytime.

Arrays in java
String [] name= new String [10];

Same as C++,

And like other languages.

Some methods for programming


Split method: x= n.split (“,”);

Size method: x=name.size (); will count the elements

2. Exception Handling
Try catch
There are some errors that are nor logical nor syntax but make
disaster during compiling known as exception errors. To prevent program
we use try catch before writing the program. Mostly we use it writing or
reading a file.to read/write a file we use library file javax.swing.

Example:

Finally is not compulsory we can execute code without it.


4. File reading:

5. File writing:

This program will convert data from one file to another file.

Finally is use to execute data in both cases for condition true or false.
Line 23 please enter file name to save);

6. Classes
Works same as c++ but we use dot (.) as-> in cpp.

And we call object in main as:

Human rehan= new human ();

Example of the code:


7. Inheritance in
java
Inheritance means to inherit with
another object, to combine the data.
Inheritance is same in java as well as in
cpp. In cpp we use as class student:
public human {} but in java we use

Full code. It will connect all the pages


automatically. But use must use public
keyword with it.
8. Phone Book Application

To make a phonebook we need


to add a file with name
“contact.java”. Write the
following code:

Public class contact {

Public String name;

Public String
number;

Public String
address;

This will save a contact


and show total contacts:

Line 11++ String address);


Some more methods
To search:

To remove:
9. Full code

What is bat file?


Write a file with extension .bat

And write following code

11. First GUI


Libraries use to make GUI “javax.swing” and “java.awt”.

Line 9: It is use to make a box contain close, minimize, maximize buttons.

Line 10: Container is use for internal box. OUTPUT:

Line 15: to show in public

Line 13: set width, height

Line 12: to close it from task manager.

Layouts:
Flow layout-> arrange automatically

Grid layout ->row columns

Relative layouts ->


Line 13: use to add a button

Line 14: to add layout

Line 15: to input

Line 16: text field with size

12. FLOW LAYOUT


This helps to show data at the bottom of button. Both are to print square

13. Grid layout


An action listener for subtraction and addition method.

14. Connecting MySQL with java


Download java MySQL connecter
 Search: java MySQL connector j downloads
Extract both files connector and eclipse ide
Now add eclipse folder in local disk c -> program files.
Who to connect MySQL with java?
 Add a source folder in package explorer and select a name for it.
 Copy MySQL connector and paste in the folder.
 Now right click on the JRE... library -> build path-> configure.
 Click on add jars.
 Select MySQL connector now click apply and close.

Line no 15++, “root”, “”);


Line no 20++, student age, student address etc.
First two lines (14, 15) helps to connect phpmyadmin and next (17, 18) help to
select DB.
And then print it.
If we want to use external entity then we have to use try catch.

15. Prepared statements


It helps us to create, read, update or delete data.
Line 13 -> Allow to connect MySQL DB

16. Java crud operation


File-> new->others->windowBuilder->swingDesigner-
>applicationWindow
Absolute layout -> allow krta hai k chezon ko apny according set kea
jay.
On any button like save right click and select add event handler ->action
->listener
Try to use everything from private
17.
16. Java crud operations

You might also like