Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
Empty file added README
Empty file.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# JavaProgrammingA2Z
Source codes for the book Java Programming A2Z by Dr. Mokter Hossain
14 changes: 0 additions & 14 deletions src/JavaBook1Codes/J02_00.java

This file was deleted.

15 changes: 15 additions & 0 deletions src/chapter00/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package chapter00;

/* 1. */ /* HelloWorld.java */
/* 2. */ /* A Sample Java Application Program */

/* 3. */ public class HelloWorld {

/* 5. */ public static void main(String args[])
/* 6. */ {
/* 7. */ System.out.println("Hello World!");
/* 8. */ System.out.print("Welcome to Java Programming");
/* 9. */ System.out.print("\nThis is my First Java Program");
/* 10.*/ } // End of main()

/* 11.*/} // End of class
36 changes: 36 additions & 0 deletions src/chapter00/MonthDayCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package chapter00;
/**
* MonthDayCalculator.java
*/
import java.io.File;
import java.io.IOException;
import java.util.Random;
public class MonthDayCalculator {
public static void main(String[] args) throws IOException {
// int yearNum = 0;
Random randomNumY = new Random();
int yearNum = randomNumY.nextInt(10001);
int numDays = 0;
Random randomNumM = new Random();
int monthNum = randomNumM.nextInt(13);

switch (monthNum) {
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
numDays = 31; break;
case 4: case 6: case 9: case 11:
numDays = 30; break;
case 2:
if (((yearNum % 4 == 0) && !(yearNum % 100 == 0))||(yearNum % 400 == 0))
numDays = 29;
else
numDays = 28;
break;
default:
System.out.println("Oops!! Invalid month, please run again.");
break;

}

System.out.println("In year " + yearNum + " month #"+ monthNum + " has/had " + numDays + " days");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter02;

/* 1. */ /* J02_01.java */
/* 2. */ /* A Sample Java Application Program */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter02;

public class J02_02 {

Expand Down
Binary file added src/chapter02/J02_03.class
Binary file not shown.
8 changes: 4 additions & 4 deletions src/JavaBook1Codes/J02_03.java → src/chapter02/J02_03.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package JavaBook1Codes;
package chapter02;
/* J02_03.java */
/* A Command Line Argumented Program */

class J02_03{
public class J02_03{

public static void main (String args[])
{
public static void main (String[] args )
{
int i, c;
String S;
c = args.length;
Expand Down
18 changes: 18 additions & 0 deletions src/chapter03/BooleanEx1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package chapter03;
/* BooleanEx1.java */
/* Working with boolean type Variable */
public class BooleanEx1{
public static void main(String args[]) {
boolean x, y;
x = true; y = false;
System.out.println("x= " +x);
System.out.println("y= " +y);

int x1, y1; boolean z1;
x1 = 15; y1 = 10;
System.out.println("x1>y1 is " +(x1>y1));
z1 = y1>x1;
System.out.println("y1>x1 is " +z1);

}
}
14 changes: 14 additions & 0 deletions src/chapter03/ByteEx1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package chapter03;
/* ByteEx1.java */
/* ERROR IN RUNNING */
public class ByteEx1{
public static void main(String args[]) {
//byte Value1 = 1000; // Illegal Assigning
//short Value2 = 100000; // Illegal Assigning
byte Value1 = 100; // Legal Assigning
short Value2 = 1000; // Legal Assigning

System.out.println("Value1: " +Value1);
System.out.println("Value2: " +Value2);
}
}
10 changes: 10 additions & 0 deletions src/chapter03/CharEx1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package chapter03;
/* CharEx1.java */
/* Assigning value to character variables */
public class CharEx1{
public static void main(String args[]) {
char Ch1 = 65, Ch2= 'A';
System.out.println("Ch1: " +Ch1);
System.out.println("Ch2: " +Ch2);
}
}
17 changes: 17 additions & 0 deletions src/chapter03/DoubleEx1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package chapter03;
/* DoubleEx1.java */
/* ERROR IN RUNNING */
public class DoubleEx1{
public static void main(String args[]) {
float Value1, Value2, Sum;
// Value1 = 3.123456789; // Illegal
// Value2 = 350.0; // Illegal
Value1 = 3.123456789f; // Legal
Value2 = 350.0f; // Legal

Sum = Value1 + Value2;
System.out.println("Value1 = " +Value1);
System.out.println("Value2 = " +Value2);
System.out.println("Sum = " +Sum);
}
}
31 changes: 31 additions & 0 deletions src/chapter03/InputStreamReaderEx1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package chapter03;
/* InputStreamReaderEx1.java */
/* Converting String Object to Corresponding Wrapper Class Objct using valueOf() Method */
import java.io.*;
public class InputStreamReaderEx1{
public static void main(String args[]) {
Integer Roll; // Roll is wrapper class object
String Name;
Float Mark; // Mark is wrapper class object
String S1, S2;
InputStreamReader IN = new InputStreamReader(System.in);
BufferedReader BR = new BufferedReader (IN);
try{
System.out.print("Enter Roll: ");
S1 = BR.readLine();
Roll = Integer.valueOf(S1);
System.out.print("Enter Name: ");
Name = BR.readLine();
System.out.print("Enter Mark: ");
S2 = BR.readLine();
Mark = Float.valueOf(S2);
System.out.println("Roll is : " +Roll);
System.out.println("Name is : " +Name);
System.out.println("Mark is : " +Mark);
}
catch(Exception e)
{
System.out.println("Exception No: " +e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

public class J03_01 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

public class J03_02 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

public class J03_03 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

public class J03_04 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

public class J03_05 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

public class J03_08 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

public class J03_09 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

public class J03_10 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

public class J03_12 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

public class J03_13 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

public class J03_14 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

public class J03_15 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

public class J03_16 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

public class J03_17 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;
//import java.io.DataInputStream;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;


import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

import java.io.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

import java.io.IOException;
import java.util.Scanner;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package JavaBook1Codes;
package chapter03;

import java.io.IOException;
import java.util.Scanner;
Expand Down
14 changes: 14 additions & 0 deletions src/chapter03/LongEx1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package chapter03;
/* LongEx1.java */
/* Using long type Variable */
public class LongEx1{
public static void main(String args[]) {
long Year = 10;
long LightSpeed = 186000;
long Distance;
Distance = Year*365*24*60*60*LightSpeed;
System.out.print("In " +Year + " years " );
System.out.print("light will travel about ");
System.out.println(Distance + " miles");
}
}
17 changes: 17 additions & 0 deletions src/chapter03/ReadCharEx1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package chapter03;
/* ReadCharEx1.java */
/* Reading a character from Keyboard*/
import java.io.IOException;

import java.io.InputStream;

public class ReadCharEx1 {
public static void main(String[] args) throws IOException
{
// TODO Auto-generated method stub
System.out.print("Enter a character: ");
char ch = (char)System.in.read();
// Accepts a single character
System.out.print("You have entered " +ch);
}
}
15 changes: 15 additions & 0 deletions src/chapter03/ReadLinesEx1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package chapter03;
/* ReadLinesEx1.java */
/* Array of String Variable */
import java.io.*;
public class ReadLinesEx1 {
public static void main(String args[])throws IOException {
char Ch;
System.out.print("Enter some characters ('Q' to quit) : ");
do{
Ch = (char)System.in.read();
System.out.print(Ch);
}while(Ch != 'Q');
System.out.print("Program terminated.");
}
}
14 changes: 14 additions & 0 deletions src/chapter03/ReadLinesEx2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package chapter03;
/* ReadLinesEx2.java */
/* Example of readLine() Method */
import java.io.*;
public class ReadLinesEx2{
public static void main(String args[]) throws IOException {
DataInputStream inData = new DataInputStream(System.in);
System.out.print("Please enter your name: ");
String Name;
Name= inData.readLine();
System.out.print("Your name is : ");
System.out.print(Name);
}
}
Loading