Java Programming Basics and Applications
Java Programming Basics and Applications
Java Application :
-Desktop software application
-web Application
-mobile Application
-Embedded & IOT Application
-Games
Software needed:
-Eclipse IDE
-OracleDB
package myprogram;
-----------------------------
Fundamentals of Java:
Data types:
[Link] data type:
char
char a='Z';
package myprogram;
[Link](a);
}
int:
float:decimal value
5.09
double:decimal value
3.9865335
boolean:
t or f
bytes
package myprogram;
[Link](a);
[Link](mark);
[Link](z);
[Link](d);
[Link](b);
}
----------------------------------
[Link](livewire[0]);
[Link](livewire[1]);
--------------------------------------------
string:
collection of char
package myprogram;
public class Hello {
[Link](college);
}
}
-----------------------------------------
Variable:storage location
int a=10;
char b='Z';
------------------------------------------
Keywords:
-Reserved words or pre-defined words
-abstract
-boolean
-char
-int
-class
-float
-else
-if
-final
-for
.......................
Operators:
-operations
+,-,*,/,%,++,--
package myprogram;
[Link] or compare:
==,!=,>,>=,<,<=
package myprogram;
}
-------------------------------------------
[Link]
=,+=,-=,*=,/=
package myprogram;
int priyanka=10;
priyanka += 5;
priyanka -=3;
priyanka *= 2;
[Link]("Output is:"+ (priyanka));
}
--------------------------------------------
[Link] :
and &&
or||
not !
package myprogram;
int a=10;
boolean z=(a >5 && a<=9);
[Link]("Output is:"+ (z));
-----------------------
[Link]
----------------------------
Comment line:
// - single line comment
package myprogram;
//int a=10;
//boolean z=(a >5 && a<=9);
//[Link]("Output is:"+ (z));
}
--------------------------------
package myprogram;
/*int a=10;
boolean z=(a >5 && a<=9);
[Link]("Output is:"+ (a));*/
}
----------------------
OOPs with Java:
class:
object:
package myprogram;
[Link](obj.a);
}
---------------------------------
package myprogram;
[Link](obj.c);
------------------------------------------
inheritance:
package myprogram;
String food="Doza";
package myprogram;
-----------------------------------------------------
3 type:
-single inheritance:
A----------B
package myprogram;
package myprogram;
-----------------------------------
-multi-level:
A-------B--------------C
package myprogram;
void eat() {
[Link]("eat well");
}
package myprogram;
package myprogram;
------------------------------------------------
-hierarchical:
------------------------------
polymorphism:
[Link] overloading:
package myprogram;
[Link] overriding
package myprogram;
package myprogram;
}
-----------------------------------------------------
abtract class:
package myprogram;
package myprogram;
------------------------------------
interface:
package myprogram;
package myprogram;
------------------------------------------
GUI - Graphical User Interface
Button:
package myprogram;
import [Link].*;
public class Desktopgui extends Frame{
Desktopgui(){
Button b=new Button("submit");
[Link](30, 100, 100, 30);
add(b);
setSize(400,400);
setTitle("GUI");
setLayout(null);
setVisible(true);
}
public static void main(String[] args) {
Desktopgui obj=new Desktopgui();
--------------------------------------------
Label:
package myprogram;
import [Link].*;
public class Desktopgui extends Frame{
Desktopgui(){
setSize(400,400);
setTitle("GUI");
setLayout(null);
setVisible(true);
}
public static void main(String[] args) {
Desktopgui obj=new Desktopgui();
}
---------------------------------------------------------------
check box:
package myprogram;
import [Link].*;
public class Desktopgui extends Frame{
Desktopgui(){
setSize(400,400);
setTitle("GUI");
setLayout(null);
setVisible(true);
}
public static void main(String[] args) {
Desktopgui obj=new Desktopgui();
------------------------------------------------------------------
Text Field:
package myprogram;
import [Link].*;
public class Desktopgui extends Frame{
Desktopgui(){
setSize(400,400);
setTitle("GUI");
setLayout(null);
setVisible(true);
}
public static void main(String[] args) {
Desktopgui obj=new Desktopgui();
-----------------------------------------------------------
Text Area:
package myprogram;
import [Link].*;
public class Desktopgui extends Frame{
Desktopgui(){
setSize(400,400);
setTitle("GUI");
setLayout(null);
setVisible(true);
}
public static void main(String[] args) {
Desktopgui obj=new Desktopgui();
-------------------------------------------------------
Action Event:
package myprogram;
import [Link].*;
import [Link].*;
public class Desktopgui extends Frame implements ActionListener{
TextField tf1,tf2,tf3;
Button b1;
Desktopgui(){
tf1=new TextField();
[Link](50, 50, 150, 20);
tf2=new TextField();
[Link](50, 100, 150, 20);
tf3=new TextField();
[Link](50, 150, 150, 20);
b1=new Button("Add");
[Link](50, 200, 50, 50);
[Link](this);
add(tf1);
add(tf2);
add(tf3);
add(b1);
setSize(400,400);
setTitle("GUI");
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String s1=[Link]();
String s2=[Link]();
int a=[Link](s1);
int b=[Link](s2);
int c=0;
if([Link]()==b1) {
c=a+b;
}
String rezult=[Link](c);
[Link](rezult);
}
public static void main(String[] args) {
Desktopgui obj=new Desktopgui();
}
-----------------------------------------------------------
package myprogram;
import [Link].*;
import [Link].*;
public class Desktopgui extends Frame {
Desktopgui(){
Checkbox c=new Checkbox("Java");
[Link](100, 100, 150, 30);
add(c);
setSize(400,400);
setTitle("GUI");
setLayout(null);
setVisible(true);
[Link](new ItemListener() {
public void itemStateChanged(ItemEvent e) {
[Link]("Java is object oriented programming");
}
});
}
public static void main(String[] args) {
Desktopgui obj=new Desktopgui();
}
---------------------------------------------
Jswing - Java Swing
Button
package myprogram;
import [Link].*;
}
-----------------------------------
package myprogram;
import [Link].*;
public class Desktopgui extends JFrame {
Desktopgui(){
setSize(400,400);
setLayout(null);
setVisible(true);
}
----------------------------------------
package myprogram;
import [Link].*;
setSize(400,400);
setLayout(null);
setVisible(true);
}
-------------------------------------------------------
package myprogram;
import [Link].*;
setSize(400,400);
setLayout(null);
setVisible(true);
}
---------------------------------------------
package myprogram;
import [Link].*;
import [Link].*;
public class Desktopgui extends JFrame implements ActionListener {
Desktopgui(){
});
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
--------------------------------------------------------
package myprogram;
import [Link].*;
import [Link].*;
public class Desktopgui extends JFrame {
Desktopgui(){
String country[]= {"India","UK","Canada","Brazil","US"};
JComboBox c=new JComboBox(country);
[Link](50, 50, 90, 30);
JLabel l=new JLabel();
[Link](200, 100, 475, 30);
@Override
public void actionPerformed(ActionEvent e) {
String data="You have
selected :"+[Link]([Link]());
[Link](data);
});
}
}
----------------------------------------------
package myprogram;
import [Link].*;
import [Link].*;
public class Desktopgui extends JFrame {
Desktopgui(){
String column[]= {"Name","Email","mobile"};
String row[][]= {{"Priyanka","priyanka@[Link]","9876543451"},
{"Ajay","ajay@[Link]","9898989898"},
{"Divya","divya@[Link]","9876545678"}};
JTable t=new JTable(row,column);
[Link](50, 40, 300, 300);
JScrollPane z=new JScrollPane(t);
add(z);
setSize(600,600);
setVisible(true);
}
----------------------------------------
package myprogram;
import [Link].*;
import [Link].*;
public class Desktopgui extends JFrame {
Desktopgui(){
DefaultListModel<String> l=new DefaultListModel<>();
[Link]("Priyanka");
[Link]("Bala");
[Link]("Nivetha");
[Link]("ajay");
[Link](100,100,100,100);
add(list);
setSize(600,600);
setLayout(null);
setVisible(true);
}
--------------------------------------------
project:
package anup;
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link].*;
import [Link];
JFileChooser f1;
// Default constructor to
// initialize the parameters
fee()
{
l2 = new JLabel(
"Name of the Student:");
[Link](50, 150, 250, 20);
l3 = new JLabel(
"Name of the Father:");
[Link](50, 200, 250, 20);
l7 = new JLabel("Address:");
[Link](50, 400, 250, 20);
l9 = new JLabel("Gender:");
[Link](50, 500, 250, 20);
JRadioButton r5
= new JRadioButton(" Male");
JRadioButton r6
= new JRadioButton(" Female");
String language[]
= { "2016", "2015", "2014" };
String languagess[]
= { "2019", "2018", "2017","2016" };
[Link](rb1);
[Link](rb2);
String languages[]
= { "CSE", "ECE", "EEE",
"CIVIL", "MECH" };
final JComboBox cb
= new JComboBox(languages);
[Link](800, 200, 90, 20);
DefaultListModel<String> li2
= new DefaultListModel<>();
[Link](
"2 SHARE(1, 50, 000)");
[Link](
"3 SHARE(1, 40, 000)");
[Link](
"5 SHARE(1, 20, 000)");
[Link](
"8 SHARE(1, 10, 000)");
[Link](
"bus(40, 000)");
add(l1);
add(l2);
add(l3);
add(l4);
add(l5);
add(l6);
add(l7);
add(l8);
add(l9);
add(l10);
add(l11);
add(l12);
add(l13);
add(l14);
add(tf1);
add(tf2);
add(tf3);
add(tf4);
add(tf5);
add(tf6);
add(tf7);
add(tf8);
add(area1);
add(area2);
add(l15);
add(rb1);
add(rb2);
add(rb3);
add(rb4);
add(r5);
add(r6);
add(cb);
add(cb1);
add(cb2);
add(list1);
add(list2);
add(b);
add(label);
add(Receipt);
add(b2);
add(Print);
[Link](new ActionListener() {
[Link](
"--------------------------------"
+ "-----------FEE RECEIPT----"
+ "--------------------------"
+ "--------------------------"
+ "-------------------\n");
[Link]([Link]()
+ "Student Name: "
+ [Link]()
+ "\n");
[Link]([Link]()
+ "Father's Name: "
+ [Link]()
+ "\n");
[Link]([Link]()
+ "RollNumber: "
+ [Link]()
+ "\n");
[Link]([Link]()
+ "Email ID: "
+ [Link]()
+ "\n");
[Link]([Link]()
+ "Contact Number: "
+ [Link]()
+ "\n");
[Link]([Link]()
+ "Wants to take: "
+ [Link]()
.toString()
+ "\n");
if ([Link]()) {
[Link]([Link]()
+ "Wants to Join in "
+ "School of Engineering "
+ "and Applied Sciences\n");
}
if ([Link]()) {
[Link]([Link]()
+ "Wants to Join in "
+ "School of Liberal "
+ "Arts and Sciences\n");
}
if ([Link]()) {
[Link]([Link]()
+ "Wants to be a "
+ "Hosteller \n");
}
if ([Link]()) {
[Link]([Link]()
+ "Wants to be a "
+ "Day Scholar \n");
}
[Link]([Link]()
+ "Had chosen: "
+ [Link]()
.toString()
+ "\n");
[Link]([Link]()
+ "Had chosen: "
+ [Link]()
.toString()
+ "\n");
if (index2 == 1) {
[Link]([Link]()
+ " "
+ "Total amount to be paid "
+ "is 3.9 Lakhs \n");
}
if (index2 == 2) {
[Link]([Link]()
+ " "
+ "Total amount to be paid "
+ "is 3.8 Lakhs \n");
}
if (index2 == 3) {
[Link]([Link]()
+ " "
+ "Total amount to be paid "
+ "is 3.7 Lakhs \n");
}
if (index2 == 4) {
[Link]([Link]()
+ " "
+ "Total amount to be paid "
+ "is 2.9 Lakhs \n");
}
if ([Link]() == Receipt) {
try {
FileWriter fw
= new FileWriter(
"[Link]", true);
[Link]([Link]());
[Link]();
}
catch (Exception ae) {
[Link](ae);
}
}
[Link](
area2, "DATA SAVED SUCCESSFULLY");
};
});
addWindowListener(
new WindowAdapter() {
public void windowClosing(
WindowEvent we)
{
[Link](0);
}
});
setSize(1000, 1000);
setLayout(null);
setVisible(true);
setBackground([Link]);
}
public static void main(String[] args)
{
new fee();
}
}
------------------------------------------------------
Layout Managers:
Border Layout:
package myprogram;
import [Link].*;
import [Link].*;
public class Layoutt extends JFrame {
Layoutt(){
JButton b=new JButton("East");
JButton b1=new JButton("West");
JButton b2=new JButton("North");
JButton b3=new JButton("South");
add(b,[Link]);
add(b1,[Link]);
add(b2,[Link]);
add(b3,[Link]);
setSize(400,400);
setVisible(true);
}
public static void main(String[] args) {
new Layoutt();
}
-------------------------------------------------------
Grid:
package myprogram;
import [Link].*;
import [Link].*;
public class Layoutt extends JFrame {
Layoutt(){
JButton b=new JButton("East");
JButton b1=new JButton("West");
JButton b2=new JButton("North");
JButton b3=new JButton("South");
JButton b4=new JButton("Add");
JButton b5=new JButton("sub");
JButton b6=new JButton("mul");
JButton b7=new JButton("div");
JButton b8=new JButton("click");
add(b);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
setLayout(new GridLayout(3,3));
setSize(400,400);
setVisible(true);
}
public static void main(String[] args) {
new Layoutt();
----------------------------------------------------------
flow layout:
package myprogram;
import [Link].*;
import [Link].*;
public class Layoutt extends JFrame {
Layoutt(){
JButton b=new JButton("East");
JButton b1=new JButton("West");
JButton b2=new JButton("North");
JButton b3=new JButton("South");
JButton b4=new JButton("Add");
JButton b5=new JButton("sub");
JButton b6=new JButton("mul");
JButton b7=new JButton("div");
JButton b8=new JButton("click");
add(b);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
setLayout(new FlowLayout());
setSize(400,400);
setVisible(true);
}
public static void main(String[] args) {
new Layoutt();
}
-------------------------------------------------
box Layout:
package myprogram;
import [Link].*;
import [Link].*;
public class Layoutt extends Frame {
Layoutt(){
JButton b=new JButton("East");
JButton b1=new JButton("West");
JButton b2=new JButton("North");
JButton b3=new JButton("South");
JButton b4=new JButton("Add");
JButton b5=new JButton("sub");
JButton b6=new JButton("mul");
JButton b7=new JButton("div");
JButton b8=new JButton("click");
add(b);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
setSize(400,400);
setVisible(true);
}
public static void main(String[] args) {
new Layoutt();
-------------------------------------
card layout:
package myprogram;
import [Link].*;
import [Link].*;
public class Layoutt extends JFrame {
Layoutt(){
JButton b=new JButton("East");
add(b);
setLayout(new CardLayout());
setSize(400,400);
setVisible(true);
}
public static void main(String[] args) {
new Layoutt();
------------------------------------------------------
package myprogram;
import [Link].*;
public class Layoutt {
-----------------------------------------------------------
Linked listt:
package myprogram;
import [Link].*;
public class Layoutt {
Iterator itr=[Link]();
while([Link]()) {
[Link]([Link]());
}
----------------------------------------------
package myprogram;
import [Link].*;
public class Layoutt {
Iterator itr=[Link]();
while([Link]()) {
[Link]([Link]());
}
---------------------------------------
priority queue:
package myprogram;
import [Link].*;
public class Layoutt {
Iterator itr=[Link]();
while([Link]()) {
[Link]([Link]());
}
----------------------------------
map interface:
package myprogram;
import [Link].*;
public class Layoutt {
for([Link] m:[Link]()) {
[Link]([Link]()+" "+[Link]());
}
}
---------------------------------------------
Enum:
package myprogram;
import [Link].*;
enum day{
sunday,monday,tuesday,wednesday,thursday,friday,saturday
}
public class Layoutt {
Iterator itr=[Link]();
while([Link]()) {
[Link]([Link]());
}
}
}
----------------------------
package myprogram;
import [Link].*;
[Link](z);
String y=[Link]();
[Link](y);
--------------------------------------
package myprogram;
import [Link];
}
-----------------------------------------
package myprogram;
try:
catch:
package myprogram;
}
public static void main(String args[]) {
Age(15);
}
}
---------------------------------
finally:
package myprogram;
----------------------------------------------
Serialization and Deserialization in Java
package myprogram;
import [Link];
}
}
package myprogram;
import [Link].*;
}
catch(Exception e){
[Link](e);
}
--------------------------------------
Deserialization :
package myprogram;
import [Link].*;
[Link]([Link]+" "+[Link]);
[Link]();
}
catch(Exception e){
[Link](e);
}
}
---------------------------------------
Java Heap Memory and Stack Memory:
---------------------------------------
Java Networking:
package anup;
import [Link].*;
import [Link].*;
public class MyClient {
package anup;
import [Link].*;
import [Link].*;
------------------------------------------
I/O streams:
package myprogram;
import [Link].*;
}
}
package myprogram;
import [Link].*;
[Link]();
}catch(Exception e) {
[Link](e);
}
}
}
-----------------------------------------------------------------------
Database Introduction:
Oracle DB:
1. configuration
2. JDBC
package anup;
-------------------------------
import [Link].*;
class Login
{
public static void main(String[] args) throws
SQLException ,ClassNotFoundException
{
[Link]("[Link]");
Connection con =
[Link]("jdbc:oracle:thin:@localhost:1521:xe", "REACT",
"react");
Statement st = [Link]();
[Link]( "Create Table Amazon( Id varchar2(10),Name varchar2(20),Location
varchar2(20))" );
[Link]("Table is created");
}
}
------------------------------
package anup;
import [Link].*;
class Login
{
public static void main(String[] args) throws SQLException,
ClassNotFoundException
{
[Link]("[Link]");
Connection con =
[Link]("jdbc:oracle:thin:@localhost:1521:xe", "REACT",
"react");
Statement st = [Link]();
[Link]("Insert into Amazon values('E101','Bala','Chennai')");
[Link]("Insert into Amazon values('E102','David','Kerala')");
[Link]("Insert into Amazon values('E103','Jagan','Bangalore')");
[Link]("Insert into Amazon values('E104','Mohan','Andhra')");
[Link]("Details are inserted");
}
}
-------------------------------------------
package anup;
import [Link].*;
class Login
{
public static void main(String[] args) throws
SQLException,ClassNotFoundException
{
[Link]("[Link]");
Connection con =
[Link]("jdbc:oracle:thin:@localhost:1521:xe", "REACT",
"react");
Statement st = [Link]();
[Link]("Update Amazon Set Location = 'Mumbai' where name =
'David'");
[Link]("Details are updated");
}
}
-----------------------------------------
package anup;
import [Link].*;
class Login
{
public static void main(String[] args) throws
SQLException,ClassNotFoundException
{
[Link]("[Link]");
Connection con =
[Link]("jdbc:oracle:thin:@localhost:1521:xe", "REACT",
"react");
Statement st = [Link]();
[Link]("Delete from Amazon where Id='E103'");
[Link]("Data is deleted");
}
}
----------------------------------------------
package anup;
import [Link].*;
class Login
{
public static void main(String[] args) throws
SQLException,ClassNotFoundException
{
[Link]("[Link]");
Connection con =
[Link]("jdbc:oracle:thin:@localhost:1521:xe", "REACT",
"react");
Statement st = [Link]();
int z;
z=[Link]("select * from Amazon");
[Link]("ID:"+z);
}
}
----------------------------------------
Internationalization:
package anup;
import [Link].*;
}
----------------------
package anup;
import [Link].*;
}
-----------------------------------------
Date:
package anup;
import [Link].*;
import [Link];
}
-----------------------------------------------------------------
package anup;
import [Link].*;
import [Link];
}
----------------------------------------------
package anup;
import [Link].*;
import [Link];
}
--------------------------------------------