Using Java RegEx Pattern and Matcher

 
Using pattern matcher in java is very easy and simple to identify a specific word or text from the given input String. Also we can check for case insensitive formats also by using Java RegEx. In that case lets see simple example for finding specific text from the multiple String inputs and return whether given text or (Pattern) matches from the given input.
Using Java RegEx Pattern and Matcher



import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PatternMatcherTest {

 public static void main(String[] args) {
  
  String str = "The listener interface for receiving text events. " +
    "The class that is interested in processing a text event implements this interface. " +
    "The object created with that class is then registered with a component using the " +
    "component's addTextListener method. When the component's text changes, " +
    "the listener object's textValueChanged method is invoked.";
  
  PatternMatcherTest obj = new PatternMatcherTest();
  System.out.println("PRESENT : "+obj.checkPatternMatch(str, "interface"));
  System.out.println("PRESENT : "+obj.checkPatternMatch(str, "EVENTS"));
  System.out.println("PRESENT : "+obj.checkPatternMatch(str, "Java"));
  System.out.println("PRESENT : "+obj.checkPatternMatch(str, "Method"));
 }

 public boolean checkPatternMatch(String str, String regex) {
  Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
  Matcher match = pattern.matcher(str);
  if (match.find())
   return true;
  else
   return false;
 }
}


OUTPUT:


PRESENT : true
PRESENT : true
PRESENT : false
PRESENT : true



Change file permission using java

 
Changing file permission using GUI is an end user easy operation. Same thing if we need to change multiple files like around hundreds or thousands of file then its difficult. But we can achieve this easy by using Java code. So lets see simple example for reading file permissions and then changing file to full permission (Read, Write and Execute).
Change file permission using java



import java.io.File;

public class FilePermissionTest {

 public static void main(String[] args) {
  
  String testFile = "D://testfile.txt";
  
  File file = new File(testFile);
  System.out.println("Current File Permissions : ");
  System.out.println("\t Read     : "+file.canRead());
  System.out.println("\t Write    : "+file.canWrite());
  System.out.println("\t Execute  : "+file.canExecute());
  
  System.out.println("\nLets change file to full permission ");
  
  file.setReadable(true);
  file.setWritable(true);
  file.setExecutable(true);
  
  System.out.println("\nChanged File Permissions : ");
  System.out.println("\t Read     : "+file.canRead());
  System.out.println("\t Write    : "+file.canWrite());
  System.out.println("\t Execute  : "+file.canExecute());
 }
}

OUTPUT:


Current File Permissions : 
  Read     : true
  Write    : false
  Execute  : true

Lets change file to full permission 

Changed File Permissions : 
  Read     : true
  Write    : true
  Execute  : true

Read and Write Objects from a file

Sometimes we may thinking of writing Objects into file and reading from other class or may need for future purpose. Basically we need to store the state of Object in a file and need to retrieve. For this we need to use Serializable interface to Serialize all class variables and by using ObjectInputStream and ObjectOutputStream class can be read and write from a file. Lets see simple example how to Serialize Object and same Object can to written into file. Next by another Java file we will read same Object from the file.
Read and Write Objects from a file



import java.io.Serializable;

public class Student implements Serializable {

 private static final long serialVersionUID = 1L;

 private String name;
 private int marks[] = new int[5];

 public Student(String name, int marks[]) {
  this.name = name;
  this.marks = marks;
 }

 public String getName() {
  return name;
 }

 public int[] getMarks() {
  return marks;
 }
}



In next program we will create Student Object and write to a file. 


import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

public class WriteToFile {

 public static void main(String[] args) {

  String name = "Steve";
  int marks[] = new int[] { 89, 86, 94, 78, 91 };

  Student obj = new Student(name, marks);

  new WriteToFile().writeStudentObjectToFile(obj);
 }

 public void writeStudentObjectToFile(Student obj) {

  OutputStream os = null;
  ObjectOutputStream oos = null;
  
  try {
   os = new FileOutputStream("D://student.txt");
   oos = new ObjectOutputStream(os);
   oos.writeObject(obj);
   oos.flush();
   System.out.println("Object written successfully to file");
   
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  
  } catch (IOException e) {
   e.printStackTrace();
  
  } finally {
   try {
    if (oos != null) oos.close();
   } catch (Exception ex) {}
  }
 }
}

OUPTUT:


Object written successfully to file


In next program we will read same file and extract Student Object from the file and print the values. 


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;

public class ReadFromFile {

 public static void main(String[] args) {

  new ReadFromFile().readStudentObjectFromFile();
 }

 public void readStudentObjectFromFile() {
  InputStream is = null;
  ObjectInputStream ois = null;
  
  try {
   is = new FileInputStream("D://student.txt");
   ois = new ObjectInputStream(is);
   
   Student obj = (Student) ois.readObject();
   
   System.out.println("Student Name : " + obj.getName());
   System.out.print("Marks        : ");
   for (int mark : obj.getMarks()) {
    System.out.print(mark+", ");
   }
  
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  } catch (ClassNotFoundException e) {
   e.printStackTrace();
  } finally {
   try {
    if (ois != null) ois.close();
   } catch (Exception ex) {}
  }
 }
}

OUTPUT:


Student Name : Steve
Marks        : 89, 86, 94, 78, 91, 




How to change File Modified Date and Time in Java

As a fun some times we may be thinking of changing file modified date and time from its original modified date and time. We may be thinking of changing date and time and need to puzzle our surrounding. Yes we can achieve this through Java code and lets see how to change it. Lets have fun.


import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileModifyDateAndTime {

 public static void main(String[] args) {
  try{
    
   File file = new File("F:\\testing\\Fool.txt");
  
   SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
   System.out.println("Original Modified Date and Time : " + sdf.format(file.lastModified()));
  
   //Modifying date and time
   Date newDateAndTime = sdf.parse("24/12/1980 12:59:59");
   file.setLastModified(newDateAndTime.getTime());
  
   System.out.println("Newly Modified Date and Time : " + sdf.format(file.lastModified()));
  
      }catch(ParseException e){ 
       e.printStackTrace(); 
      }
 }
}


OUTPUT:


Original Modified Date and Time : 01/04/2014 19:45:51
Newly Modified Date and Time : 24/12/1980 12:59:59


BEFORE:


How to change File Modified Date and Time in Java

AFTER:


How to change File Modified Date and Time in Java


Does Java pass by value or pass by reference?

Java does only pass by value and doesn't pass method arguments by reference, instead it passes Object reference by its value as method parameter. Java copies and passes the reference by value, not the object, hence if we modify Object values in method then original objects will get modified, since both references point to the original objects. 
Below are the 2 diagrams which we can see how primitive types work when we pass to another methods and how Objects work when we pass to another methods. Basically primitive types will create new variable in stack and it manipulates on it, but when we pass Objects it creates new reference and its passes the value of reference. Again Java does only pass by value and doesn't use pass by reference. 

When we pass primitive datatype to another method.
Does Java pass by value or pass by reference?
When we pass Object to another method.


Now lets see simple example in java as how it works. Lets create Employee class for Object passing.


public class Employee{
 
 private String name;

 public String getName() {
  return name;
 }

 public void setName(String name) {
  this.name = name;
 } 
}

Next we will create main class which will initiate Employee Object and pass to another method along with integer primitive datatype.


public class MyTest {
 
 public static void main(String[] args) {
  
  Employee obj = new Employee();
  obj.setName("JAVA");// IMP
  
  int _int = 100;
  
  MyTest ob1 = new MyTest();
  ob1.changeValue(obj, _int);
  
  System.out.println("Inside Main Method : "+obj.getName()+ " : "+_int);
 }
 
 public void changeValue(Employee mObj, int mInt){
  
  mObj.setName("DISCOVER");
  
  mInt = 99;
  
  System.out.println("Inside another Method : "+mObj.getName() + " : "+mInt);
 }
 
}

OUTPUT:


Inside another Method : DISCOVER : 99
Inside Main Method : DISCOVER : 100

Character Array to String in Java

 
We may seen lot of arrays like Integer, Character, Float and Double or even String array. In this tutorial we will see about converting Character array to String in Java code. We can achieve this by 2 ways like given below,
Character Array to String in Java


public class CharToString {

 public static void main(String[] args) {
  
  char[] myArray = new char[]{'j','a','v','a',' ','d','i','s','c','o','v','e','r'};
  
  //By 2 ways we can convert char[] to String and lets see both ways
  
  String type1 = String.valueOf(myArray);

String type2 = new String(myArray);
  
  
  System.out.println("TYPE 1 : "+type1);
  System.out.println("TYPE 2 : "+type2);
 }
}

OUTPUT:

TYPE 1 : java discover
TYPE 2 : java discover

Java Locale to get Countries List

 
Some times we may required to list of country names from XML or through properties file. On alternate way we can get list of country names using Java API also which gives most effective and generic way of using country names along with their country codes. In this tutorial we will see about how to get list of Countries using Java util class Locale. They may be a simple code where lot of Java developers aware of it, but gives new learning for freshers to Java.
Java Locale to get Countries List



import java.util.Locale;

public class CountriesList {

 public static void main(String[] args) {
  
  String[] countriesList = Locale.getISOCountries();
  
  int id = 1;
  System.out.println("ID \t COUNTRY CODE \t COUNTRY NAME");
  
  for (String country : countriesList) {
   
   Locale tmp = new Locale("", country);
    
   System.out.println((id++) +" \t "+tmp.getCountry() + " \t\t " + tmp.getDisplayCountry());
  }
 }
}

OUTPUT:


ID   COUNTRY CODE   COUNTRY NAME
1   AD    Andorra
2   AE    United Arab Emirates
3   AF    Afghanistan
4   AG    Antigua and Barbuda
5   AI    Anguilla
6   AL    Albania
7   AM    Armenia
8   AN    Netherlands Antilles
9   AO    Angola
10   AQ    Antarctica
11   AR    Argentina
12   AS    American Samoa
13   AT    Austria
14   AU    Australia
15   AW    Aruba
16   AX    Ã…land Islands
17   AZ    Azerbaijan
18   BA    Bosnia and Herzegovina
19   BB    Barbados
20   BD    Bangladesh
21   BE    Belgium
22   BF    Burkina Faso
23   BG    Bulgaria
24   BH    Bahrain
25   BI    Burundi
26   BJ    Benin
27   BL    Saint Barthélemy
28   BM    Bermuda
29   BN    Brunei
30   BO    Bolivia
31   BQ    Bonaire, Sint Eustatius and Saba
32   BR    Brazil
33   BS    Bahamas
34   BT    Bhutan
35   BV    Bouvet Island
36   BW    Botswana
37   BY    Belarus
38   BZ    Belize
39   CA    Canada
40   CC    Cocos Islands
41   CD    The Democratic Republic Of Congo
42   CF    Central African Republic
43   CG    Congo
44   CH    Switzerland
45   CI    Côte d'Ivoire
46   CK    Cook Islands
47   CL    Chile
48   CM    Cameroon
49   CN    China
50   CO    Colombia
51   CR    Costa Rica
52   CU    Cuba
53   CV    Cape Verde
54   CW    Curaçao
55   CX    Christmas Island
56   CY    Cyprus
57   CZ    Czech Republic
58   DE    Germany
59   DJ    Djibouti
60   DK    Denmark
61   DM    Dominica
62   DO    Dominican Republic
63   DZ    Algeria
64   EC    Ecuador
65   EE    Estonia
66   EG    Egypt
67   EH    Western Sahara
68   ER    Eritrea
69   ES    Spain
70   ET    Ethiopia
71   FI    Finland
72   FJ    Fiji
73   FK    Falkland Islands
74   FM    Micronesia
75   FO    Faroe Islands
76   FR    France
77   GA    Gabon
78   GB    United Kingdom
79   GD    Grenada
80   GE    Georgia
81   GF    French Guiana
82   GG    Guernsey
83   GH    Ghana
84   GI    Gibraltar
85   GL    Greenland
86   GM    Gambia
87   GN    Guinea
88   GP    Guadeloupe
89   GQ    Equatorial Guinea
90   GR    Greece
91   GS    South Georgia And The South Sandwich Islands
92   GT    Guatemala
93   GU    Guam
94   GW    Guinea-Bissau
95   GY    Guyana
96   HK    Hong Kong
97   HM    Heard Island And McDonald Islands
98   HN    Honduras
99   HR    Croatia
100   HT    Haiti
101   HU    Hungary
102   ID    Indonesia
103   IE    Ireland
104   IL    Israel
105   IM    Isle Of Man
106   IN    India
107   IO    British Indian Ocean Territory
108   IQ    Iraq
109   IR    Iran
110   IS    Iceland
111   IT    Italy
112   JE    Jersey
113   JM    Jamaica
114   JO    Jordan
115   JP    Japan
116   KE    Kenya
117   KG    Kyrgyzstan
118   KH    Cambodia
119   KI    Kiribati
120   KM    Comoros
121   KN    Saint Kitts And Nevis
122   KP    North Korea
123   KR    South Korea
124   KW    Kuwait
125   KY    Cayman Islands
126   KZ    Kazakhstan
127   LA    Laos
128   LB    Lebanon
129   LC    Saint Lucia
130   LI    Liechtenstein
131   LK    Sri Lanka
132   LR    Liberia
133   LS    Lesotho
134   LT    Lithuania
135   LU    Luxembourg
136   LV    Latvia
137   LY    Libya
138   MA    Morocco
139   MC    Monaco
140   MD    Moldova
141   ME    Montenegro
142   MF    Saint Martin
143   MG    Madagascar
144   MH    Marshall Islands
145   MK    Macedonia
146   ML    Mali
147   MM    Myanmar
148   MN    Mongolia
149   MO    Macao
150   MP    Northern Mariana Islands
151   MQ    Martinique
152   MR    Mauritania
153   MS    Montserrat
154   MT    Malta
155   MU    Mauritius
156   MV    Maldives
157   MW    Malawi
158   MX    Mexico
159   MY    Malaysia
160   MZ    Mozambique
161   NA    Namibia
162   NC    New Caledonia
163   NE    Niger
164   NF    Norfolk Island
165   NG    Nigeria
166   NI    Nicaragua
167   NL    Netherlands
168   NO    Norway
169   NP    Nepal
170   NR    Nauru
171   NU    Niue
172   NZ    New Zealand
173   OM    Oman
174   PA    Panama
175   PE    Peru
176   PF    French Polynesia
177   PG    Papua New Guinea
178   PH    Philippines
179   PK    Pakistan
180   PL    Poland
181   PM    Saint Pierre And Miquelon
182   PN    Pitcairn
183   PR    Puerto Rico
184   PS    Palestine
185   PT    Portugal
186   PW    Palau
187   PY    Paraguay
188   QA    Qatar
189   RE    Reunion
190   RO    Romania
191   RS    Serbia
192   RU    Russia
193   RW    Rwanda
194   SA    Saudi Arabia
195   SB    Solomon Islands
196   SC    Seychelles
197   SD    Sudan
198   SE    Sweden
199   SG    Singapore
200   SH    Saint Helena
201   SI    Slovenia
202   SJ    Svalbard And Jan Mayen
203   SK    Slovakia
204   SL    Sierra Leone
205   SM    San Marino
206   SN    Senegal
207   SO    Somalia
208   SR    Suriname
209   ST    Sao Tome And Principe
210   SV    El Salvador
211   SX    Sint Maarten (Dutch part)
212   SY    Syria
213   SZ    Swaziland
214   TC    Turks And Caicos Islands
215   TD    Chad
216   TF    French Southern Territories
217   TG    Togo
218   TH    Thailand
219   TJ    Tajikistan
220   TK    Tokelau
221   TL    Timor-Leste
222   TM    Turkmenistan
223   TN    Tunisia
224   TO    Tonga
225   TR    Turkey
226   TT    Trinidad and Tobago
227   TV    Tuvalu
228   TW    Taiwan
229   TZ    Tanzania
230   UA    Ukraine
231   UG    Uganda
232   UM    United States Minor Outlying Islands
233   US    United States
234   UY    Uruguay
235   UZ    Uzbekistan
236   VA    Vatican
237   VC    Saint Vincent And The Grenadines
238   VE    Venezuela
239   VG    British Virgin Islands
240   VI    U.S. Virgin Islands
241   VN    Vietnam
242   VU    Vanuatu
243   WF    Wallis And Futuna
244   WS    Samoa
245   YE    Yemen
246   YT    Mayotte
247   ZA    South Africa
248   ZM    Zambia
249   ZW    Zimbabwe

Java Interview Questions - 6

Which of the following statements about arrays is syntactically wrong?
(a) Person[] p = new Person[5];
(b) Person p[5];
(c) Person[] p [];
(d) Person p[][] = new Person[2][];
Java Interview Questions


2. Given the following piece of code:
public class Test {
public static void main(String args[]) {
int i = 0, j = 5 ;
for( ; (i < 3) && (j++ < 10) ; i++ ) {
System.out.print(" " + i + " " + j );
}
System.out.print(" " + i + " " + j );
}
}
what will be the result?
(a) 0 6 1 7 2 8 3 8
(b) 0 6 1 7 2 8 3 9
(c) 0 5 1 5 2 5 3 5
(d) compilation fails


3. Which of the following declarations is correct? (2 answers):
(a) boolean b = TRUE;
(b) byte b = 255;
(c) String s = “null”;
(d) int i = new Integer(“56”);


4. Suppose a class has public visibility. In this class we define a protected method. Which of the following statements is correct?
(a) This method is only accessible from inside the class itself and from inside all subclasses.
(b) In a class, you can not declare methods with a lower visibility than the visibility of the class in which it is defined.
(c) From within protected methods you dnot have access tpublic methods.
(d) This method is accessible from within the class itself and from within all classes defined in the same package as the class itself.


5. Given the following piece of code:
public class Company{
public abstract double calculateSalaries();
}
which of the following statements is true?
(a) The keywords public and abstract can not be used together.
(b) The method calculateSalaries() in class Company must have a body
(c) You must add a return statement in method calculateSalaries().
(d) Class Company must be defined abstract.


6. Given the following piece of code:
public interface Guard{
void doYourJob();
}
abstract public class Dog implements Guard{}
which of the following statements is correct?
(a) This code will not compile, because method doYourJob() in interface Guard must be defined abstract.
(b) This code will not compile, because class Dog must implement method doYourJob() from interface Guard.
(c) This code will not compile, because in the declaration of class Dog we must use the key-word extends in stead of implements.
(d) This code will compile without any errors.


7. Given these classes:
public class Person{
public void talk(){ 
System.out.print("I am a Person "); 
}
}
public class Student extends Person {
public void talk(){ 
System.out.print("I am a Student "); 
}
}
what is the result of this piece of code:
public class Test{
public static void main(String args[]){
Person p = new Student();
p.talk();
}
}
(a) I am a Person
(b) I am a Student
(c) I am a Person I am a Student
(d) I am a Student I am a Person


8. Given the following piece of code:
public class Person{
private String firstName;
public Person(String fn){ 
firstName = fn; 
}
}
public class Student extends Person{
private String studentNumber;
public Student(String number) { 
studentNumber = number; 
}
}
Which of the following statements is true? (2 answers)
(a) This code will compile if we define in class Person a no-argument constructor.
(b) This code will compile if we define in class Student a no-argument constructor.
(c) This code will compile if we add in the constructor of Student the following line of code as first statement:super();
(d) This code will compile if we call the constructor of Person from within the constructor of Student.


9. Specify the correct characteristics of an enumeration type (2 answers)
(a) enum can define static fields and methods 
(b) enum can contain a public constructor
(c) enum can implement interfaces
(d) enum is a reference ta variable set of constants


10. Given the following piece of code:
class Person { 
public int number; 
}

public class Test{
public void doIt(int i , Person p){
i = 5;
p.number = 8;
}
public static void main(String args[]){
int x = 0;
Person p = new Person();
new Test().doIt(x, p);
System.out.println(x + " " + p.number);
}
}
What is the result?
(a) 0 8
(b) 5 0
(c) 0 0
(d) 5 8


11. Given the following piece of code:
class SalaryCalculationException extends Exception{}
class Person{
public void calculateSalary() throws SalaryCalculationException {
//...
throw new SalaryCalculationException();
//...
}
}
class Company{
public void paySalaries(){
new Person().calculateSalary();
}
}
Which of the following statements is correct? (2 answers)
(a) This code will compile without any problems.
(b) This code will compile if in method paySalaries() we return a boolean in stead of void.
(c) This code will compile if we add a try-catch block in paySalaries() 
(d) This code will compile if we add throws SalaryCalculationException in the signature of method paySalaries().


12. Which of the following statements regarding static methods are correct? (2 answers)
(a) static methods are difficult tmaintain, because you can not change their implementa-tion.
(b) static methods can be called using an object reference tan object of the class in which this method is defined.
(c) static methods are always public, because they are defined at class-level.
(d) static methods dnot have direct access tnon-static methods which are defined inside the same class.


13. Given the following piece of code:
class Person{ 
public void talk(){} 
}
public class Test{
public static void main(String args[]){
Person p = null;
try{
p.talk();
} catch(NullPointerException e){
System.out.print("There is a NullPointerException. ");
} catch(Exception e){
System.out.print("There is an Exception. ");
}
System.out.print("Everything went fine. ");
}
}
what will be the result?
(a) If you run this program, the outcome is: There is a NullPointerException. Everything went fine.
(b) If you run this program, the outcome is: There is a NullPointerException.
(c) If you run this program, the outcome is: There is a NullPointerException. There is an Exception.
(d) This code will not compile, because in Java there are npointers.


14. Which of the following statement about Generics are correct? (2 answers)
(a) Generics are typed subclasses of the classes from the Collections framework
(b) Generics are used tparameterize the collections in order tallow for static type check-
ing at compile tIme of the objects in the collection.
(c) Generics can be used tperform type checking of the objects in a collection at runtime.
(d) Generics can be used titerate over a complete collection in an easy way, using the ‘enhanced for’ loop.


15. Which collection class associates values witch keys, and orders the keys according ttheir natural order?
(a) java.util.HashSet
(b) java.util.LinkedList
(c) java.util.TreeMap
(d) java.util.SortedSet


16. Which of the following statements about GUI components is wrong?
(a) Swing exists since version 1.2 of the jdk.
(b) AWT stands for Abstract Window Toolkit
(c) You can not place AWT components on Swing containers.
(d) The AWT classes are deprecated.


17. Which of the following statements about events are correct? (2 answers)
(a) Event objects are placed on a Queue, where they are fetched by subscribers (objects of classes which implement the interface Subscriber).
(b) The listener of an event must implement the method public void listen(EventObject obj).
(c) Each event object must be an object of a subclass of EventObject.
(d) Each event listener can investigate about the source of an event by calling the method getSource() on the event object.


18. How can you serialize an object?
(a) You have tmake the class of the object implement the interface Serializable.
(b) You must call the method serializeObject()(which is inherited from class Object) on the object.
(c) You should call the static method serialize(Object obj) from class Serializer, with as argument the object tbe serialized.
(d) You don’t have tdanything, because all objects are serializable by default.


19. Which statements about Iare correct (2 answers)?
(a)OutputStream is the abstract superclass of all classes that represent an outputstream of bytes.
(b) Subclasses of the class Reader are used tread character streams.
(c) Twrite characters tan outputstream, you have tmake use of the class CharacterOutputStream.
(d) Twrite an object ta file, you use the class ObjectFileWriter.


20. Given the following piece of code:
public class MyThread extends Thread{
public String text;
public void run(){
System.out.print(text);
}
}
public class Test{
public static void main(String args[]){
MyThread t1 = new MyThread(); t1.text = "one ";
MyThread t2 = new MyThread(); t2.text = "tw";
t1.start();
t2.start();
System.out.print("three ");
}
}
Which of the following statements is true?
(a) If you execute this program, the result is always one twthree
(b) If you execute this program, the result is always three one two
(c) The result of this program is undetermined.
(d) Compilation will faill.


Answers:

1. b
2. a
3. c, d
4. d
5. d
6. d
7. b
8. a, d
9. a, c
10. a
11. c, d
12. b, d
13. a
14. b, d
15. c
16. d
17. c, d
18. a
19. a, b
20. c